@blake.regalia/belt
Advanced tools
Comparing version 0.6.3 to 0.6.4
@@ -23,3 +23,3 @@ import type { Dict, JsonObject } from './types'; | ||
/** | ||
* More advanced test for whether an ES object is a plain object (dict) or not | ||
* Strict test for whether an ES object is a plain object (dict) or not | ||
*/ | ||
@@ -26,0 +26,0 @@ export declare const is_dict_es: (z: unknown) => z is JsonObject<never>; |
@@ -30,5 +30,5 @@ "use strict"; | ||
/** | ||
* More advanced test for whether an ES object is a plain object (dict) or not | ||
* Strict test for whether an ES object is a plain object (dict) or not | ||
*/ | ||
const is_dict_es = (z) => z ? 'object' === typeof z && Object === z.constructor : false; | ||
const is_dict_es = (z) => Object === z?.constructor; | ||
exports.is_dict_es = is_dict_es; | ||
@@ -159,3 +159,3 @@ /** | ||
*/ | ||
const fodemtv = (h_thing, f_transform) => Object.fromEntries((0, exports.ode)(h_thing).map(([si_key, w_value]) => [si_key, f_transform(w_value, si_key)])); | ||
const fodemtv = (h_thing, f_transform) => (0, exports.ofe)((0, exports.ode)(h_thing).map(([si_key, w_value]) => [si_key, f_transform(w_value, si_key)])); | ||
exports.fodemtv = fodemtv; | ||
@@ -162,0 +162,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import type { JsonValue } from './types'; | ||
import type { JsonObject, JsonValue } from './types'; | ||
export declare const uuid_v4: () => string; | ||
@@ -99,3 +99,3 @@ /** | ||
*/ | ||
export declare const canonicalize_json: (w_json: JsonValue) => JsonValue; | ||
export declare const canonicalize_json: <w_json extends JsonObject<never>>(w_json: w_json) => w_json; | ||
/** | ||
@@ -102,0 +102,0 @@ * Concatenate a sequence of Uint8Arrays. |
@@ -176,5 +176,5 @@ "use strict"; | ||
const canonicalize_json = (w_json) => { | ||
if ((0, belt_1.is_dict)(w_json)) { | ||
if ((0, belt_1.is_dict_es)(w_json)) { | ||
// sort all keys | ||
const h_sorted = Object.fromEntries(Object.entries(w_json).sort((a_a, a_b) => a_a[0] < a_b[0] ? -1 : 1)); | ||
const h_sorted = (0, belt_1.ofe)((0, belt_1.ode)(w_json).sort((a_a, a_b) => a_a[0] < a_b[0] ? -1 : 1)); | ||
// traverse on children | ||
@@ -181,0 +181,0 @@ for (const si_key in h_sorted) { |
@@ -23,3 +23,3 @@ import type { Dict, JsonObject } from './types'; | ||
/** | ||
* More advanced test for whether an ES object is a plain object (dict) or not | ||
* Strict test for whether an ES object is a plain object (dict) or not | ||
*/ | ||
@@ -26,0 +26,0 @@ export declare const is_dict_es: (z: unknown) => z is JsonObject<never>; |
@@ -23,5 +23,5 @@ /** | ||
/** | ||
* More advanced test for whether an ES object is a plain object (dict) or not | ||
* Strict test for whether an ES object is a plain object (dict) or not | ||
*/ | ||
export const is_dict_es = (z) => z ? 'object' === typeof z && Object === z.constructor : false; | ||
export const is_dict_es = (z) => Object === z?.constructor; | ||
/** | ||
@@ -141,3 +141,3 @@ * Fold array into an object | ||
*/ | ||
export const fodemtv = (h_thing, f_transform) => Object.fromEntries(ode(h_thing).map(([si_key, w_value]) => [si_key, f_transform(w_value, si_key)])); | ||
export const fodemtv = (h_thing, f_transform) => ofe(ode(h_thing).map(([si_key, w_value]) => [si_key, f_transform(w_value, si_key)])); | ||
/** | ||
@@ -144,0 +144,0 @@ * Promise-based version of `setTimeout()` |
@@ -1,2 +0,2 @@ | ||
import type { JsonValue } from './types'; | ||
import type { JsonObject, JsonValue } from './types'; | ||
export declare const uuid_v4: () => string; | ||
@@ -99,3 +99,3 @@ /** | ||
*/ | ||
export declare const canonicalize_json: (w_json: JsonValue) => JsonValue; | ||
export declare const canonicalize_json: <w_json extends JsonObject<never>>(w_json: w_json) => w_json; | ||
/** | ||
@@ -102,0 +102,0 @@ * Concatenate a sequence of Uint8Arrays. |
@@ -1,2 +0,2 @@ | ||
import { is_dict } from './belt'; | ||
import { is_dict, is_dict_es, ode, ofe } from './belt'; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
@@ -156,5 +156,5 @@ const S_UUID_V4 = 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'; | ||
export const canonicalize_json = (w_json) => { | ||
if (is_dict(w_json)) { | ||
if (is_dict_es(w_json)) { | ||
// sort all keys | ||
const h_sorted = Object.fromEntries(Object.entries(w_json).sort((a_a, a_b) => a_a[0] < a_b[0] ? -1 : 1)); | ||
const h_sorted = ofe(ode(w_json).sort((a_a, a_b) => a_a[0] < a_b[0] ? -1 : 1)); | ||
// traverse on children | ||
@@ -161,0 +161,0 @@ for (const si_key in h_sorted) { |
{ | ||
"name": "@blake.regalia/belt", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"repository": "github:blake-regalia/belt", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
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
156186