@esposter/shared 2.34.1 → 2.34.2
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/dist/index.d.ts +61 -42
- package/dist/index.js +7 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -457,16 +457,16 @@ An if-else-like type that resolves depending on whether the given type is `any`
|
|
|
457
457
|
|
|
458
458
|
@example
|
|
459
459
|
```
|
|
460
|
-
// When `T` is
|
|
461
|
-
type A = IfNotAnyOrNever<string, 'VALID'
|
|
460
|
+
// When `T` is neither `any` nor `never` (like `string`) => Returns `IfNot` branch
|
|
461
|
+
type A = IfNotAnyOrNever<string, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
462
462
|
//=> 'VALID'
|
|
463
463
|
|
|
464
464
|
// When `T` is `any` => Returns `IfAny` branch
|
|
465
|
-
type B = IfNotAnyOrNever<any, 'VALID'
|
|
465
|
+
type B = IfNotAnyOrNever<any, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
466
466
|
//=> 'IS_ANY'
|
|
467
467
|
|
|
468
468
|
// When `T` is `never` => Returns `IfNever` branch
|
|
469
|
-
type C = IfNotAnyOrNever<never, 'VALID'
|
|
469
|
+
type C = IfNotAnyOrNever<never, {ifNot: 'VALID'; ifAny: 'IS_ANY'; ifNever: 'IS_NEVER'}>;
|
|
470
470
|
//=> 'IS_NEVER'
|
|
471
471
|
```
|
|
472
472
|
|
|
@@ -479,7 +479,7 @@ import type {StringRepeat} from 'type-fest';
|
|
|
479
479
|
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
480
480
|
|
|
481
481
|
// The following implementation is not tail recursive
|
|
482
|
-
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
482
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, {ifNot: S extends ` ${infer R}` ? TrimLeft<R> : S}>;
|
|
483
483
|
|
|
484
484
|
// Hence, instantiations with long strings will fail
|
|
485
485
|
// @ts-expect-error
|
|
@@ -488,7 +488,7 @@ type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
|
488
488
|
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
489
489
|
|
|
490
490
|
// To fix this, move the recursion into a helper type
|
|
491
|
-
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S
|
|
491
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, {ifNot: _TrimLeftOptimised<S>}>;
|
|
492
492
|
|
|
493
493
|
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
494
494
|
|
|
@@ -496,7 +496,11 @@ type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
|
496
496
|
//=> ''
|
|
497
497
|
```
|
|
498
498
|
*/
|
|
499
|
-
type IfNotAnyOrNever<T,
|
|
499
|
+
type IfNotAnyOrNever<T, Cases extends {
|
|
500
|
+
ifNot: unknown;
|
|
501
|
+
ifAny?: unknown;
|
|
502
|
+
ifNever?: unknown;
|
|
503
|
+
}> = IsAny<T> extends true ? 'ifAny' extends keyof Cases ? Cases['ifAny'] : any : IsNever<T> extends true ? 'ifNever' extends keyof Cases ? Cases['ifNever'] : never : Cases['ifNot'];
|
|
500
504
|
/**
|
|
501
505
|
Indicates the value of `exactOptionalPropertyTypes` compiler option.
|
|
502
506
|
*/
|
|
@@ -532,7 +536,9 @@ type B = CollapseRestElement<[string?, string?, ...number[]]>;
|
|
|
532
536
|
//=> [string | undefined, string | undefined, number]
|
|
533
537
|
```
|
|
534
538
|
*/
|
|
535
|
-
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray,
|
|
539
|
+
type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, {
|
|
540
|
+
ifNot: _CollapseRestElement<TArray>;
|
|
541
|
+
}>;
|
|
536
542
|
type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
|
|
537
543
|
? keyof TArray & `${number}` extends never // Enters this branch, if `TArray` is empty (e.g., []),
|
|
538
544
|
// or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
@@ -777,7 +783,11 @@ type L2 = Length<`${number}`>;
|
|
|
777
783
|
@category Type Guard
|
|
778
784
|
@category Utilities
|
|
779
785
|
*/
|
|
780
|
-
type IsStringLiteral<S> = IfNotAnyOrNever<S,
|
|
786
|
+
type IsStringLiteral<S> = IfNotAnyOrNever<S, {
|
|
787
|
+
ifNot: _IsStringLiteral<CollapseLiterals<S extends TagContainer<any> ? UnwrapTagged<S> : S>>;
|
|
788
|
+
ifAny: false;
|
|
789
|
+
ifNever: false;
|
|
790
|
+
}>;
|
|
781
791
|
type _IsStringLiteral<S> = // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
|
782
792
|
// and since `{}` extends index signatures, the result becomes `false`.
|
|
783
793
|
S extends string ? {} extends Record<S, never> ? false : true : false;
|
|
@@ -805,34 +815,6 @@ type Example = Trim<' foo '>;
|
|
|
805
815
|
*/
|
|
806
816
|
type Trim<V extends string> = TrimLeft<TrimRight<V>>;
|
|
807
817
|
/**
|
|
808
|
-
Returns a boolean for whether the given string `S` starts with the given string `SearchString`.
|
|
809
|
-
|
|
810
|
-
@example
|
|
811
|
-
```
|
|
812
|
-
type A = StartsWith<'abcde', 'abc'>;
|
|
813
|
-
//=> true
|
|
814
|
-
|
|
815
|
-
type B = StartsWith<'abcde', 'bc'>;
|
|
816
|
-
//=> false
|
|
817
|
-
|
|
818
|
-
type C = StartsWith<string, 'bc'>;
|
|
819
|
-
//=> never
|
|
820
|
-
|
|
821
|
-
type D = StartsWith<'abcde', string>;
|
|
822
|
-
//=> never
|
|
823
|
-
```
|
|
824
|
-
|
|
825
|
-
@category String
|
|
826
|
-
@category Template literal
|
|
827
|
-
*/
|
|
828
|
-
type StartsWith<S extends string, SearchString extends string> = string extends S | SearchString ? never : S extends `${SearchString}${infer T}` ? true : false;
|
|
829
|
-
/**
|
|
830
|
-
Returns a boolean for whether the string is numeric.
|
|
831
|
-
|
|
832
|
-
This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987).
|
|
833
|
-
*/
|
|
834
|
-
type IsNumeric<T extends string> = T extends `${number}` ? Trim<T> extends T ? true : false : false;
|
|
835
|
-
/**
|
|
836
818
|
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
837
819
|
|
|
838
820
|
@example
|
|
@@ -1289,8 +1271,12 @@ type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
|
|
|
1289
1271
|
@category Array
|
|
1290
1272
|
*/
|
|
1291
1273
|
type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
|
|
1292
|
-
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray,
|
|
1293
|
-
|
|
1274
|
+
type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, {
|
|
1275
|
+
ifNot: TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
|
|
1276
|
+
? true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false;
|
|
1277
|
+
ifAny: false;
|
|
1278
|
+
ifNever: false;
|
|
1279
|
+
}>;
|
|
1294
1280
|
/**
|
|
1295
1281
|
Returns a boolean for whether any of the given elements is `true`.
|
|
1296
1282
|
|
|
@@ -1439,6 +1425,34 @@ type G = Or<never, never>;
|
|
|
1439
1425
|
*/
|
|
1440
1426
|
type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
|
|
1441
1427
|
/**
|
|
1428
|
+
Returns a boolean for whether the given string `S` starts with the given string `SearchString`.
|
|
1429
|
+
|
|
1430
|
+
@example
|
|
1431
|
+
```
|
|
1432
|
+
type A = StartsWith<'abcde', 'abc'>;
|
|
1433
|
+
//=> true
|
|
1434
|
+
|
|
1435
|
+
type B = StartsWith<'abcde', 'bc'>;
|
|
1436
|
+
//=> false
|
|
1437
|
+
|
|
1438
|
+
type C = StartsWith<string, 'bc'>;
|
|
1439
|
+
//=> never
|
|
1440
|
+
|
|
1441
|
+
type D = StartsWith<'abcde', string>;
|
|
1442
|
+
//=> never
|
|
1443
|
+
```
|
|
1444
|
+
|
|
1445
|
+
@category String
|
|
1446
|
+
@category Template literal
|
|
1447
|
+
*/
|
|
1448
|
+
type StartsWith<S extends string, SearchString extends string> = string extends S | SearchString ? never : S extends `${SearchString}${infer T}` ? true : false;
|
|
1449
|
+
/**
|
|
1450
|
+
Returns a boolean for whether the string is numeric.
|
|
1451
|
+
|
|
1452
|
+
This type is a workaround for [Microsoft/TypeScript#46109](https://github.com/microsoft/TypeScript/issues/46109#issuecomment-930307987).
|
|
1453
|
+
*/
|
|
1454
|
+
type IsNumeric<T extends string> = T extends `${number}` ? Trim<T> extends T ? true : false : false;
|
|
1455
|
+
/**
|
|
1442
1456
|
@see {@link AllExtend}
|
|
1443
1457
|
*/
|
|
1444
1458
|
type AllExtendOptions = {
|
|
@@ -1520,8 +1534,12 @@ type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
|
1520
1534
|
@category Array
|
|
1521
1535
|
*/
|
|
1522
1536
|
type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
1523
|
-
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray,
|
|
1524
|
-
|
|
1537
|
+
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, {
|
|
1538
|
+
ifNot: TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
1539
|
+
? _AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true;
|
|
1540
|
+
ifAny: false;
|
|
1541
|
+
ifNever: false;
|
|
1542
|
+
}>;
|
|
1525
1543
|
/**
|
|
1526
1544
|
Filter out keys from an object.
|
|
1527
1545
|
|
|
@@ -2496,6 +2514,7 @@ declare const takeOne: TakeOne;
|
|
|
2496
2514
|
declare const getIsServer: () => boolean;
|
|
2497
2515
|
declare const noop: () => void;
|
|
2498
2516
|
declare const ID_SEPARATOR = "|";
|
|
2517
|
+
declare const getOrCreate: <TKey, TValue>(map: Map<TKey, TValue>, key: TKey, create: () => TValue) => TValue;
|
|
2499
2518
|
declare const checkIsPlainObject: (data: unknown) => data is object;
|
|
2500
2519
|
declare const getPropertyNames: <T>() => PropertyNames<T>;
|
|
2501
2520
|
declare const jsonDateParse: <T = any>(text: string) => T;
|
|
@@ -2529,4 +2548,4 @@ declare const createUniqueArraySchema: CreateUniqueArraySchema;
|
|
|
2529
2548
|
declare const NIL = "00000000-0000-0000-0000-000000000000";
|
|
2530
2549
|
declare const UUIDV4_REGEX: RegExp;
|
|
2531
2550
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
2532
|
-
export { AllSpecialValues, BuildTuple, ClassifiedMentions, CreateUniqueArraySchema, DeepOmit, DeepOptionalUndefined, ExcludeFunctionProperties, ForbiddenError, FunctionProperties, GetArrayProps, GetObjectProps, GetPaths, GetPrimitiveProps, GetProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KnownKeys, MAX_READ_LIMIT, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_ITEM_TYPE_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MentionType, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UniqueArraySchemaKey, WithMetadata, applyItemMetadataMixin, capitalize, checkIsPlainObject, classifyMentions, createItemEntityTypeSchema, createNormalizedStringSchema, createUniqueArraySchema, css, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, getResult, getResultAsync, hrtime, html, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, sanitizeHtml, sanitizeMessageHtml, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4, withFinalizer, withFinalizerAsync };
|
|
2551
|
+
export { AllSpecialValues, BuildTuple, ClassifiedMentions, CreateUniqueArraySchema, DeepOmit, DeepOptionalUndefined, ExcludeFunctionProperties, ForbiddenError, FunctionProperties, GetArrayProps, GetObjectProps, GetPaths, GetPrimitiveProps, GetProperties, ID_SEPARATOR, InvalidOperationError, ItemEntityType, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KnownKeys, MAX_READ_LIMIT, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_ITEM_TYPE_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MapValue, MentionType, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, PropertyNames, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, SkipFirst, TakeFirst, TakeOne, ToData, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UniqueArraySchemaKey, WithMetadata, applyItemMetadataMixin, capitalize, checkIsPlainObject, classifyMentions, createItemEntityTypeSchema, createNormalizedStringSchema, createUniqueArraySchema, css, exhaustiveGuard, getIsServer, getMentions, getOrCreate, getPropertyNames, getRawData, getResult, getResultAsync, hrtime, html, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, sanitizeHtml, sanitizeMessageHtml, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4, withFinalizer, withFinalizerAsync };
|
package/dist/index.js
CHANGED
|
@@ -16132,6 +16132,12 @@ const takeOne = (values, index = 0) => {
|
|
|
16132
16132
|
};
|
|
16133
16133
|
const getIsServer = () => typeof window === "undefined";
|
|
16134
16134
|
const ID_SEPARATOR = "|";
|
|
16135
|
+
const getOrCreate = (map, key, create) => {
|
|
16136
|
+
if (map.has(key)) return map.get(key);
|
|
16137
|
+
const value = create();
|
|
16138
|
+
map.set(key, value);
|
|
16139
|
+
return value;
|
|
16140
|
+
};
|
|
16135
16141
|
const checkIsPlainObject = (data) => {
|
|
16136
16142
|
if (typeof data !== "object" || data === null) return false;
|
|
16137
16143
|
const prototype = Object.getPrototypeOf(data);
|
|
@@ -16199,4 +16205,4 @@ const createUniqueArraySchema = (schema, key) => schema.array().refine((array) =
|
|
|
16199
16205
|
const NIL = "00000000-0000-0000-0000-000000000000";
|
|
16200
16206
|
const UUIDV4_REGEX = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/iu;
|
|
16201
16207
|
const uuidValidateV4 = (uuid) => UUIDV4_REGEX.test(uuid);
|
|
16202
|
-
export { AllSpecialValues, ForbiddenError, ID_SEPARATOR, InvalidOperationError, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, MAX_READ_LIMIT, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_ITEM_TYPE_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MentionType, NIL, NotFoundError, NotInitializedError, Operation, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, UUIDV4_REGEX, applyItemMetadataMixin, capitalize, checkIsPlainObject, classifyMentions, createItemEntityTypeSchema, createNormalizedStringSchema, createUniqueArraySchema, css, exhaustiveGuard, getIsServer, getMentions, getPropertyNames, getRawData, getResult, getResultAsync, hrtime, html, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, sanitizeHtml, sanitizeMessageHtml, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4, withFinalizer, withFinalizerAsync };
|
|
16208
|
+
export { AllSpecialValues, ForbiddenError, ID_SEPARATOR, InvalidOperationError, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, MAX_READ_LIMIT, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_ITEM_TYPE_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MentionType, NIL, NotFoundError, NotInitializedError, Operation, RoutePath, SITE_NAME, SURVEY_DISPLAY_NAME, Serializable, UUIDV4_REGEX, applyItemMetadataMixin, capitalize, checkIsPlainObject, classifyMentions, createItemEntityTypeSchema, createNormalizedStringSchema, createUniqueArraySchema, css, exhaustiveGuard, getIsServer, getMentions, getOrCreate, getPropertyNames, getRawData, getResult, getResultAsync, hrtime, html, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, sanitizeHtml, sanitizeMessageHtml, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, uuidValidateV4, withFinalizer, withFinalizerAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esposter/shared",
|
|
3
|
-
"version": "2.34.
|
|
3
|
+
"version": "2.34.2",
|
|
4
4
|
"description": "A library that contains shared typescript code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@azure/data-tables": "^13.3.2",
|
|
51
|
-
"@esposter/configuration": "2.34.
|
|
51
|
+
"@esposter/configuration": "2.34.2",
|
|
52
52
|
"@types/node": "^26.1.0",
|
|
53
53
|
"@types/sanitize-html": "^2.16.1",
|
|
54
54
|
"ctix": "^2.8.1",
|
|
55
55
|
"rolldown": "^1.1.4",
|
|
56
|
-
"type-fest": "^5.
|
|
56
|
+
"type-fest": "^5.8.0",
|
|
57
57
|
"vitest": "^4.1.9",
|
|
58
58
|
"vue": "^3.5.39"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"zod": "^4.4.3"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "70032635c47bdf1e55414c7d84c955350f991055"
|
|
64
64
|
}
|