@xylabs/object
Advanced tools
Comparing version 2.89.0 to 2.89.1
@@ -113,2 +113,26 @@ var __defProp = Object.defineProperty; | ||
// src/JsonObject.ts | ||
var isJsonValue = /* @__PURE__ */ __name((value) => { | ||
switch (typeof value) { | ||
case "string": | ||
case "number": | ||
case "boolean": { | ||
return true; | ||
} | ||
default: { | ||
return value === null || isJsonObject(value) || isJsonArray(value); | ||
} | ||
} | ||
}, "isJsonValue"); | ||
var isJsonArray = /* @__PURE__ */ __name((value) => { | ||
return Array.isArray(value) && !value.some((item) => !isJsonValue(item)); | ||
}, "isJsonArray"); | ||
var isValidJsonFieldPair = /* @__PURE__ */ __name(([key, value]) => { | ||
return typeof key === "string" && isJsonValue(value); | ||
}, "isValidJsonFieldPair"); | ||
var isJsonObject = /* @__PURE__ */ __name((value) => { | ||
return isObject(value) && //check if all keys are strings | ||
!Object.entries(value).some((item) => !isValidJsonFieldPair(item)); | ||
}, "isJsonObject"); | ||
// src/ObjectWrapper.ts | ||
@@ -142,5 +166,9 @@ var ObjectWrapper = class { | ||
asAnyObject, | ||
isJsonArray, | ||
isJsonObject, | ||
isJsonValue, | ||
isObject, | ||
isType | ||
isType, | ||
isValidJsonFieldPair | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,6 @@ export type JsonValue = string | number | boolean | null | JsonObject | JsonArray; | ||
export type JsonArray = JsonValue[]; | ||
export declare const isJsonValue: (value: unknown) => value is JsonValue; | ||
export declare const isJsonArray: (value: unknown) => value is JsonArray; | ||
export declare const isValidJsonFieldPair: ([key, value]: [key: unknown, value: unknown]) => boolean; | ||
export declare const isJsonObject: (value: unknown) => value is JsonObject; | ||
//# sourceMappingURL=JsonObject.d.ts.map |
@@ -118,2 +118,26 @@ var __defProp = Object.defineProperty; | ||
// src/JsonObject.ts | ||
var isJsonValue = /* @__PURE__ */ __name((value) => { | ||
switch (typeof value) { | ||
case "string": | ||
case "number": | ||
case "boolean": { | ||
return true; | ||
} | ||
default: { | ||
return value === null || isJsonObject(value) || isJsonArray(value); | ||
} | ||
} | ||
}, "isJsonValue"); | ||
var isJsonArray = /* @__PURE__ */ __name((value) => { | ||
return Array.isArray(value) && !value.some((item) => !isJsonValue(item)); | ||
}, "isJsonArray"); | ||
var isValidJsonFieldPair = /* @__PURE__ */ __name(([key, value]) => { | ||
return typeof key === "string" && isJsonValue(value); | ||
}, "isValidJsonFieldPair"); | ||
var isJsonObject = /* @__PURE__ */ __name((value) => { | ||
return isObject(value) && //check if all keys are strings | ||
!Object.entries(value).some((item) => !isValidJsonFieldPair(item)); | ||
}, "isJsonObject"); | ||
// src/ObjectWrapper.ts | ||
@@ -145,5 +169,9 @@ var _ObjectWrapper = class _ObjectWrapper { | ||
asAnyObject, | ||
isJsonArray, | ||
isJsonObject, | ||
isJsonValue, | ||
isObject, | ||
isType | ||
isType, | ||
isValidJsonFieldPair | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,6 @@ export type JsonValue = string | number | boolean | null | JsonObject | JsonArray; | ||
export type JsonArray = JsonValue[]; | ||
export declare const isJsonValue: (value: unknown) => value is JsonValue; | ||
export declare const isJsonArray: (value: unknown) => value is JsonArray; | ||
export declare const isValidJsonFieldPair: ([key, value]: [key: unknown, value: unknown]) => boolean; | ||
export declare const isJsonObject: (value: unknown) => value is JsonObject; | ||
//# sourceMappingURL=JsonObject.d.ts.map |
@@ -14,5 +14,5 @@ { | ||
"dependencies": { | ||
"@xylabs/assert": "^2.14.0", | ||
"@xylabs/logger": "^2.14.0", | ||
"@xylabs/promise": "^2.14.0" | ||
"@xylabs/assert": "^2.14.1", | ||
"@xylabs/logger": "^2.14.1", | ||
"@xylabs/promise": "^2.14.1" | ||
}, | ||
@@ -62,4 +62,4 @@ "devDependencies": { | ||
"sideEffects": false, | ||
"version": "2.89.0", | ||
"version": "2.89.1", | ||
"type": "module" | ||
} |
@@ -0,3 +1,34 @@ | ||
import { isObject } from './isObject' | ||
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray | ||
export type JsonObject = { [key: string]: JsonValue } | ||
export type JsonArray = JsonValue[] | ||
export const isJsonValue = (value: unknown): value is JsonValue => { | ||
switch (typeof value) { | ||
case 'string': | ||
case 'number': | ||
case 'boolean': { | ||
return true | ||
} | ||
default: { | ||
return value === null || isJsonObject(value) || isJsonArray(value) | ||
} | ||
} | ||
} | ||
export const isJsonArray = (value: unknown): value is JsonArray => { | ||
return Array.isArray(value) && !value.some((item) => !isJsonValue(item)) | ||
} | ||
export const isValidJsonFieldPair = ([key, value]: [key: unknown, value: unknown]) => { | ||
return typeof key === 'string' && isJsonValue(value) | ||
} | ||
export const isJsonObject = (value: unknown): value is JsonObject => { | ||
return ( | ||
isObject(value) && | ||
//check if all keys are strings | ||
!Object.entries(value).some((item) => !isValidJsonFieldPair(item)) | ||
) | ||
} |
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
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
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
194486
1166
Updated@xylabs/assert@^2.14.1
Updated@xylabs/logger@^2.14.1
Updated@xylabs/promise@^2.14.1