@unchainedshop/utils 5.0.0-alpha.1 → 5.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/lib/ch/priceToString.d.ts +2 -1
- package/lib/ch/priceToString.js +12 -3
- package/lib/director/BaseDirector.d.ts +0 -4
- package/lib/director/BaseDirector.js +1 -15
- package/lib/executeBulkOperation.d.ts +4 -0
- package/lib/executeBulkOperation.js +19 -0
- package/lib/generate-random-hash.js +3 -7
- package/lib/memoize-with-ttl.d.ts +8 -7
- package/lib/memoize-with-ttl.js +23 -31
- package/lib/phone-number.d.ts +5 -0
- package/lib/phone-number.js +17 -0
- package/lib/utils-index.d.ts +3 -1
- package/lib/utils-index.js +3 -1
- package/package.json +8 -5
- package/lib/repository/Repository.d.ts +0 -43
- package/lib/repository/Repository.js +0 -1
- package/lib/repository/index.d.ts +0 -1
- package/lib/repository/index.js +0 -1
- package/lib/specification/Specification.d.ts +0 -27
- package/lib/specification/Specification.js +0 -88
- package/lib/specification/index.d.ts +0 -1
- package/lib/specification/index.js +0 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @unchainedshop/utils
|
|
5
5
|
|
|
6
|
-
Common utility functions and
|
|
6
|
+
Common utility functions and adapter/director building blocks for the Unchained Engine.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -70,14 +70,13 @@ Available under the `calculation` namespace:
|
|
|
70
70
|
| `objectInvert` | Invert object keys and values |
|
|
71
71
|
| `buildObfuscatedFieldsFilter` | Build filter for obfuscating sensitive fields |
|
|
72
72
|
|
|
73
|
-
### Director/Adapter
|
|
73
|
+
### Director/Adapter Building Blocks
|
|
74
74
|
|
|
75
75
|
| Export | Description |
|
|
76
76
|
|--------|-------------|
|
|
77
|
-
| `BaseAdapter` | Base
|
|
78
|
-
| `BaseDirector` | Factory for creating adapter directors |
|
|
77
|
+
| `BaseAdapter` | Base object for adapter implementations with logging support |
|
|
79
78
|
| `IBaseAdapter` | Interface for adapter implementations |
|
|
80
|
-
| `IBaseDirector` | Interface
|
|
79
|
+
| `IBaseDirector` | Interface implemented by the directors in `@unchainedshop/core` (adapters come from the plugin registry) |
|
|
81
80
|
|
|
82
81
|
### Swiss-specific Helpers
|
|
83
82
|
|
package/lib/ch/priceToString.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
export const priceToString = ({ amount, currencyCode }) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
export const priceToString = ({ amount, currencyCode, locale = 'de-CH', }) => {
|
|
2
|
+
const majorUnitAmount = amount / 100;
|
|
3
|
+
try {
|
|
4
|
+
return new Intl.NumberFormat(locale, {
|
|
5
|
+
style: 'currency',
|
|
6
|
+
currency: currencyCode,
|
|
7
|
+
currencyDisplay: 'code',
|
|
8
|
+
}).format(majorUnitAmount);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return `${currencyCode} ${majorUnitAmount}`;
|
|
12
|
+
}
|
|
4
13
|
};
|
|
5
14
|
export default priceToString;
|
|
@@ -5,7 +5,3 @@ export interface IBaseDirector<Adapter extends IBaseAdapter> {
|
|
|
5
5
|
}) => Adapter[];
|
|
6
6
|
getAdapter: (key: string) => Adapter | null;
|
|
7
7
|
}
|
|
8
|
-
export declare const BaseDirector: <AdapterType extends IBaseAdapter>(directorName: string, options?: {
|
|
9
|
-
adapterSortKey?: string;
|
|
10
|
-
adapterKeyField?: string;
|
|
11
|
-
}) => IBaseDirector<AdapterType>;
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
const Adapters = new Map();
|
|
3
|
-
const keyField = options?.adapterKeyField || 'key';
|
|
4
|
-
return {
|
|
5
|
-
getAdapter: (key) => {
|
|
6
|
-
return Adapters.get(key) || null;
|
|
7
|
-
},
|
|
8
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
9
|
-
const sortKey = options?.adapterSortKey || keyField;
|
|
10
|
-
return Array.from(Adapters.values())
|
|
11
|
-
.toSorted((left, right) => left[sortKey] - right[sortKey])
|
|
12
|
-
.filter(adapterFilter || (() => true));
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
const logger = createLogger('unchained:utils:bulk-operation');
|
|
3
|
+
export async function executeBulkOperation(ids, operation) {
|
|
4
|
+
const successIds = [];
|
|
5
|
+
const failedIds = [];
|
|
6
|
+
for (const id of new Set(ids)) {
|
|
7
|
+
try {
|
|
8
|
+
await operation(id);
|
|
9
|
+
successIds.push(id);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
failedIds.push(id);
|
|
13
|
+
logger.debug(`Bulk operation failed for entity ${String(id)}`, {
|
|
14
|
+
error: error instanceof Error ? error.message : String(error),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { successIds, failedIds };
|
|
19
|
+
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
export default () => {
|
|
4
|
-
const randomBytes = crypto.getRandomValues(new Uint32Array(1));
|
|
5
|
-
const randomNumber = (randomBytes[0] % 999999998) + 1;
|
|
6
|
-
return hashids.encode(randomNumber);
|
|
7
|
-
};
|
|
1
|
+
import { randomInt } from 'node:crypto';
|
|
2
|
+
const ALPHABET = 'ABCDEFGHIJKLMNPQRSTUVWXYZ23456789';
|
|
3
|
+
export default () => Array.from({ length: 6 }, () => ALPHABET[randomInt(ALPHABET.length)]).join('');
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
cacheKey?: (args: any[]) => string;
|
|
4
|
-
}
|
|
5
|
-
export declare function memoizeWithTTL<T extends AsyncFunction>(fn: T, ttlMs: number, options?: MemoizeOptions): T & {
|
|
1
|
+
export interface MemoizedWithTTL<A extends unknown[], R> {
|
|
2
|
+
(...args: A): Promise<R>;
|
|
6
3
|
clear: () => void;
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
delete: (key: unknown) => boolean;
|
|
5
|
+
}
|
|
6
|
+
export default function memoizeWithTTL<A extends unknown[], R>(fn: (...args: A) => Promise<R>, { ttl, cacheKey }: {
|
|
7
|
+
ttl: number;
|
|
8
|
+
cacheKey?: (args: A) => unknown;
|
|
9
|
+
}): MemoizedWithTTL<A, R>;
|
package/lib/memoize-with-ttl.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
set(key,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const cache = createTTLCache(ttlMs);
|
|
24
|
-
const memoized = async function (...args) {
|
|
25
|
-
const key = options?.cacheKey ? options.cacheKey(args) : JSON.stringify(args);
|
|
26
|
-
const cached = cache.get(key);
|
|
27
|
-
if (cached !== undefined)
|
|
28
|
-
return cached;
|
|
29
|
-
const result = await fn(...args);
|
|
30
|
-
cache.set(key, result);
|
|
31
|
-
return result;
|
|
1
|
+
export default function memoizeWithTTL(fn, { ttl, cacheKey = (args) => args[0] }) {
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
const memoized = (...args) => {
|
|
4
|
+
const key = cacheKey(args);
|
|
5
|
+
const now = Date.now();
|
|
6
|
+
const hit = cache.get(key);
|
|
7
|
+
if (hit && (!hit.settled || hit.expires > now))
|
|
8
|
+
return hit.promise;
|
|
9
|
+
for (const [expiredKey, entry] of cache) {
|
|
10
|
+
if (entry.settled && entry.expires <= now)
|
|
11
|
+
cache.delete(expiredKey);
|
|
12
|
+
}
|
|
13
|
+
const entry = { promise: fn(...args), settled: false, expires: Infinity };
|
|
14
|
+
cache.set(key, entry);
|
|
15
|
+
entry.promise.then(() => {
|
|
16
|
+
entry.settled = true;
|
|
17
|
+
entry.expires = Date.now() + ttl;
|
|
18
|
+
}, () => {
|
|
19
|
+
if (cache.get(key) === entry)
|
|
20
|
+
cache.delete(key);
|
|
21
|
+
});
|
|
22
|
+
return entry.promise;
|
|
32
23
|
};
|
|
33
24
|
memoized.clear = () => cache.clear();
|
|
25
|
+
memoized.delete = (key) => cache.delete(key);
|
|
34
26
|
return memoized;
|
|
35
27
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const normalizePhoneNumber: (value?: string | null, defaultCountry?: string | null) => string | undefined;
|
|
2
|
+
export declare const phoneNumberToParts: (value?: string | null, defaultCountry?: string | null) => {
|
|
3
|
+
cc: string;
|
|
4
|
+
subscriber: string;
|
|
5
|
+
} | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parsePhoneNumber } from 'awesome-phonenumber';
|
|
2
|
+
export const normalizePhoneNumber = (value, defaultCountry) => {
|
|
3
|
+
if (!value)
|
|
4
|
+
return undefined;
|
|
5
|
+
const parsed = parsePhoneNumber(value, defaultCountry ? { regionCode: defaultCountry } : undefined);
|
|
6
|
+
if (!parsed.valid)
|
|
7
|
+
return undefined;
|
|
8
|
+
return parsed.number.e164;
|
|
9
|
+
};
|
|
10
|
+
export const phoneNumberToParts = (value, defaultCountry) => {
|
|
11
|
+
if (!value)
|
|
12
|
+
return undefined;
|
|
13
|
+
const parsed = parsePhoneNumber(value, defaultCountry ? { regionCode: defaultCountry } : undefined);
|
|
14
|
+
if (!parsed.valid)
|
|
15
|
+
return undefined;
|
|
16
|
+
return { cc: String(parsed.countryCode), subscriber: parsed.number.significant };
|
|
17
|
+
};
|
package/lib/utils-index.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-field
|
|
|
9
9
|
export { default as sha256 } from './sha256.ts';
|
|
10
10
|
export { default as sha1 } from './sha1.ts';
|
|
11
11
|
export { timingSafeEqual, timingSafeStringEqual } from './timing-safe-equal.ts';
|
|
12
|
-
export {
|
|
12
|
+
export { normalizePhoneNumber, phoneNumberToParts } from './phone-number.ts';
|
|
13
|
+
export { default as memoizeWithTTL } from './memoize-with-ttl.ts';
|
|
14
|
+
export { executeBulkOperation } from './executeBulkOperation.ts';
|
|
13
15
|
export declare const SortDirection: {
|
|
14
16
|
readonly ASC: "ASC";
|
|
15
17
|
readonly DESC: "DESC";
|
package/lib/utils-index.js
CHANGED
|
@@ -9,7 +9,9 @@ export { default as buildObfuscatedFieldsFilter } from "./build-obfuscated-field
|
|
|
9
9
|
export { default as sha256 } from "./sha256.js";
|
|
10
10
|
export { default as sha1 } from "./sha1.js";
|
|
11
11
|
export { timingSafeEqual, timingSafeStringEqual } from "./timing-safe-equal.js";
|
|
12
|
-
export {
|
|
12
|
+
export { normalizePhoneNumber, phoneNumberToParts } from "./phone-number.js";
|
|
13
|
+
export { default as memoizeWithTTL } from "./memoize-with-ttl.js";
|
|
14
|
+
export { executeBulkOperation } from "./executeBulkOperation.js";
|
|
13
15
|
export const SortDirection = {
|
|
14
16
|
ASC: 'ASC',
|
|
15
17
|
DESC: 'DESC',
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/utils",
|
|
3
3
|
"description": "Common utility functions and base classes for the Unchained Engine",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.11",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib"
|
|
7
|
+
],
|
|
5
8
|
"main": "lib/utils-index.js",
|
|
6
9
|
"types": "lib/utils-index.d.ts",
|
|
7
10
|
"type": "module",
|
|
@@ -29,11 +32,11 @@
|
|
|
29
32
|
},
|
|
30
33
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@unchainedshop/logger": "^5.0.0-alpha.
|
|
33
|
-
"
|
|
35
|
+
"@unchainedshop/logger": "^5.0.0-alpha.11",
|
|
36
|
+
"awesome-phonenumber": "^7.8.0"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"typescript": "^
|
|
39
|
+
"@types/node": "^26.2.0",
|
|
40
|
+
"typescript": "^6.0.3"
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export interface Entity<TId = string> {
|
|
2
|
-
_id: TId;
|
|
3
|
-
}
|
|
4
|
-
export interface IRepository<T extends Entity<TId>, TId = string> {
|
|
5
|
-
findById(id: TId): Promise<T | null>;
|
|
6
|
-
save(aggregate: T): Promise<void>;
|
|
7
|
-
delete(id: TId): Promise<boolean>;
|
|
8
|
-
exists(id: TId): Promise<boolean>;
|
|
9
|
-
}
|
|
10
|
-
export interface IQueryableRepository<T extends Entity<TId>, TId = string, TQuery = Partial<T>> extends IRepository<T, TId> {
|
|
11
|
-
findAll(query?: TQuery): Promise<T[]>;
|
|
12
|
-
findOne(query: TQuery): Promise<T | null>;
|
|
13
|
-
count(query?: TQuery): Promise<number>;
|
|
14
|
-
}
|
|
15
|
-
export interface IPaginatedRepository<T extends Entity<TId>, TId = string, TQuery = Partial<T>> extends IQueryableRepository<T, TId, TQuery> {
|
|
16
|
-
findPaginated(query: TQuery, options: PaginationOptions): Promise<PaginatedResult<T>>;
|
|
17
|
-
}
|
|
18
|
-
export interface PaginationOptions {
|
|
19
|
-
offset?: number;
|
|
20
|
-
limit?: number;
|
|
21
|
-
sortBy?: string;
|
|
22
|
-
sortDirection?: 'asc' | 'desc';
|
|
23
|
-
}
|
|
24
|
-
export interface PaginatedResult<T> {
|
|
25
|
-
items: T[];
|
|
26
|
-
totalCount: number;
|
|
27
|
-
hasMore: boolean;
|
|
28
|
-
offset: number;
|
|
29
|
-
limit: number;
|
|
30
|
-
}
|
|
31
|
-
export interface IReadOnlyRepository<T extends Entity<TId>, TId = string, TQuery = Partial<T>> {
|
|
32
|
-
findById(id: TId): Promise<T | null>;
|
|
33
|
-
findAll(query?: TQuery): Promise<T[]>;
|
|
34
|
-
findOne(query: TQuery): Promise<T | null>;
|
|
35
|
-
count(query?: TQuery): Promise<number>;
|
|
36
|
-
exists(id: TId): Promise<boolean>;
|
|
37
|
-
}
|
|
38
|
-
export interface IUnitOfWork {
|
|
39
|
-
begin(): Promise<void>;
|
|
40
|
-
commit(): Promise<void>;
|
|
41
|
-
rollback(): Promise<void>;
|
|
42
|
-
executeInTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Entity, IRepository, IQueryableRepository, IPaginatedRepository, IReadOnlyRepository, IUnitOfWork, PaginationOptions, PaginatedResult, } from './Repository.ts';
|
package/lib/repository/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type Specification<T> = (candidate: T) => boolean;
|
|
2
|
-
export declare function and<T>(...specs: Specification<T>[]): Specification<T>;
|
|
3
|
-
export declare function or<T>(...specs: Specification<T>[]): Specification<T>;
|
|
4
|
-
export declare function not<T>(spec: Specification<T>): Specification<T>;
|
|
5
|
-
export declare function alwaysTrue<T>(): Specification<T>;
|
|
6
|
-
export declare function alwaysFalse<T>(): Specification<T>;
|
|
7
|
-
export declare function propEquals<T, K extends keyof T = keyof T>(propertyName: K, expectedValue: T[K]): Specification<T>;
|
|
8
|
-
export declare function propIn<T, K extends keyof T = keyof T>(propertyName: K, values: T[K][]): Specification<T>;
|
|
9
|
-
export declare function dateRange<T>(propertyName: keyof T, range: {
|
|
10
|
-
start?: Date;
|
|
11
|
-
end?: Date;
|
|
12
|
-
}): Specification<T>;
|
|
13
|
-
export declare function numericRange<T>(propertyName: keyof T, range: {
|
|
14
|
-
min?: number;
|
|
15
|
-
max?: number;
|
|
16
|
-
}): Specification<T>;
|
|
17
|
-
export declare function propTruthy<T>(propertyName: keyof T): Specification<T>;
|
|
18
|
-
export declare function propFalsy<T>(propertyName: keyof T): Specification<T>;
|
|
19
|
-
export declare function propNullish<T>(propertyName: keyof T): Specification<T>;
|
|
20
|
-
export declare function propNotNullish<T>(propertyName: keyof T): Specification<T>;
|
|
21
|
-
export declare function propContains<T, V>(propertyName: keyof T, value: V): Specification<T>;
|
|
22
|
-
export declare function spec<T>(predicate: (candidate: T) => boolean): Specification<T>;
|
|
23
|
-
export declare function filterBy<T>(items: T[], specification: Specification<T>): T[];
|
|
24
|
-
export declare function findBy<T>(items: T[], specification: Specification<T>): T | undefined;
|
|
25
|
-
export declare function countBy<T>(items: T[], specification: Specification<T>): number;
|
|
26
|
-
export declare function someBy<T>(items: T[], specification: Specification<T>): boolean;
|
|
27
|
-
export declare function everyBy<T>(items: T[], specification: Specification<T>): boolean;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
export function and(...specs) {
|
|
2
|
-
return (candidate) => specs.every((spec) => spec(candidate));
|
|
3
|
-
}
|
|
4
|
-
export function or(...specs) {
|
|
5
|
-
return (candidate) => specs.some((spec) => spec(candidate));
|
|
6
|
-
}
|
|
7
|
-
export function not(spec) {
|
|
8
|
-
return (candidate) => !spec(candidate);
|
|
9
|
-
}
|
|
10
|
-
export function alwaysTrue() {
|
|
11
|
-
return () => true;
|
|
12
|
-
}
|
|
13
|
-
export function alwaysFalse() {
|
|
14
|
-
return () => false;
|
|
15
|
-
}
|
|
16
|
-
export function propEquals(propertyName, expectedValue) {
|
|
17
|
-
return (candidate) => candidate[propertyName] === expectedValue;
|
|
18
|
-
}
|
|
19
|
-
export function propIn(propertyName, values) {
|
|
20
|
-
const valueSet = new Set(values);
|
|
21
|
-
return (candidate) => valueSet.has(candidate[propertyName]);
|
|
22
|
-
}
|
|
23
|
-
export function dateRange(propertyName, range) {
|
|
24
|
-
return (candidate) => {
|
|
25
|
-
const value = candidate[propertyName];
|
|
26
|
-
if (!(value instanceof Date)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
if (range.start && value < range.start) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
if (range.end && value > range.end) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export function numericRange(propertyName, range) {
|
|
39
|
-
return (candidate) => {
|
|
40
|
-
const value = candidate[propertyName];
|
|
41
|
-
if (typeof value !== 'number') {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (range.min !== undefined && value < range.min) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (range.max !== undefined && value > range.max) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export function propTruthy(propertyName) {
|
|
54
|
-
return (candidate) => Boolean(candidate[propertyName]);
|
|
55
|
-
}
|
|
56
|
-
export function propFalsy(propertyName) {
|
|
57
|
-
return (candidate) => !candidate[propertyName];
|
|
58
|
-
}
|
|
59
|
-
export function propNullish(propertyName) {
|
|
60
|
-
return (candidate) => candidate[propertyName] == null;
|
|
61
|
-
}
|
|
62
|
-
export function propNotNullish(propertyName) {
|
|
63
|
-
return (candidate) => candidate[propertyName] != null;
|
|
64
|
-
}
|
|
65
|
-
export function propContains(propertyName, value) {
|
|
66
|
-
return (candidate) => {
|
|
67
|
-
const arr = candidate[propertyName];
|
|
68
|
-
return Array.isArray(arr) && arr.includes(value);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export function spec(predicate) {
|
|
72
|
-
return predicate;
|
|
73
|
-
}
|
|
74
|
-
export function filterBy(items, specification) {
|
|
75
|
-
return items.filter(specification);
|
|
76
|
-
}
|
|
77
|
-
export function findBy(items, specification) {
|
|
78
|
-
return items.find(specification);
|
|
79
|
-
}
|
|
80
|
-
export function countBy(items, specification) {
|
|
81
|
-
return items.filter(specification).length;
|
|
82
|
-
}
|
|
83
|
-
export function someBy(items, specification) {
|
|
84
|
-
return items.some(specification);
|
|
85
|
-
}
|
|
86
|
-
export function everyBy(items, specification) {
|
|
87
|
-
return items.every(specification);
|
|
88
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { type Specification, and, or, not, alwaysTrue, alwaysFalse, propEquals, propIn, dateRange, numericRange, propTruthy, propFalsy, propNullish, propNotNullish, propContains, spec, filterBy, findBy, countBy, someBy, everyBy, } from './Specification.ts';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { and, or, not, alwaysTrue, alwaysFalse, propEquals, propIn, dateRange, numericRange, propTruthy, propFalsy, propNullish, propNotNullish, propContains, spec, filterBy, findBy, countBy, someBy, everyBy, } from "./Specification.js";
|