@glideapps/ts-necessities
Advanced tools
Comparing version 2.2.4 to 2.3.0
@@ -21,2 +21,3 @@ "use strict"; | ||
class DefaultMap extends Map { | ||
_defaultFunc; | ||
/** | ||
@@ -23,0 +24,0 @@ * |
@@ -56,5 +56,2 @@ /** | ||
}; | ||
export type DeepReadonly<T> = { | ||
readonly [P in keyof T]: DeepReadonly<T[P]>; | ||
}; | ||
/** | ||
@@ -100,2 +97,4 @@ * If `x` is undefined, return `undefined`. Otherwise, return `f(x)`. | ||
export declare function filterUndefined<T>(arr: Iterable<T | undefined>): T[]; | ||
export declare function mapRecord<T, U>(r: Record<string, T>, f: (v: T, n: string) => U): Record<string, U>; | ||
export declare function mapRecordFilterUndefined<T, U>(r: Record<string, T>, f: (v: T, n: string) => U | undefined): Record<string, U>; | ||
/** | ||
@@ -102,0 +101,0 @@ * Returns a string representation of `e`, which is supposed to be an |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeBrandString = exports.brandString = exports.DefaultMap = exports.exceptionToError = exports.exceptionToString = exports.filterUndefined = exports.mapFilterUndefined = exports.hasOwnProperty = exports.isArray = exports.isEnumValue = exports.definedMap = exports.reduceTwo = exports.sleep = exports.dontAwait = exports.defined = exports.assertNever = exports.assert = exports.panic = exports.proveNever = exports.proveType = void 0; | ||
exports.makeBrandString = exports.brandString = exports.DefaultMap = exports.exceptionToError = exports.exceptionToString = exports.mapRecordFilterUndefined = exports.mapRecord = exports.filterUndefined = exports.mapFilterUndefined = exports.hasOwnProperty = exports.isArray = exports.isEnumValue = exports.definedMap = exports.reduceTwo = exports.sleep = exports.dontAwait = exports.defined = exports.assertNever = exports.assert = exports.panic = exports.proveNever = exports.proveType = void 0; | ||
/** | ||
@@ -155,2 +155,21 @@ * Do nothing, but only compile if `_val` is of type `T`. | ||
exports.filterUndefined = filterUndefined; | ||
function mapRecord(r, f) { | ||
const result = {}; | ||
for (const [name, value] of Object.entries(r)) { | ||
result[name] = f(value, name); | ||
} | ||
return result; | ||
} | ||
exports.mapRecord = mapRecord; | ||
function mapRecordFilterUndefined(r, f) { | ||
const result = {}; | ||
for (const [name, value] of Object.entries(r)) { | ||
const o = f(value, name); | ||
if (o === undefined) | ||
continue; | ||
result[name] = o; | ||
} | ||
return result; | ||
} | ||
exports.mapRecordFilterUndefined = mapRecordFilterUndefined; | ||
/** | ||
@@ -170,3 +189,3 @@ * Returns a string representation of `e`, which is supposed to be an | ||
} | ||
catch (_a) { | ||
catch { | ||
return "Exception can't be stringified"; | ||
@@ -173,0 +192,0 @@ } |
{ | ||
"name": "@glideapps/ts-necessities", | ||
"version": "2.2.4", | ||
"version": "2.3.0", | ||
"description": "Small utilities to make life with TypeScript easier", | ||
@@ -27,4 +27,4 @@ "main": "dist/index.js", | ||
"typedoc": "^0.25.13", | ||
"typescript": "^5.4.4" | ||
"typescript": "^5.4.5" | ||
} | ||
} |
@@ -171,2 +171,23 @@ /** | ||
export function mapRecord<T, U>(r: Record<string, T>, f: (v: T, n: string) => U): Record<string, U> { | ||
const result: Record<string, U> = {}; | ||
for (const [name, value] of Object.entries(r)) { | ||
result[name] = f(value, name); | ||
} | ||
return result; | ||
} | ||
export function mapRecordFilterUndefined<T, U>( | ||
r: Record<string, T>, | ||
f: (v: T, n: string) => U | undefined | ||
): Record<string, U> { | ||
const result: Record<string, U> = {}; | ||
for (const [name, value] of Object.entries(r)) { | ||
const o = f(value, name); | ||
if (o === undefined) continue; | ||
result[name] = o; | ||
} | ||
return result; | ||
} | ||
/** | ||
@@ -173,0 +194,0 @@ * Returns a string representation of `e`, which is supposed to be an |
@@ -15,5 +15,5 @@ { | ||
"noImplicitReturns": true, | ||
"target": "es6", | ||
"target": "esnext", | ||
"outDir": "dist", | ||
"lib": ["es6", "dom"], | ||
"lib": ["es2017", "dom"], | ||
"baseUrl": "./src", | ||
@@ -20,0 +20,0 @@ "typeRoots": ["./node_modules/@types"] |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
37868
847
0