@statoscope/helpers
Advanced tools
Comparing version 5.6.1 to 5.7.0-alpha.0
export declare type Entities<TEntity> = TEntity[] | Set<TEntity> | Map<unknown, TEntity> | Record<string, TEntity>; | ||
export declare type Resolver<TID, TEntity> = (id: TID) => TEntity | null; | ||
export declare type GetIDFn<TID, TEntity> = (entity: TEntity) => TID; | ||
export default function makeResolver<TID, TEntity>(entities: Entities<TEntity>, getId: (entity: TEntity) => TID): Resolver<TID, TEntity>; | ||
export default function makeResolver<TID, TEntity, TReturn = TEntity>(entities: Entities<TEntity>, getId: (entity: TEntity) => TID, get?: (entity: TEntity) => TReturn): Resolver<TID, TReturn>; |
@@ -21,3 +21,3 @@ "use strict"; | ||
} | ||
function makeResolver(entities, getId) { | ||
function makeResolver(entities, getId, get) { | ||
const cache = new Map(); | ||
@@ -28,3 +28,3 @@ warnCache(entities, getId, cache); | ||
if (cached) { | ||
return cached; | ||
return get ? get(cached) : cached; | ||
} | ||
@@ -63,4 +63,5 @@ let result = null; | ||
cache.set(id, result); | ||
return (get ? get(result) : result); | ||
} | ||
return result; | ||
return null; | ||
}; | ||
@@ -67,0 +68,0 @@ } |
@@ -46,2 +46,5 @@ "use strict"; | ||
function walk(module, entry) { | ||
if (module === entry) { | ||
total++; | ||
} | ||
if (solutions.has(module)) { | ||
@@ -57,6 +60,2 @@ return solutions.get(module); | ||
solutions.set(module, solution); | ||
if (module === entry) { | ||
total++; | ||
return solution; | ||
} | ||
let find = false; | ||
@@ -63,0 +62,0 @@ for (const parent of module.parents) { |
@@ -11,3 +11,3 @@ import type Graph from './'; | ||
addChild(node: Node<TData>): void; | ||
findPathsTo(node: Node<TData>, max?: number): PathSolution<TData> | null; | ||
findPathsTo(node: Node<TData>, max?: number): PathSolution<TData>; | ||
} |
import jora from './jora'; | ||
export { jora }; | ||
export { default as makeASCIITree } from './asciiTree'; |
@@ -6,5 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jora = void 0; | ||
exports.makeASCIITree = exports.jora = void 0; | ||
const jora_1 = __importDefault(require("./jora")); | ||
exports.jora = jora_1.default; | ||
var asciiTree_1 = require("./asciiTree"); | ||
Object.defineProperty(exports, "makeASCIITree", { enumerable: true, get: function () { return __importDefault(asciiTree_1).default; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { SemVer } from 'semver'; | ||
import { Range, SemVer } from 'semver'; | ||
import { Item } from '../network-type-list'; | ||
@@ -32,4 +32,23 @@ import Graph, { Node as GraphNode, PathSolution } from '../graph'; | ||
} | ||
export declare type Limit = { | ||
type: 'absolute'; | ||
number: number; | ||
} | { | ||
type: 'percent'; | ||
number: number; | ||
}; | ||
export declare type ValueDiff = { | ||
absolute: number; | ||
percent: number; | ||
}; | ||
export declare type SerializedStringOrRegexp = { | ||
type: 'string'; | ||
content: string; | ||
} | { | ||
type: 'regexp'; | ||
content: string; | ||
flags: string; | ||
}; | ||
export declare type DiffItem = TimeDiffItem | SizeDiffItem | NumberDiffItem | VersionDiffItem; | ||
declare const _default: () => { | ||
export default function helpers(): { | ||
stringify: { | ||
@@ -39,2 +58,8 @@ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; | ||
}; | ||
typeof(value: unknown): string; | ||
isNullish(value: unknown): boolean; | ||
isArray(value: unknown): boolean; | ||
useNotNullish(values: unknown[]): unknown | null; | ||
serializeStringOrRegexp(value?: string | RegExp | undefined): SerializedStringOrRegexp | null; | ||
deserializeStringOrRegexp(value?: SerializedStringOrRegexp | null | undefined): string | RegExp | null; | ||
toNumber(str: string): number; | ||
@@ -66,6 +91,20 @@ formatSize(value: number): string; | ||
semverParse(version?: string | undefined): SemVer | null; | ||
semverSatisfies(version: string | SemVer, range: string | Range): boolean; | ||
formatDiff(value: DiffItem): string; | ||
isMatch(a?: string | undefined, b?: string | RegExp | undefined): boolean; | ||
exclude<TItem>(items: TItem[], params?: { | ||
exclude?: (string | RegExp)[] | undefined; | ||
get?: ((arg: TItem) => string | undefined) | undefined; | ||
} | undefined): TItem[]; | ||
graph_getNode<TData>(id?: string | undefined, graph?: Graph<TData> | undefined): GraphNode<TData> | null; | ||
graph_getPaths<TData_1>(from?: GraphNode<TData_1> | undefined, graph?: Graph<TData_1> | undefined, to?: GraphNode<TData_1> | undefined, max?: number): PathSolution<TData_1> | null; | ||
diff_normalizeLimit(limit?: number | Limit | null | undefined): Limit | null; | ||
diff_isLTETheLimit(valueDiff: ValueDiff, limit?: number | Limit | null | undefined): boolean; | ||
}; | ||
export default _default; | ||
export declare type Prepared = { | ||
query: (query: string, data?: unknown, context?: unknown) => unknown; | ||
}; | ||
export declare type Options = { | ||
helpers?: Record<string, unknown>; | ||
}; | ||
export declare function prepareWithJora(input: unknown, options?: Options): Prepared; |
@@ -25,3 +25,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.prepareWithJora = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
// @ts-ignore | ||
const jora_1 = __importDefault(require("jora")); | ||
const diff_1 = __importDefault(require("semver/functions/diff")); | ||
@@ -34,9 +37,46 @@ const gt_1 = __importDefault(require("semver/functions/gt")); | ||
const parse_1 = __importDefault(require("semver/functions/parse")); | ||
const satisfies_1 = __importDefault(require("semver/functions/satisfies")); | ||
const network_type_list_1 = __importStar(require("../network-type-list")); | ||
const colors_1 = require("./colors"); | ||
const plural_1 = require("./plural"); | ||
const identityFn = (arg) => arg; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
exports.default = () => { | ||
function helpers() { | ||
const helpers = { | ||
stringify: JSON.stringify, | ||
typeof(value) { | ||
return typeof value; | ||
}, | ||
isNullish(value) { | ||
return value == null; | ||
}, | ||
isArray(value) { | ||
return Array.isArray(value); | ||
}, | ||
useNotNullish(values) { | ||
for (const value of values) { | ||
if (value != null) { | ||
return value; | ||
} | ||
} | ||
return null; | ||
}, | ||
serializeStringOrRegexp(value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value instanceof RegExp) { | ||
return { type: 'regexp', content: value.source, flags: value.flags }; | ||
} | ||
return { type: 'string', content: value }; | ||
}, | ||
deserializeStringOrRegexp(value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value.type === 'regexp') { | ||
return new RegExp(value.content, value.flags); | ||
} | ||
return value.content; | ||
}, | ||
toNumber(str) { | ||
@@ -150,2 +190,5 @@ return parseInt(str, 10); | ||
}, | ||
semverSatisfies(version, range) { | ||
return satisfies_1.default(version, range); | ||
}, | ||
formatDiff(value) { | ||
@@ -169,2 +212,21 @@ var _a; | ||
}, | ||
isMatch(a, b) { | ||
if (!a || !b) { | ||
return a === b; | ||
} | ||
return b instanceof RegExp ? b.test(a) : a === b; | ||
}, | ||
exclude(items, params) { | ||
return items.filter((item) => { | ||
var _a, _b; | ||
for (const excludeItem of (_a = params === null || params === void 0 ? void 0 : params.exclude) !== null && _a !== void 0 ? _a : []) { | ||
const getter = (_b = params === null || params === void 0 ? void 0 : params.get) !== null && _b !== void 0 ? _b : identityFn; | ||
const value = getter(item); | ||
if (this.isMatch(value, excludeItem)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
}, | ||
graph_getNode(id, graph) { | ||
@@ -180,5 +242,29 @@ var _a; | ||
}, | ||
diff_normalizeLimit(limit) { | ||
return typeof limit === 'number' | ||
? { type: 'absolute', number: limit } | ||
: limit !== null && limit !== void 0 ? limit : null; | ||
}, | ||
diff_isLTETheLimit(valueDiff, limit) { | ||
const normalizedLimit = this.diff_normalizeLimit(limit); | ||
return (!normalizedLimit || | ||
(normalizedLimit.type === 'absolute' | ||
? valueDiff.absolute <= normalizedLimit.number | ||
: valueDiff.percent <= normalizedLimit.number)); | ||
}, | ||
}; | ||
return helpers; | ||
}; | ||
} | ||
exports.default = helpers; | ||
function prepareWithJora(input, options = {}) { | ||
const j = jora_1.default.setup({ | ||
...helpers(), | ||
...options.helpers, | ||
}); | ||
const rootContext = {}; | ||
return { | ||
query: (query, data = input, context = rootContext) => j(query)(data || input, context), | ||
}; | ||
} | ||
exports.prepareWithJora = prepareWithJora; | ||
//# sourceMappingURL=index.js.map |
@@ -9,3 +9,3 @@ export declare type Item = { | ||
type: string; | ||
name: string; | ||
name: "Slow"; | ||
typicalSpeed: number; | ||
@@ -15,17 +15,113 @@ }; | ||
type: string; | ||
name: string; | ||
name: "Fast"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_GPRS: Item; | ||
export declare const TYPE_EDGE: Item; | ||
export declare const TYPE_Basic: Item; | ||
export declare const TYPE_HSPA: Item; | ||
export declare const TYPE_HSPA_PLUS: Item; | ||
export declare const TYPE_DC_HSPA_PLUS: Item; | ||
export declare const TYPE_LTE_CAT_4: Item; | ||
export declare const TYPE_LTE_CAT_6: Item; | ||
export declare const TYPE_LTE_CAT_9: Item; | ||
export declare const TYPE_LTE_CAT_12: Item; | ||
export declare const TYPE_5G: Item; | ||
declare const _default: Item[]; | ||
export declare const TYPE_GPRS: { | ||
type: string; | ||
name: "GPRS"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_EDGE: { | ||
type: string; | ||
name: "EDGE"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_Basic: { | ||
type: string; | ||
name: "Basic"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_HSPA: { | ||
type: string; | ||
name: "HSPA"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_HSPA_PLUS: { | ||
type: string; | ||
name: "HSPA+"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_DC_HSPA_PLUS: { | ||
type: string; | ||
name: "DC-HSPA+"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_LTE_CAT_4: { | ||
type: string; | ||
name: "LTE cat.4"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_LTE_CAT_6: { | ||
type: string; | ||
name: "LTE cat.6"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_LTE_CAT_9: { | ||
type: string; | ||
name: "LTE cat.9"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_LTE_CAT_12: { | ||
type: string; | ||
name: "LTE cat.12"; | ||
typicalSpeed: number; | ||
}; | ||
export declare const TYPE_5G: { | ||
type: string; | ||
name: "5G"; | ||
typicalSpeed: number; | ||
}; | ||
declare const _default: readonly [{ | ||
type: string; | ||
name: "Slow"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "Fast"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "GPRS"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "EDGE"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "Basic"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "HSPA"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "HSPA+"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "DC-HSPA+"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "LTE cat.4"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "LTE cat.6"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "LTE cat.9"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "LTE cat.12"; | ||
typicalSpeed: number; | ||
}, { | ||
type: string; | ||
name: "5G"; | ||
typicalSpeed: number; | ||
}]; | ||
export default _default; |
{ | ||
"name": "@statoscope/helpers", | ||
"version": "5.6.1", | ||
"version": "5.7.0-alpha.0", | ||
"description": "Statoscope utils", | ||
@@ -24,6 +24,9 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@types/archy": "^0.0.32", | ||
"@types/semver": "^7.3.6", | ||
"archy": "~1.0.0", | ||
"jora": "^1.0.0-beta.5", | ||
"semver": "^7.3.5" | ||
}, | ||
"gitHead": "3703e8dfdfa5a9311908ba6804a68b23c195945c" | ||
"gitHead": "d87b4b850ad9ff1f94110fb017bb915a77ed4c62" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
50097
30
919
0
7
5
1
+ Added@types/archy@^0.0.32
+ Addedarchy@~1.0.0
+ Addedjora@^1.0.0-beta.5
+ Added@discoveryjs/natural-compare@1.1.0(transitive)
+ Added@types/archy@0.0.32(transitive)
+ Addedarchy@1.0.0(transitive)
+ Addedjora@1.0.0-beta.13(transitive)