Skip to content

Commit 48c9439

Browse files
Add CLI
1 parent 43d7765 commit 48c9439

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

.eslintrc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ module.exports = {
3535
"padded-blocks": "off",
3636
"prefer-arrow-callback": "off",
3737
"prefer-destructuring": "off",
38+
"prefer-template": "off",
3839
"quote-props": "off",
3940
"require-unicode-regexp": "off",
4041
"sort-keys": "off",
4142
"vars-on-top": "off"
42-
}
43+
},
44+
45+
overrides: [{
46+
files: "cli.js",
47+
rules: {
48+
"no-console": "off",
49+
"no-process-exit": "off"
50+
}
51+
}]
4352
};

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Parser is available as [NPM package](https://www.npmjs.com/package/tc-string-par
1313
### NodeJS (>=5.10.0)
1414

1515
```js
16-
const TCStringParse = require('tc-string-parse');
16+
const tcStringParse = require('tc-string-parse');
1717

1818
const consentString = ''; // your consent string
19-
const consentModel = TCStringParse(consentString);
19+
const consentModel = tcStringParse(consentString);
2020
```
2121

2222
### Browser (IE 9+ with [atob polyfill](https://caniuse.com/#feat=atob-btoa))
@@ -29,3 +29,9 @@ const consentModel = TCStringParse(consentString);
2929
var consentModel = TCStringParse(consentString);
3030
</script>
3131
```
32+
33+
### Command line
34+
35+
```shell
36+
tc-string-parse <your consent string>
37+
```

cli.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
5+
var args = process.argv.slice(2);
6+
7+
if (!args.length) {
8+
console.error("Transparency and consent string not passed.");
9+
process.exit(1);
10+
}
11+
12+
if (args.length !== 1) {
13+
console.error("Too many arguments passed.");
14+
process.exit(1);
15+
}
16+
17+
var parse = require(".");
18+
19+
var model = {};
20+
try {
21+
model = parse(args[0]);
22+
} catch (error) {
23+
console.error("Unable to parse constent string: " + error.message);
24+
process.exit(1);
25+
}
26+
27+
var output = JSON.stringify(model, null, 2);
28+
29+
console.log(output);
30+
process.exit(0);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"license": "Apache-2.0",
1818
"main": "tc-string-parse.js",
19+
"bin": "./cli.js",
1920
"scripts": {
2021
"test": "ava --verbose",
2122
"lint": "eslint .",

0 commit comments

Comments
 (0)