@oada/oadaify
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -40,3 +40,4 @@ /** | ||
export declare type JsonValue = string | number | boolean | null | JsonObject | JsonArray; | ||
declare type OADAified<T> = T extends JsonValue ? OADAifiedJsonValue<T> : never; | ||
export declare type OADAified<T> = T extends JsonValue ? OADAifiedJsonValue<T> : T; | ||
declare type OADAifyKey<T, K> = K extends keyof T ? T[K] : never; | ||
/** | ||
@@ -46,9 +47,9 @@ * @todo Better name | ||
export declare type OADAifiedJsonObject<T extends JsonObject = JsonObject> = { | ||
[_id]?: OADAified<T['_id']>; | ||
[_rev]?: OADAified<T['_rev']>; | ||
[_type]?: OADAified<T['_type']>; | ||
[_id]: OADAifyKey<T, '_id'>; | ||
[_rev]: OADAifyKey<T, '_rev'>; | ||
[_type]: OADAifyKey<T, '_type'>; | ||
/** | ||
* @todo OADAify under _meta or not? | ||
*/ | ||
[_meta]?: OADAified<T['_meta']>; | ||
[_meta]: OADAified<T['_meta']>; | ||
} & { | ||
@@ -75,3 +76,3 @@ [K in keyof Except<T, keyof typeof Symbols>]: OADAified<T[K]>; | ||
*/ | ||
export declare function oadaify<T extends Readonly<JsonValue>>(value: T, deep?: boolean): OADAifiedJsonValue<T>; | ||
export declare function oadaify<T extends JsonValue>(value: T, deep?: boolean): OADAified<T>; | ||
/** | ||
@@ -84,4 +85,4 @@ * Inverse of oadaify | ||
*/ | ||
export declare function deoadaify<T extends JsonValue>(value: OADAifiedJsonValue<T>): T; | ||
export declare function deoadaify<T extends JsonValue>(value: OADAified<T>): T; | ||
export default oadaify; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@oada/oadaify", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Make OADA data nicer to work with in JS/TS", | ||
@@ -53,5 +53,5 @@ "keywords": [ | ||
"@tsconfig/node12": "^1.0.9", | ||
"@types/node": "^14.18.10", | ||
"@typescript-eslint/eslint-plugin": "^5.10.2", | ||
"@typescript-eslint/parser": "^5.10.2", | ||
"@types/node": "^12.20.43", | ||
"@typescript-eslint/eslint-plugin": "^5.11.0", | ||
"@typescript-eslint/parser": "^5.11.0", | ||
"@yarnpkg/sdks": "^2.6.0-rc.6", | ||
@@ -62,4 +62,4 @@ "ajv": "^8.10.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-xo": "^0.39.0", | ||
"eslint-config-xo-typescript": "^0.49.0", | ||
"eslint-config-xo": "^0.40.0", | ||
"eslint-config-xo-typescript": "^0.50.0", | ||
"eslint-formatter-pretty": "^4.1.0", | ||
@@ -88,8 +88,14 @@ "eslint-import-resolver-node": "^0.3.6", | ||
"ts-expect": "^1.3.0", | ||
"type-fest": "^2.11.2", | ||
"typescript": "^4.5.5" | ||
}, | ||
"dependencies": { | ||
"peerDependencies": { | ||
"type-fest": "^2.11.2" | ||
}, | ||
"peerDependenciesMeta": { | ||
"type-fest": { | ||
"optional": true | ||
} | ||
}, | ||
"packageManager": "yarn@3.1.1" | ||
} |
# @OADA/oadaify | ||
A library to make working with OADA data in JavaSript/TypeScript less annoying. | ||
A library to make working with OADA data in JavaScript/TypeScript less annoying. | ||
@@ -5,0 +5,0 @@ I was always writing loops with checks to skip `_` keys, |
@@ -54,4 +54,6 @@ /** | ||
type OADAified<T> = T extends JsonValue ? OADAifiedJsonValue<T> : never; | ||
export type OADAified<T> = T extends JsonValue ? OADAifiedJsonValue<T> : T; | ||
type OADAifyKey<T, K> = K extends keyof T ? T[K] : never; | ||
/** | ||
@@ -61,9 +63,9 @@ * @todo Better name | ||
export type OADAifiedJsonObject<T extends JsonObject = JsonObject> = { | ||
[_id]?: OADAified<T['_id']>; | ||
[_rev]?: OADAified<T['_rev']>; | ||
[_type]?: OADAified<T['_type']>; | ||
[_id]: OADAifyKey<T, '_id'>; | ||
[_rev]: OADAifyKey<T, '_rev'>; | ||
[_type]: OADAifyKey<T, '_type'>; | ||
/** | ||
* @todo OADAify under _meta or not? | ||
*/ | ||
[_meta]?: OADAified<T['_meta']>; | ||
[_meta]: OADAified<T['_meta']>; | ||
} & { | ||
@@ -97,5 +99,3 @@ [K in keyof Except<T, keyof typeof Symbols>]: OADAified<T[K]>; | ||
function isArray<T>( | ||
value: T | T[] | readonly T[] | ||
): value is T[] | readonly T[] { | ||
function isArray(value: unknown): value is unknown[] | readonly unknown[] { | ||
return Array.isArray(value); | ||
@@ -110,6 +110,6 @@ } | ||
*/ | ||
export function oadaify<T extends Readonly<JsonValue>>( | ||
export function oadaify<T extends JsonValue>( | ||
value: T, | ||
deep?: boolean | ||
): OADAifiedJsonValue<T>; | ||
): OADAified<T>; | ||
export function oadaify(value: JsonValue, deep = true): OADAifiedJsonValue { | ||
@@ -128,3 +128,3 @@ if (!value || typeof value !== 'object') { | ||
const out: OADAifiedJsonObject = deep | ||
const out: Partial<OADAifiedJsonObject> = deep | ||
? Object.fromEntries( | ||
@@ -177,3 +177,3 @@ Object.entries(value).map(([k, v]) => [k, oadaify(v!)!]) | ||
return out; | ||
return out as OADAifiedJsonObject; | ||
} | ||
@@ -188,5 +188,3 @@ | ||
*/ | ||
export function deoadaify<T extends JsonValue>( | ||
value: OADAifiedJsonValue<T> | ||
): T { | ||
export function deoadaify<T extends JsonValue>(value: OADAified<T>): T { | ||
if (!value || typeof value !== 'object') { | ||
@@ -201,3 +199,3 @@ return value as T; | ||
const out = Object.fromEntries( | ||
Object.entries(value).map(([k, v]) => [k, deoadaify<JsonValue>(v)]) | ||
Object.entries(value).map(([k, v]) => [k, deoadaify<JsonValue>(v!)]) | ||
); | ||
@@ -204,0 +202,0 @@ |
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
57065
37
1071
- Removedtype-fest@^2.11.2