@duplojs/utils 0.1.0 → 0.2.0

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.
@@ -1,4 +1,5 @@
1
- export interface ExpectType<GenericOne extends unknown, GenericTwo extends unknown, GenericRule extends ((<V>() => V extends GenericOne ? 1 : 2) extends (<V>() => V extends GenericTwo ? 1 : 2) ? "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" : never)> {
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) {
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 "./isAny";
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) {
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>>(value: GenericValue): <GenericInterpolationMapperValue extends string, GenericInterpolationValues extends Record<GenericInterpolationId, GenericInterpolationMapperValue>>(...[interpolationValues]: IsEqual<GenericInterpolationId, never> extends true ? [] : [interpolationValues: GenericInterpolationValues]) => ReplaceInterpolationIdByValues<GenericValue, GenericInterpolationValues>;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "mathcovax",
5
5
  "license": "MIT",
6
6
  "type": "module",
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;