@duplojs/utils 0.1.0 → 0.2.1
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/expectType.d.ts +2 -1
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +7 -1
- package/dist/interpolation.d.ts +5 -0
- package/dist/isEqual.d.ts +1 -0
- package/package.json +1 -1
- package/dist/isAny.d.ts +0 -1
package/dist/expectType.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type IsEqual } from "./isEqual";
|
|
2
|
+
export interface ExpectType<GenericOne extends unknown, GenericTwo extends unknown, GenericRule extends (IsEqual<GenericOne, GenericTwo> extends true ? "strict" : (GenericOne extends GenericTwo ? true : 1) extends (GenericTwo extends GenericOne ? true : 2) ? "flexible" : GenericOne extends GenericTwo ? "one-extends-two" : GenericTwo extends GenericOne ? "two-extends-one" : "none")> {
|
|
2
3
|
one: GenericOne;
|
|
3
4
|
two: GenericTwo;
|
|
4
5
|
rule: GenericRule;
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,12 @@ function hasKey(obj, key) {
|
|
|
39
39
|
return key in obj;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function createInterpolation(value, _strict) {
|
|
43
|
+
return (interpolationValues) => (interpolationValues
|
|
44
|
+
? value.replace(/\{([^}]*)\}/g, (match, interpolationId) => interpolationValues[interpolationId])
|
|
45
|
+
: value);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
function simpleClone(unknownValue) {
|
|
43
49
|
if (!unknownValue) {
|
|
44
50
|
return unknownValue;
|
|
@@ -120,6 +126,7 @@ function unPartial(partialObject, keys) {
|
|
|
120
126
|
exports.InvalidBytesInStringError = InvalidBytesInStringError;
|
|
121
127
|
exports.UnPartialError = UnPartialError;
|
|
122
128
|
exports.clone = clone;
|
|
129
|
+
exports.createInterpolation = createInterpolation;
|
|
123
130
|
exports.entryUseMapper = entryUseMapper;
|
|
124
131
|
exports.escapeRegExp = escapeRegExp;
|
|
125
132
|
exports.getTypedEntries = getTypedEntries;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export * from "./getTypedEntries";
|
|
|
9
9
|
export * from "./getTypedKeys";
|
|
10
10
|
export * from "./hasKey";
|
|
11
11
|
export * from "./incremente";
|
|
12
|
-
export * from "./
|
|
12
|
+
export * from "./interpolation";
|
|
13
|
+
export * from "./isEqual";
|
|
13
14
|
export * from "./overrideInterface";
|
|
14
15
|
export * from "./partialKeys";
|
|
15
16
|
export * from "./requiredKeys";
|
package/dist/index.mjs
CHANGED
|
@@ -37,6 +37,12 @@ function hasKey(obj, key) {
|
|
|
37
37
|
return key in obj;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function createInterpolation(value, _strict) {
|
|
41
|
+
return (interpolationValues) => (interpolationValues
|
|
42
|
+
? value.replace(/\{([^}]*)\}/g, (match, interpolationId) => interpolationValues[interpolationId])
|
|
43
|
+
: value);
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
function simpleClone(unknownValue) {
|
|
41
47
|
if (!unknownValue) {
|
|
42
48
|
return unknownValue;
|
|
@@ -115,4 +121,4 @@ function unPartial(partialObject, keys) {
|
|
|
115
121
|
return partialObject;
|
|
116
122
|
}
|
|
117
123
|
|
|
118
|
-
export { InvalidBytesInStringError, UnPartialError, clone, entryUseMapper, escapeRegExp, getTypedEntries, getTypedKeys, hasKey, simpleClone, sleep, stringToBytes, unPartial };
|
|
124
|
+
export { InvalidBytesInStringError, UnPartialError, clone, createInterpolation, entryUseMapper, escapeRegExp, getTypedEntries, getTypedKeys, hasKey, simpleClone, sleep, stringToBytes, unPartial };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type IsEqual } from "./isEqual";
|
|
2
|
+
export type ExtractInterpolationId<GenericValue extends string> = GenericValue extends `${string}{${infer InferedInterpolationId}}${infer InferedEndValue}` ? InferedInterpolationId | ExtractInterpolationId<InferedEndValue> : never;
|
|
3
|
+
export type ReplaceInterpolationIdByValues<GenericValue extends string, GenericInterpolationValues extends Record<string, string>> = GenericValue extends `${infer InferedStartValue}{${infer InferedInterpolationId}}${infer InferedEndValue}` ? InferedInterpolationId extends keyof GenericInterpolationValues ? `${InferedStartValue}${GenericInterpolationValues[InferedInterpolationId]}${ReplaceInterpolationIdByValues<InferedEndValue, GenericInterpolationValues>}` : `${InferedStartValue}${string}${ReplaceInterpolationIdByValues<InferedEndValue, GenericInterpolationValues>}` : GenericValue;
|
|
4
|
+
export type CreateInterpolationContract<GenericInterpolationFunction extends ((value: Record<string, string>) => string)> = ReplaceInterpolationIdByValues<ReturnType<GenericInterpolationFunction>, {}>;
|
|
5
|
+
export declare function createInterpolation<GenericValue extends string, GenericInterpolationId extends ExtractInterpolationId<GenericValue>, GenericStrict extends boolean>(value: GenericValue, strict?: GenericStrict): <GenericInterpolationMapperValue extends string, GenericInterpolationValues extends Record<GenericInterpolationId, GenericInterpolationMapperValue>>(...[interpolationValues]: IsEqual<GenericInterpolationId, never> extends true ? [] : [interpolationValues: GenericInterpolationValues]) => IsEqual<GenericStrict, true> extends true ? ReplaceInterpolationIdByValues<GenericValue, GenericInterpolationValues> : string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type IsEqual<GenericOne extends unknown, GenericTwo extends unknown> = (<V>() => V extends GenericOne ? 1 : 2) extends (<V>() => V extends GenericTwo ? 1 : 2) ? true : false;
|
package/package.json
CHANGED
package/dist/isAny.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type IsAny<T extends any> = (any extends T ? true : false) extends true ? true : false;
|