Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
littlespex committed Nov 8, 2021
1 parent 4f74d19 commit d854c49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All CMCD properties are optional. Properties that with nullish values will not b
```typescript
import {
Cmcd,
CmcdHeaader,
CmcdHeader,
CmcdObjectType,
CmcdStreamingFormat,
CmcdStreamType,
Expand All @@ -35,7 +35,7 @@ const data: Cmcd = {
const query = toQuery(data);
console.log(query);
/*
'CMCD=br%3D200%2Cbs%2Cmtp%3D10000%2Cot%3Dm%2Csf%3Dd%2Ccid%3D%229f7f349b-baba-43d7-bbe7-b0dc8a65af0d%22%2Cst%3Dv'
'CMCD=br%3D200%2Cbs%2Ccid%3D%229f7f349b-baba-43d7-bbe7-b0dc8a65af0d%22%2Cmtp%3D10000%2Cot%3Dm%2Csf%3Dd%2Cst%3Dv'
*/

const headers = toHeaders(data);
Expand All @@ -44,38 +44,49 @@ console.log(headers);
{
'CMCD-Object': 'br=200,ot=m',
'CMCD-Request': 'mtp=10000',
'CMCD-Session': 'sf=d,cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",st=v',
'CMCD-Status': 'bs',
'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",sf=d,st=v',
'CMCD-Status': 'bs'
}
*/

const json = toJson(data);
console.log(json);
/*
'{"mtp":10000,"su":false,"br":200,"ot":"m","sf":"d","cid":"9f7f349b-baba-43d7-bbe7-b0dc8a65af0d","st":"v","bs":true}'
'{"br":200,"bs":true,"cid":"9f7f349b-baba-43d7-bbe7-b0dc8a65af0d","mtp":10000,"ot":"m","sf":"d","st":"v"}'
*/

/* Custom Fields */
/**
* Custom Fields
*/

data['com.example-a'] = 'hello';
data['com.example-b']: 1234;
data['com.example-c']: true;
data['com.example-d']: Symbol('s');
data['com.example-b'] = 1234;
data['com.example-c'] = true;
data['com.example-d'] = Symbol('s');

console.log(toQuery(data));
/*
'CMCD=br%3D200%2Cbs%2Ccid%3D%229f7f349b-baba-43d7-bbe7-b0dc8a65af0d%22%2Ccom.example-a%3D%22hello%22%2Ccom.example-b%3D1234%2Ccom.example-c%2Ccom.example-d%3Ds%2Cmtp%3D10000%2Cot%3Dm%2Csf%3Dd%2Cst%3Dv'
*/

/**
* Custom fields can be mapped to specific headers by providing a mapping
* object to the `toHeader` function. Unmapped custom fields are added to
* the CMCD-Request header.
*/
const headerMap = {
['com.example-a']: CmcdHeader.Object,
['com.example-b']: CmcdHeader.Session,
['com.example-c']: CmcdHeader.Status,
// Unmapped custom fields are added to the CMCD-Request header
};

const headers = toHeaders(data, headerMap);
console.log(headers);
console.log(toHeaders(data, headerMap));
/*
{
'CMCD-Object': 'br=200,com.example-a="hello",ot=m',
'CMCD-Request': 'mtp=10000',
'CMCD-Request': 'com.example-d=s,mtp=10000',
'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",com.example-b=1234,sf=d,st=v',
'CMCD-Status': 'bs,com.example-c',
'CMCD-Status': 'bs,com.example-c'
}
*/
```
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cmcd.js",
"version": "0.6.1",
"version": "0.6.2",
"description": "CMCD (Common Media Client Data) library with Typescript definitions",
"main": "dist/cmcd.min.js",
"types": "dist/types/index.d.ts",
Expand Down

0 comments on commit d854c49

Please sign in to comment.