UNPKG

json-property-filter

Version:

JavaScript library and application to filter a JSON object by including and excluding properties.

18 lines (17 loc) 859 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createContext = exports.EMPTY_CONTEXT = void 0; exports.EMPTY_CONTEXT = { absolutePath: "", segments: [], relativePath: "" }; function createContext(context, source, propertyName) { var segments = context.segments ? context.segments.concat(propertyName) : [propertyName]; var absolutePath = segments.join("."); var relativePath = createRelativePath(propertyName, source, context); return { absolutePath: absolutePath, relativePath: relativePath, segments: segments }; } exports.createContext = createContext; function createRelativePath(propertyName, source, context) { if (!Array.isArray(source)) { return context.relativePath ? context.relativePath + "." + propertyName : propertyName; } return context.relativePath; }