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 8750882 commit 4f74d19
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ npm i cmcd.js
```

## Usage
All CMCD properties are optional. Properties that are with nullish values will not be serialized.
All CMCD properties are optional. Properties that with nullish values will not be serialized.

```typescript
import {
Cmcd,
CmcdHeaader,
CmcdObjectType,
CmcdStreamingFormat,
CmcdStreamType,
Expand Down Expand Up @@ -41,10 +42,10 @@ const headers = toHeaders(data);
console.log(headers);
/*
{
'cmcd-request': 'mtp=10000',
'cmcd-object': 'br=200,ot=m',
'cmcd-session': 'sf=d,cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",st=v',
'cmcd-status': 'bs',
'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',
}
*/

Expand All @@ -53,6 +54,30 @@ console.log(json);
/*
'{"mtp":10000,"su":false,"br":200,"ot":"m","sf":"d","cid":"9f7f349b-baba-43d7-bbe7-b0dc8a65af0d","st":"v","bs":true}'
*/

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

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);
/*
{
'CMCD-Object': 'br=200,com.example-a="hello",ot=m',
'CMCD-Request': 'mtp=10000',
'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",com.example-b=1234,sf=d,st=v',
'CMCD-Status': 'bs,com.example-c',
}
*/
```

## API Docs
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.0",
"version": "0.6.1",
"description": "CMCD (Common Media Client Data) library with Typescript definitions",
"main": "dist/cmcd.min.js",
"types": "dist/types/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './Cmcd';
export * from './CmcdCustomKey';
export * from './CmcdHeader';
export * from './CmcdKey';
export * from './CmcdObjectType';
Expand Down

0 comments on commit 4f74d19

Please sign in to comment.