@stoplight/common
Advanced tools
Comparing version 0.0.11-25 to 0.0.11-26
export declare const stringify: (target: any, replacer?: ((key: any, value: any) => any) | undefined, offset?: number | undefined) => any; | ||
export declare const parse: (target: string) => any; | ||
export declare const decycle: (target: object) => any; | ||
export declare const getValue: (obj: any, path: string | string[], defaultVal?: boolean | undefined) => any; | ||
export declare const setValue: (obj: any, path: string | string[], value: any) => any; | ||
export declare const unsetValue: (obj: any, path: string | string[]) => boolean; | ||
export declare const startsWith: (source: string | any[], val: string | any[]) => boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fast_safe_stringify_1 = require("fast-safe-stringify"); | ||
var fast_safe_stringify_1 = require("@stoplight/fast-safe-stringify"); | ||
// @ts-ignore | ||
@@ -11,12 +11,22 @@ var _get = require("get-value"); | ||
exports.stringify = function (target, replacer, offset) { | ||
if (target && typeof target !== 'string') { | ||
try { | ||
// try regular stringify first as mentioned in this tip: https://github.com/davidmarkclements/fast-safe-stringify#protip | ||
return JSON.stringify(target, replacer, offset); | ||
} | ||
catch (_) { | ||
// @ts-ignore | ||
return fast_safe_stringify_1.default(target, replacer, offset); | ||
} | ||
if (!target || typeof target === 'string') | ||
return target; | ||
try { | ||
// try regular stringify first as mentioned in this tip: https://github.com/davidmarkclements/fast-safe-stringify#protip | ||
return JSON.stringify(target, replacer, offset); | ||
} | ||
catch (_) { | ||
// @ts-ignore | ||
return fast_safe_stringify_1.default(target, replacer, offset); | ||
} | ||
}; | ||
exports.parse = function (target) { | ||
if (typeof target !== 'string') | ||
return target; | ||
return JSON.parse(target); | ||
}; | ||
exports.decycle = function (target) { | ||
if (typeof target !== 'object') | ||
return target; | ||
fast_safe_stringify_1.default.decirc(target, '', []); | ||
return target; | ||
@@ -33,2 +43,34 @@ }; | ||
}; | ||
exports.startsWith = function (source, val) { | ||
if (source instanceof Array) { | ||
if (val instanceof Array) { | ||
if (val.length > source.length) | ||
return false; | ||
for (var i in val) { | ||
if (!val.hasOwnProperty(i)) | ||
continue; | ||
var si = parseInt(source[i]); | ||
var vi = parseInt(val[i]); | ||
// support if numeric index is stringified in one but not the other | ||
if (!isNaN(si) || !isNaN(vi)) { | ||
if (si !== vi) { | ||
return false; | ||
} | ||
} | ||
else if (source[i] !== val[i]) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
else if (typeof source === 'string') { | ||
if (typeof val === 'string') { | ||
return source.startsWith(val); | ||
} | ||
} | ||
else { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
//# sourceMappingURL=json.js.map |
{ | ||
"name": "@stoplight/common", | ||
"version": "0.0.11-25", | ||
"version": "0.0.11-26", | ||
"description": "Stoplight common type and interface definitions.", | ||
@@ -24,3 +24,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"fast-safe-stringify": "2.0.x", | ||
"@stoplight/fast-safe-stringify": "2.0.x", | ||
"get-value": "3.x.x", | ||
@@ -27,0 +27,0 @@ "set-value": "3.x.x", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
88192
1570
+ Added@stoplight/fast-safe-stringify@2.0.3(transitive)
- Removedfast-safe-stringify@2.0.x
- Removedfast-safe-stringify@2.0.8(transitive)