mirror of
https://github.com/yldio/copilot.git
synced 2024-12-01 07:30:07 +02:00
e2c0845145
- cloudapi-gql@1.0.4 - joyent-cp-frontend@1.1.0 - joyent-cp-gql-mock-server@1.0.4 - joyent-cp-gql-schema@1.0.4 - joyent-cp-rdb-bootstrap@1.0.4 - normalized-styled-components@1.0.5 - pseudo-json-ast@1.0.6 - pseudo-yaml-ast@1.0.6 - remcalc@1.0.5 - rnd-id@1.0.5 - styled-is@1.0.7 - joyent-ui-toolkit@1.1.0 - unitcalc@1.0.5 |
||
---|---|---|
.. | ||
src | ||
test | ||
.babelrc | ||
.eslintignore | ||
.eslintrc | ||
.tern-project | ||
CHANGELOG.md | ||
package.json | ||
README.md | ||
yarn.lock |
pseudo-json-ast
Parse a JSON string into an object with location properties.
Table of Contents
Install
yarn add --dev pseudo-json-ast
Usage
import jsonAST, { loc } from 'pseudo-json-ast';
import assert from 'assert';
const ast = jsonAST(`{
"obj": {
"arr": [{
"nums": [1, 2, 3],
"strs1": ["1", "2", "3"],
"strs: ["1", "2", "3"]
}],
"str": "1",
"num": 1
}
}`);
assert.deepEqual(Object.keys(ast), ['obj']);
assert.deepEqual(ast[loc].start.line, 1);
assert.deepEqual(ast[loc].end.line, 11);
assert.deepEqual(Object.keys(ast.obj), ['arr', 'str', 'num']);
assert.deepEqual(ast.obj[loc].start.line, 2);
assert.deepEqual(ast.obj[loc].end.line, 10);
assert.deepEqual(ast.obj.str[loc].start.line, 8);
assert.deepEqual(ast.obj.str[loc].end.line, 8);
assert.deepEqual(ast.obj.num[loc].start.line, 9);
assert.deepEqual(ast.obj.num[loc].end.line, 9);
assert.deepEqual(ast.obj.arr[0][loc].start.line, 3);
assert.deepEqual(ast.obj.arr[0][loc].end.line, 7);
assert.deepEqual(Object.keys(ast.obj.arr[0]), ['nums', 'strs1']);
assert.deepEqual(ast.obj.arr[0].nums[loc].start.line, 4);
assert.deepEqual(ast.obj.arr[0].nums[loc].end.line, 4);
assert.deepEqual(ast.obj.arr[0].strs1[loc].start.line, 5);
assert.deepEqual(ast.obj.arr[0].strs1[loc].end.line, 5);
License
MPL-2.0