@dbpath/utils
Advanced tools
| export declare function deepSort(t: any): any; | ||
| export declare function deepSortNames(t: any): any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.deepSortNames = exports.deepSort = void 0; | ||
| function deepSort(t) { | ||
| if (Array.isArray(t)) | ||
| return t.map(deepSort).sort(); | ||
| if (typeof t === 'object') { | ||
| const res = {}; | ||
| Object.entries(t).sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(kv => res[kv[0]] = deepSort(kv[1])); | ||
| return res; | ||
| } | ||
| return t; | ||
| } | ||
| exports.deepSort = deepSort; | ||
| function deepSortNames(t) { | ||
| if (Array.isArray(t)) | ||
| return t.map(deepSortNames).sort(); | ||
| if (typeof t === 'object') { | ||
| const res = {}; | ||
| Object.entries(t).sort((a, b) => a[0].toString().localeCompare(b[0].toString())).forEach(kv => res[kv[0]] = deepSortNames(kv[1])); | ||
| return res; | ||
| } | ||
| return t; | ||
| } | ||
| exports.deepSortNames = deepSortNames; |
+7
-6
@@ -1,10 +0,11 @@ | ||
| export * from './src/safe'; | ||
| export * from './src/nameAnd'; | ||
| export * from "./src/columns"; | ||
| export * from './src/combine'; | ||
| export * from './src/utils'; | ||
| export * from './src/errors'; | ||
| export * from './src/json'; | ||
| export * from "./src/maputils"; | ||
| export * from './src/nameAnd'; | ||
| export * from './src/safe'; | ||
| export * from "./src/strings"; | ||
| export * from "./src/sort"; | ||
| export * from './src/utils'; | ||
| export * from "./src/validators"; | ||
| export * from "./src/strings"; | ||
| export * from "./src/columns"; | ||
| export * from "./src/maputils"; |
+7
-6
@@ -17,11 +17,12 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./src/safe"), exports); | ||
| __exportStar(require("./src/nameAnd"), exports); | ||
| __exportStar(require("./src/columns"), exports); | ||
| __exportStar(require("./src/combine"), exports); | ||
| __exportStar(require("./src/utils"), exports); | ||
| __exportStar(require("./src/errors"), exports); | ||
| __exportStar(require("./src/json"), exports); | ||
| __exportStar(require("./src/maputils"), exports); | ||
| __exportStar(require("./src/nameAnd"), exports); | ||
| __exportStar(require("./src/safe"), exports); | ||
| __exportStar(require("./src/strings"), exports); | ||
| __exportStar(require("./src/sort"), exports); | ||
| __exportStar(require("./src/utils"), exports); | ||
| __exportStar(require("./src/validators"), exports); | ||
| __exportStar(require("./src/strings"), exports); | ||
| __exportStar(require("./src/columns"), exports); | ||
| __exportStar(require("./src/maputils"), exports); |
@@ -9,2 +9,5 @@ export type ErrorFn<From, To> = (value: From) => ErrorsAnd<To>; | ||
| export declare function mapErrors<T, T1>(t: ErrorsAnd<T>, fn: (t: T) => ErrorsAnd<T1>): ErrorsAnd<T1>; | ||
| export declare function mapAndforEachErrorFn<T, Acc, T1>(ts: T[], mapFn: (t: T) => ErrorsAnd<T1>, forEach: (t1: T1, index: number) => Acc): ErrorsAnd<void>; | ||
| export declare function allErrorsIn<T>(ts: ErrorsAnd<T>[]): string[]; | ||
| export declare function allValuesIn<T>(ts: ErrorsAnd<T>[]): T[]; | ||
| export declare function mapErrorsK<T, T1>(t: ErrorsAnd<T>, fn: (t: T) => Promise<ErrorsAnd<T1>>): Promise<ErrorsAnd<T1>>; | ||
@@ -11,0 +14,0 @@ export declare function flattenErrors<T>(t: ErrorsAnd<ErrorsAnd<T>>): ErrorsAnd<T>; |
+18
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.composeErrorFnAndThen = exports.composeErrorFn = exports.foldErrorsK = exports.foldErrors = exports.flatMapErrorsK = exports.flatMapErrors = exports.flattenErrors = exports.mapErrorsK = exports.mapErrors = exports.value = exports.errors = exports.hasErrors = exports.reportErrors = exports.mapArrayOfErrorsAnd = void 0; | ||
| exports.composeErrorFnAndThen = exports.composeErrorFn = exports.foldErrorsK = exports.foldErrors = exports.flatMapErrorsK = exports.flatMapErrors = exports.flattenErrors = exports.mapErrorsK = exports.allValuesIn = exports.allErrorsIn = exports.mapAndforEachErrorFn = exports.mapErrors = exports.value = exports.errors = exports.hasErrors = exports.reportErrors = exports.mapArrayOfErrorsAnd = void 0; | ||
| const utils_1 = require("./utils"); | ||
@@ -34,2 +34,19 @@ function mapArrayOfErrorsAnd(ts, fn) { | ||
| exports.mapErrors = mapErrors; | ||
| function mapAndforEachErrorFn(ts, mapFn, forEach) { | ||
| const raw = ts.map(mapFn); | ||
| const errors = allErrorsIn(raw); | ||
| if (errors.length > 0) | ||
| return errors; | ||
| const values = allValuesIn(raw); | ||
| values.forEach((t1, i) => forEach(t1, i)); | ||
| } | ||
| exports.mapAndforEachErrorFn = mapAndforEachErrorFn; | ||
| function allErrorsIn(ts) { | ||
| return (0, utils_1.flatMap)(ts, t => hasErrors(t) ? errors(t) : []); | ||
| } | ||
| exports.allErrorsIn = allErrorsIn; | ||
| function allValuesIn(ts) { | ||
| return (0, utils_1.flatMap)(ts, t => hasErrors(t) ? [] : [t]); | ||
| } | ||
| exports.allValuesIn = allValuesIn; | ||
| function mapErrorsK(t, fn) { | ||
@@ -36,0 +53,0 @@ return hasErrors(t) ? Promise.resolve(t) : fn(t); |
@@ -17,2 +17,3 @@ "use strict"; | ||
| const nameAnd_1 = require("./nameAnd"); | ||
| const sort_1 = require("./sort"); | ||
| describe('safeArray', () => { | ||
@@ -101,1 +102,23 @@ it("should return the array if defined", () => { | ||
| }); | ||
| describe("deepsort", () => { | ||
| it("should return param if not array or obejct", () => { | ||
| expect((0, sort_1.deepSort)(1)).toEqual(1); | ||
| expect((0, sort_1.deepSort)("1")).toEqual("1"); | ||
| }); | ||
| it("should sort arrays", () => { | ||
| expect((0, sort_1.deepSort)([[3, 2, 1], [1, 2, 3]])).toEqual([[1, 2, 3], [1, 2, 3]]); | ||
| }); | ||
| it("should sort objects", () => { | ||
| expect((0, sort_1.deepSort)({ w: 1, b: { z: 1, y: [3, 2, 1] } })).toEqual({ | ||
| "b": { | ||
| "y": [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], | ||
| "z": 1 | ||
| }, | ||
| "w": 1 | ||
| }); | ||
| }); | ||
| }); |
+1
-1
| { | ||
| "name": "@dbpath/utils", | ||
| "description": "", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "main": "dist/index", | ||
@@ -6,0 +6,0 @@ "types": "dist/index", |
+1
-1
@@ -1,1 +0,1 @@ | ||
| General utilities for db-auto: no domain knowledge at all in any of these | ||
| General utilities for dbpath: no domain knowledge at all in any of these |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
49399
5.9%35
6.06%997
7.78%