jsonc-simple-parser
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -123,3 +123,3 @@ "use strict"; | ||
const lookup = (text, position, usePartialScanning = true) => { | ||
const limit = usePartialScanning ? position : Infinity, ast = tokenize_1.default(text, limit), token = getLookupToken(ast, position), path = getLookupPath(token), isInsideProperty = getLookupIsInsideProperty(token), isInsideValue = getLookupIsInsideValue(token), property = getLookupProperty(token, isInsideProperty), value = getLookupValue(token, isInsideValue, usePartialScanning), result = { path, property, value, isInsideProperty, isInsideValue }; | ||
const limit = usePartialScanning ? position : Infinity, ast = tokenize_1.default(text, limit), token = getLookupToken(ast, position), path = getLookupPath(token), isInsideProperty = getLookupIsInsideProperty(token), isInsideValue = getLookupIsInsideValue(token), property = getLookupProperty(token, isInsideProperty), value = getLookupValue(token, isInsideValue, usePartialScanning), t = token ? { type: token.type, start: token.start, end: token.end, source: token.source } : undefined, result = { path, property, value, token: t, isInsideProperty, isInsideValue }; | ||
return result; | ||
@@ -126,0 +126,0 @@ }; |
@@ -49,3 +49,3 @@ "use strict"; | ||
const ObjectClose = $.ObjectClose `${'}'}`; | ||
const ObjectMember = $.Passthrough `${_} ${String} ${_} ${Colon} ${_} ${() => Literal} ${_}`; | ||
const ObjectMember = $.Passthrough `${_} ${String} (${EarlyReturn} | ${_} ${Colon} ${_} ${() => Literal} ${_})`; | ||
const ObjectMembers = $.Passthrough `${ObjectMember} (!${EarlyReturn} ${Comma} ${ObjectMember})* ${CommaTrailing}?`; | ||
@@ -52,0 +52,0 @@ const Object = $.Object `${ObjectOpen} ${_} ${ObjectMembers}? ${_} (${EarlyReturn} | ${ObjectClose})`; |
@@ -102,2 +102,8 @@ declare type JSONValue = import('type-fest').JsonValue; | ||
declare type LookupPath = (string | number)[]; | ||
declare type LookupResultToken = { | ||
type: ParseTokensType; | ||
source: string; | ||
start: number; | ||
end: number; | ||
}; | ||
declare type LookupResult = { | ||
@@ -107,2 +113,3 @@ path: LookupPath; | ||
value: JSONValue | undefined; | ||
token: LookupResultToken | undefined; | ||
isInsideProperty: boolean; | ||
@@ -115,2 +122,2 @@ isInsideValue: boolean; | ||
export { ParseTokensMap, ParseMatchersMap }; | ||
export { LookupChildToken, LookupParentToken, LookupToken, LookupPath, LookupResult }; | ||
export { LookupChildToken, LookupParentToken, LookupToken, LookupPath, LookupResultToken, LookupResult }; |
{ | ||
"name": "jsonc-simple-parser", | ||
"description": "A simple JSON parser that supports comments and optional trailing commas.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"main": "dist/index.js", | ||
@@ -63,2 +63,3 @@ "types": "dist/index.d.ts", | ||
"jsonc-parser": "^3.0.0", | ||
"lodash": "^4.17.21", | ||
"rimraf": "^3.0.2", | ||
@@ -65,0 +66,0 @@ "test262-harness": "^7.5.2", |
@@ -6,3 +6,3 @@ | ||
import {ChildToken, ParentToken, AST} from './types'; | ||
import {LookupChildToken, LookupParentToken, LookupPath, LookupResult} from './types'; | ||
import {LookupChildToken, LookupParentToken, LookupPath, LookupResultToken, LookupResult} from './types'; | ||
import detokenize from './detokenize'; | ||
@@ -177,3 +177,4 @@ import parse from './parse'; | ||
value = getLookupValue ( token, isInsideValue, usePartialScanning ), | ||
result: LookupResult = {path, property, value, isInsideProperty, isInsideValue}; | ||
t = token ? { type: token.type, start: token.start, end: token.end, source: token.source } as LookupResultToken : undefined, | ||
result: LookupResult = {path, property, value, token: t, isInsideProperty, isInsideValue}; | ||
@@ -180,0 +181,0 @@ return result; |
@@ -122,3 +122,3 @@ | ||
const ObjectMember | ||
= $.Passthrough`${_} ${String} ${_} ${Colon} ${_} ${() => Literal} ${_}`; | ||
= $.Passthrough`${_} ${String} (${EarlyReturn} | ${_} ${Colon} ${_} ${() => Literal} ${_})`; | ||
@@ -125,0 +125,0 @@ const ObjectMembers |
@@ -142,2 +142,9 @@ | ||
type LookupResultToken = { | ||
type: ParseTokensType, | ||
source: string, | ||
start: number, | ||
end: number | ||
}; | ||
type LookupResult = { | ||
@@ -147,2 +154,3 @@ path: LookupPath, | ||
value: JSONValue | undefined, | ||
token: LookupResultToken | undefined, | ||
isInsideProperty: boolean, | ||
@@ -158,2 +166,2 @@ isInsideValue: boolean | ||
export {ParseTokensMap, ParseMatchersMap}; | ||
export {LookupChildToken, LookupParentToken, LookupToken, LookupPath, LookupResult}; | ||
export {LookupChildToken, LookupParentToken, LookupToken, LookupPath, LookupResultToken, LookupResult}; |
@@ -497,2 +497,3 @@ | ||
`, | ||
objectPartial: `{ "foo" }`, | ||
array: ` | ||
@@ -499,0 +500,0 @@ // Example // Yes |
/* IMPORT */ | ||
import _ from 'lodash'; | ||
import {describe} from 'ava-spec'; | ||
@@ -56,86 +57,98 @@ import JSONC from '../../dist'; | ||
it ( 'does something', t => { | ||
it ( 'returns an object describing a location in a JSONC string', t => { | ||
const lookup = ( target, index, usePartialScanning ) => _.omit ( JSONC.lookup ( target, index, usePartialScanning ), ['token'] ); //TODO: Actually match against the token object too | ||
const {object} = Fixtures.lookup; | ||
t.deepEqual ( JSONC.lookup ( object, 5, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 10, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 5, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 10, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 70, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 71, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 72, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 75, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 76, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 77, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 78, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 79, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 80, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 81, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 70, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 71, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 72, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 75, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 76, false ), { path: ['one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 77, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 78, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 79, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 80, false ), { path: ['one'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 81, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 89, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 90, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 91, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 94, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 95, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 96, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 97, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 98, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 99, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 100, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 89, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 90, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 91, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 94, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 95, false ), { path: ['two'], property: 'two', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 96, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 97, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 98, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 99, false ), { path: ['two'], property: undefined, value: {}, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 100, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 123, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 123, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 130, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 131, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 134, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 135, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 137, false ), { path: ['three', 'one'], property: undefined, value: null, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 141, false ), { path: ['three', 'one'], property: undefined, value: null, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 142, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 130, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 131, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 134, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 135, false ), { path: ['three', 'one'], property: 'one', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 137, false ), { path: ['three', 'one'], property: undefined, value: null, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 141, false ), { path: ['three', 'one'], property: undefined, value: null, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 142, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 202, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 203, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 207, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 208, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 209, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 202, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 203, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 207, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 208, false ), { path: ['three', 'four'], property: 'four', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 209, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 210, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 211, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 224, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 225, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 226, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( object, 210, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 211, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 224, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 225, false ), { path: ['three', 'four'], property: undefined, value: 'asd\n\u0022\"', isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 226, false ), { path: ['three'], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( object, 275, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 276, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 275, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 276, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 277, false ), { path: ['three', 'six', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 280, false ), { path: ['three', 'six', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 281, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 277, false ), { path: ['three', 'six', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 280, false ), { path: ['three', 'six', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 281, false ), { path: ['three', 'six'], property: undefined, value: [123, true, []], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( object, 289, false ), { path: ['three', 'six', 2], property: 2, value: [], isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( object, 289, false ), { path: ['three', 'six', 2], property: 2, value: [], isInsideProperty: true, isInsideValue: true } ); | ||
const {array} = Fixtures.lookup; | ||
t.deepEqual ( JSONC.lookup ( array, 5, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 10, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 61, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 67, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 5, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 10, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 61, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 67, false ), { path: [], property: undefined, value: undefined, isInsideProperty: false, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 71, false ), { path: [0], property: undefined, value: { foo: 123, bar: [123] }, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( array, 72, false ), { path: [0], property: undefined, value: { foo: 123, bar: [123] }, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 71, false ), { path: [0], property: undefined, value: { foo: 123, bar: [123] }, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 72, false ), { path: [0], property: undefined, value: { foo: 123, bar: [123] }, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( array, 73, false ), { path: [0, 'foo'], property: 'foo', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 78, false ), { path: [0, 'foo'], property: 'foo', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 73, false ), { path: [0, 'foo'], property: 'foo', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 78, false ), { path: [0, 'foo'], property: 'foo', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 80, false ), { path: [0, 'foo'], property: undefined, value: 123, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( array, 83, false ), { path: [0, 'foo'], property: undefined, value: 123, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 80, false ), { path: [0, 'foo'], property: undefined, value: 123, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 83, false ), { path: [0, 'foo'], property: undefined, value: 123, isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( array, 98, false ), { path: [0, 'bar'], property: 'bar', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( lookup ( array, 98, false ), { path: [0, 'bar'], property: 'bar', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
t.deepEqual ( JSONC.lookup ( array, 100, false ), { path: [0, 'bar'], property: undefined, value: [123], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 100, false ), { path: [0, 'bar'], property: undefined, value: [123], isInsideProperty: false, isInsideValue: true } ); | ||
t.deepEqual ( JSONC.lookup ( array, 101, false ), { path: [0, 'bar', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
t.deepEqual ( lookup ( array, 101, false ), { path: [0, 'bar', 0], property: 0, value: 123, isInsideProperty: true, isInsideValue: true } ); | ||
}); | ||
it ( 'supports partial objects where only the property is available', t => { | ||
const lookup = ( target, index, usePartialScanning ) => _.omit ( JSONC.lookup ( target, index, usePartialScanning ), ['token'] ); //TODO: Actually match against the token object too | ||
const {objectPartial} = Fixtures.lookup; | ||
t.deepEqual ( lookup ( objectPartial, 3, true ), { path: ['foo'], property: 'foo', value: undefined, isInsideProperty: true, isInsideValue: false } ); | ||
}); | ||
it ( 'throws on invalid input', t => { | ||
@@ -142,0 +155,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
362418
12360
12