complete-common 1.4.0 → 2.1.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.
- package/dist/functions/array.d.cts +5 -5
- package/dist/functions/array.d.mts +5 -5
- package/dist/functions/array.d.ts +5 -5
- package/dist/functions/array.d.ts.map +1 -1
- package/dist/functions/assert.d.cts +1 -1
- package/dist/functions/assert.d.mts +1 -1
- package/dist/functions/assert.d.ts +1 -1
- package/dist/functions/assert.d.ts.map +1 -1
- package/dist/functions/enums.d.cts +1 -1
- package/dist/functions/enums.d.mts +1 -1
- package/dist/functions/enums.d.ts +1 -1
- package/dist/functions/enums.d.ts.map +1 -1
- package/dist/functions/map.d.cts +6 -2
- package/dist/functions/map.d.mts +6 -2
- package/dist/functions/map.d.ts +6 -2
- package/dist/functions/map.d.ts.map +1 -1
- package/dist/functions/object.d.cts +3 -30
- package/dist/functions/object.d.mts +3 -30
- package/dist/functions/object.d.ts +3 -30
- package/dist/functions/object.d.ts.map +1 -1
- package/dist/functions/set.d.cts +6 -26
- package/dist/functions/set.d.mts +6 -26
- package/dist/functions/set.d.ts +6 -26
- package/dist/functions/set.d.ts.map +1 -1
- package/dist/functions/sort.d.cts +1 -1
- package/dist/functions/sort.d.mts +1 -1
- package/dist/functions/sort.d.ts +1 -1
- package/dist/functions/sort.d.ts.map +1 -1
- package/dist/functions/string.d.cts +3 -1
- package/dist/functions/string.d.mts +3 -1
- package/dist/functions/string.d.ts +3 -1
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/index.cjs +7 -18
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7 -15
- package/dist/types/TranspiledEnum.d.cts +3 -0
- package/dist/types/TranspiledEnum.d.mts +3 -0
- package/dist/types/TranspiledEnum.d.ts +3 -0
- package/dist/types/TranspiledEnum.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/functions/array.ts +5 -10
- package/src/functions/assert.ts +1 -1
- package/src/functions/enums.ts +1 -1
- package/src/functions/map.ts +8 -5
- package/src/functions/object.ts +3 -44
- package/src/functions/set.ts +8 -41
- package/src/functions/sort.ts +3 -2
- package/src/functions/string.ts +7 -1
- package/src/index.ts +1 -0
- package/src/types/TranspiledEnum.ts +2 -0
|
@@ -41,8 +41,10 @@ export declare function isKebabCase(string: string): boolean;
|
|
|
41
41
|
* @see https://semver.org/
|
|
42
42
|
*/
|
|
43
43
|
export declare function isSemanticVersion(versionString: string): boolean;
|
|
44
|
-
/** Helper function to convert a string from kebab-case to
|
|
44
|
+
/** Helper function to convert a string from kebab-case to camelCase. */
|
|
45
45
|
export declare function kebabCaseToCamelCase(string: string): string;
|
|
46
|
+
/** Helper function to convert a string from kebab-case to PascalCase. */
|
|
47
|
+
export declare function kebabCaseToPascalCase(string: string): string;
|
|
46
48
|
/**
|
|
47
49
|
* Helper function to normalize a string. Specifically, this performs the following steps:
|
|
48
50
|
*
|
|
@@ -41,8 +41,10 @@ export declare function isKebabCase(string: string): boolean;
|
|
|
41
41
|
* @see https://semver.org/
|
|
42
42
|
*/
|
|
43
43
|
export declare function isSemanticVersion(versionString: string): boolean;
|
|
44
|
-
/** Helper function to convert a string from kebab-case to
|
|
44
|
+
/** Helper function to convert a string from kebab-case to camelCase. */
|
|
45
45
|
export declare function kebabCaseToCamelCase(string: string): string;
|
|
46
|
+
/** Helper function to convert a string from kebab-case to PascalCase. */
|
|
47
|
+
export declare function kebabCaseToPascalCase(string: string): string;
|
|
46
48
|
/**
|
|
47
49
|
* Helper function to normalize a string. Specifically, this performs the following steps:
|
|
48
50
|
*
|
|
@@ -41,8 +41,10 @@ export declare function isKebabCase(string: string): boolean;
|
|
|
41
41
|
* @see https://semver.org/
|
|
42
42
|
*/
|
|
43
43
|
export declare function isSemanticVersion(versionString: string): boolean;
|
|
44
|
-
/** Helper function to convert a string from kebab-case to
|
|
44
|
+
/** Helper function to convert a string from kebab-case to camelCase. */
|
|
45
45
|
export declare function kebabCaseToCamelCase(string: string): string;
|
|
46
|
+
/** Helper function to convert a string from kebab-case to PascalCase. */
|
|
47
|
+
export declare function kebabCaseToPascalCase(string: string): string;
|
|
46
48
|
/**
|
|
47
49
|
* Helper function to normalize a string. Specifically, this performs the following steps:
|
|
48
50
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBlE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED,
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH,kEAAkE;AAClE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBlE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED,wEAAwE;AACxE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED,yEAAyE;AACzE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBtD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GACtD;IACE,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IAErB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB,GACD,SAAS,CAwBZ;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAuBR;AAED,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIzE;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,UAAQ,GACd,MAAM,CAWR;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMxE"}
|
package/dist/index.cjs
CHANGED
|
@@ -192,8 +192,8 @@ function mapFilter(map, predicate) {
|
|
|
192
192
|
return array;
|
|
193
193
|
}
|
|
194
194
|
function mapFind(map, predicate) {
|
|
195
|
-
for (const value of map
|
|
196
|
-
const match = predicate(value);
|
|
195
|
+
for (const [key, value] of map) {
|
|
196
|
+
const match = predicate(value, key, map);
|
|
197
197
|
if (match) {
|
|
198
198
|
return value;
|
|
199
199
|
}
|
|
@@ -223,9 +223,6 @@ function objectToMap(object) {
|
|
|
223
223
|
}
|
|
224
224
|
return map;
|
|
225
225
|
}
|
|
226
|
-
function objectToReadonlyMap(object) {
|
|
227
|
-
return objectToMap(object);
|
|
228
|
-
}
|
|
229
226
|
function objectToReverseMap(object) {
|
|
230
227
|
const map = /* @__PURE__ */ new Map();
|
|
231
228
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -233,9 +230,6 @@ function objectToReverseMap(object) {
|
|
|
233
230
|
}
|
|
234
231
|
return map;
|
|
235
232
|
}
|
|
236
|
-
function objectToReverseReadonlyMap(object) {
|
|
237
|
-
return objectToReverseMap(object);
|
|
238
|
-
}
|
|
239
233
|
|
|
240
234
|
function addSetsToSet(mainSet, ...setsToAdd) {
|
|
241
235
|
for (const set of setsToAdd) {
|
|
@@ -260,9 +254,6 @@ function copySet(oldSet) {
|
|
|
260
254
|
}
|
|
261
255
|
return newSet;
|
|
262
256
|
}
|
|
263
|
-
function objectKeysToReadonlySet(object) {
|
|
264
|
-
return objectKeysToSet(object);
|
|
265
|
-
}
|
|
266
257
|
function objectKeysToSet(object) {
|
|
267
258
|
const set = /* @__PURE__ */ new Set();
|
|
268
259
|
for (const key of Object.keys(object)) {
|
|
@@ -270,9 +261,6 @@ function objectKeysToSet(object) {
|
|
|
270
261
|
}
|
|
271
262
|
return set;
|
|
272
263
|
}
|
|
273
|
-
function objectValuesToReadonlySet(object) {
|
|
274
|
-
return objectValuesToSet(object);
|
|
275
|
-
}
|
|
276
264
|
function objectValuesToSet(object) {
|
|
277
265
|
const set = /* @__PURE__ */ new Set();
|
|
278
266
|
for (const key of Object.values(object)) {
|
|
@@ -413,6 +401,10 @@ function kebabCaseToCamelCase(string) {
|
|
|
413
401
|
return firstLetterOfWord === void 0 ? "" : firstLetterOfWord.toUpperCase();
|
|
414
402
|
});
|
|
415
403
|
}
|
|
404
|
+
function kebabCaseToPascalCase(string) {
|
|
405
|
+
const camelCase = kebabCaseToCamelCase(string);
|
|
406
|
+
return capitalizeFirstLetter(camelCase);
|
|
407
|
+
}
|
|
416
408
|
function normalizeString(string) {
|
|
417
409
|
let sanitizedString = string;
|
|
418
410
|
sanitizedString = removeNonPrintableCharacters(sanitizedString);
|
|
@@ -558,19 +550,16 @@ exports.isKeyOf = isKeyOf;
|
|
|
558
550
|
exports.isObject = isObject;
|
|
559
551
|
exports.isSemanticVersion = isSemanticVersion;
|
|
560
552
|
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
553
|
+
exports.kebabCaseToPascalCase = kebabCaseToPascalCase;
|
|
561
554
|
exports.mapFilter = mapFilter;
|
|
562
555
|
exports.mapFind = mapFind;
|
|
563
556
|
exports.newArray = newArray;
|
|
564
557
|
exports.noop = noop;
|
|
565
558
|
exports.normalizeString = normalizeString;
|
|
566
559
|
exports.objectFilter = objectFilter;
|
|
567
|
-
exports.objectKeysToReadonlySet = objectKeysToReadonlySet;
|
|
568
560
|
exports.objectKeysToSet = objectKeysToSet;
|
|
569
561
|
exports.objectToMap = objectToMap;
|
|
570
|
-
exports.objectToReadonlyMap = objectToReadonlyMap;
|
|
571
562
|
exports.objectToReverseMap = objectToReverseMap;
|
|
572
|
-
exports.objectToReverseReadonlyMap = objectToReverseReadonlyMap;
|
|
573
|
-
exports.objectValuesToReadonlySet = objectValuesToReadonlySet;
|
|
574
563
|
exports.objectValuesToSet = objectValuesToSet;
|
|
575
564
|
exports.parseFloatSafe = parseFloatSafe;
|
|
576
565
|
exports.parseIntSafe = parseIntSafe;
|
package/dist/index.d.cts
CHANGED
|
@@ -24,6 +24,7 @@ export type * from "./types/ObjectValues.js";
|
|
|
24
24
|
export * from "./types/ReadonlyMap.js";
|
|
25
25
|
export type * from "./types/ReadonlyRecord.js";
|
|
26
26
|
export * from "./types/ReadonlySet.js";
|
|
27
|
+
export type * from "./types/TranspiledEnum.js";
|
|
27
28
|
export type * from "./types/Tuple.js";
|
|
28
29
|
export type * from "./types/WidenLiteral.js";
|
|
29
30
|
export type * from "./types/Writeable.js";
|
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,7 @@ export type * from "./types/ObjectValues.js";
|
|
|
24
24
|
export * from "./types/ReadonlyMap.js";
|
|
25
25
|
export type * from "./types/ReadonlyRecord.js";
|
|
26
26
|
export * from "./types/ReadonlySet.js";
|
|
27
|
+
export type * from "./types/TranspiledEnum.js";
|
|
27
28
|
export type * from "./types/Tuple.js";
|
|
28
29
|
export type * from "./types/WidenLiteral.js";
|
|
29
30
|
export type * from "./types/Writeable.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type * from "./types/ObjectValues.js";
|
|
|
24
24
|
export * from "./types/ReadonlyMap.js";
|
|
25
25
|
export type * from "./types/ReadonlyRecord.js";
|
|
26
26
|
export * from "./types/ReadonlySet.js";
|
|
27
|
+
export type * from "./types/TranspiledEnum.js";
|
|
27
28
|
export type * from "./types/Tuple.js";
|
|
28
29
|
export type * from "./types/WidenLiteral.js";
|
|
29
30
|
export type * from "./types/Writeable.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,mBAAmB,wBAAwB,CAAC;AAC5C,mBAAmB,yCAAyC,CAAC;AAC7D,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,4CAA4C,CAAC;AAChE,mBAAmB,yBAAyB,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,mBAAmB,2BAA2B,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,mBAAmB,kBAAkB,CAAC;AACtC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,mBAAmB,wBAAwB,CAAC;AAC5C,mBAAmB,yCAAyC,CAAC;AAC7D,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,4CAA4C,CAAC;AAChE,mBAAmB,yBAAyB,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,mBAAmB,2BAA2B,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,mBAAmB,2BAA2B,CAAC;AAC/C,mBAAmB,kBAAkB,CAAC;AACtC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,sBAAsB,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -190,8 +190,8 @@ function mapFilter(map, predicate) {
|
|
|
190
190
|
return array;
|
|
191
191
|
}
|
|
192
192
|
function mapFind(map, predicate) {
|
|
193
|
-
for (const value of map
|
|
194
|
-
const match = predicate(value);
|
|
193
|
+
for (const [key, value] of map) {
|
|
194
|
+
const match = predicate(value, key, map);
|
|
195
195
|
if (match) {
|
|
196
196
|
return value;
|
|
197
197
|
}
|
|
@@ -221,9 +221,6 @@ function objectToMap(object) {
|
|
|
221
221
|
}
|
|
222
222
|
return map;
|
|
223
223
|
}
|
|
224
|
-
function objectToReadonlyMap(object) {
|
|
225
|
-
return objectToMap(object);
|
|
226
|
-
}
|
|
227
224
|
function objectToReverseMap(object) {
|
|
228
225
|
const map = /* @__PURE__ */ new Map();
|
|
229
226
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -231,9 +228,6 @@ function objectToReverseMap(object) {
|
|
|
231
228
|
}
|
|
232
229
|
return map;
|
|
233
230
|
}
|
|
234
|
-
function objectToReverseReadonlyMap(object) {
|
|
235
|
-
return objectToReverseMap(object);
|
|
236
|
-
}
|
|
237
231
|
|
|
238
232
|
function addSetsToSet(mainSet, ...setsToAdd) {
|
|
239
233
|
for (const set of setsToAdd) {
|
|
@@ -258,9 +252,6 @@ function copySet(oldSet) {
|
|
|
258
252
|
}
|
|
259
253
|
return newSet;
|
|
260
254
|
}
|
|
261
|
-
function objectKeysToReadonlySet(object) {
|
|
262
|
-
return objectKeysToSet(object);
|
|
263
|
-
}
|
|
264
255
|
function objectKeysToSet(object) {
|
|
265
256
|
const set = /* @__PURE__ */ new Set();
|
|
266
257
|
for (const key of Object.keys(object)) {
|
|
@@ -268,9 +259,6 @@ function objectKeysToSet(object) {
|
|
|
268
259
|
}
|
|
269
260
|
return set;
|
|
270
261
|
}
|
|
271
|
-
function objectValuesToReadonlySet(object) {
|
|
272
|
-
return objectValuesToSet(object);
|
|
273
|
-
}
|
|
274
262
|
function objectValuesToSet(object) {
|
|
275
263
|
const set = /* @__PURE__ */ new Set();
|
|
276
264
|
for (const key of Object.values(object)) {
|
|
@@ -411,6 +399,10 @@ function kebabCaseToCamelCase(string) {
|
|
|
411
399
|
return firstLetterOfWord === void 0 ? "" : firstLetterOfWord.toUpperCase();
|
|
412
400
|
});
|
|
413
401
|
}
|
|
402
|
+
function kebabCaseToPascalCase(string) {
|
|
403
|
+
const camelCase = kebabCaseToCamelCase(string);
|
|
404
|
+
return capitalizeFirstLetter(camelCase);
|
|
405
|
+
}
|
|
414
406
|
function normalizeString(string) {
|
|
415
407
|
let sanitizedString = string;
|
|
416
408
|
sanitizedString = removeNonPrintableCharacters(sanitizedString);
|
|
@@ -508,4 +500,4 @@ function* tupleKeys(tuple) {
|
|
|
508
500
|
|
|
509
501
|
const ReadonlyMap = Map;
|
|
510
502
|
|
|
511
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertEnumValue, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isObject, isSemanticVersion, kebabCaseToCamelCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter,
|
|
503
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveInPlace, assertArray, assertBoolean, assertDefined, assertEnumValue, assertNotNull, assertNumber, assertObject, assertString, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterMap, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, interfaceSatisfiesEnum, isArray, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isObject, isSemanticVersion, kebabCaseToCamelCase, kebabCaseToPascalCase, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranspiledEnum.d.ts","sourceRoot":"","sources":["../../src/types/TranspiledEnum.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://complete-ts.github.io/",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"test": "glob \"./src/**/*.test.ts\" --cmd=\"node --import tsx --test --test-reporter spec\""
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "22.13.
|
|
39
|
-
"complete-node": "5.1.
|
|
38
|
+
"@types/node": "22.13.10",
|
|
39
|
+
"complete-node": "5.1.2",
|
|
40
40
|
"eslint-plugin-sort-exports": "0.9.1",
|
|
41
41
|
"glob": "11.0.1",
|
|
42
42
|
"typescript": "5.8.2",
|
package/src/functions/array.ts
CHANGED
|
@@ -13,10 +13,9 @@ import { getRandomInt } from "./random.js";
|
|
|
13
13
|
* Helper function to copy a two-dimensional array. Note that the sub-arrays will only be shallow
|
|
14
14
|
* copied (using the spread operator).
|
|
15
15
|
*/
|
|
16
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
17
16
|
export function arrayCopyTwoDimensional<T>(
|
|
18
17
|
array: ReadonlyArray<readonly T[]>,
|
|
19
|
-
): T[][] {
|
|
18
|
+
): readonly T[][] {
|
|
20
19
|
const copiedArray: T[][] = [];
|
|
21
20
|
|
|
22
21
|
for (const subArray of array) {
|
|
@@ -51,11 +50,10 @@ export function arrayEquals<T>(
|
|
|
51
50
|
*
|
|
52
51
|
* This function is variadic, meaning that you can specify N arguments to remove N elements.
|
|
53
52
|
*/
|
|
54
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
55
53
|
export function arrayRemove<T>(
|
|
56
54
|
originalArray: readonly T[],
|
|
57
55
|
...elementsToRemove: readonly T[]
|
|
58
|
-
): T[] {
|
|
56
|
+
): readonly T[] {
|
|
59
57
|
const elementsToRemoveSet = new ReadonlySet(elementsToRemove);
|
|
60
58
|
|
|
61
59
|
const array: T[] = [];
|
|
@@ -80,12 +78,11 @@ export function arrayRemove<T>(
|
|
|
80
78
|
*
|
|
81
79
|
* @returns The removed elements. This will be an empty array if no elements were removed.
|
|
82
80
|
*/
|
|
83
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
84
81
|
export function arrayRemoveInPlace<T>(
|
|
85
82
|
// eslint-disable-next-line complete/prefer-readonly-parameter-types
|
|
86
83
|
array: T[],
|
|
87
84
|
...elementsToRemove: readonly T[]
|
|
88
|
-
): T[] {
|
|
85
|
+
): readonly T[] {
|
|
89
86
|
const removedElements: T[] = [];
|
|
90
87
|
|
|
91
88
|
for (const element of elementsToRemove) {
|
|
@@ -116,11 +113,10 @@ export function emptyArray(array: unknown[]): void {
|
|
|
116
113
|
* This is named `filterMap` after the Rust function:
|
|
117
114
|
* https://doc.rust-lang.org/std/iter/struct.FilterMap.html
|
|
118
115
|
*/
|
|
119
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
120
116
|
export function filterMap<OldT, NewT>(
|
|
121
117
|
array: readonly OldT[],
|
|
122
118
|
func: (element: OldT) => NewT | undefined,
|
|
123
|
-
): NewT[] {
|
|
119
|
+
): readonly NewT[] {
|
|
124
120
|
const filteredArray: NewT[] = [];
|
|
125
121
|
|
|
126
122
|
for (const element of array) {
|
|
@@ -204,8 +200,7 @@ export function isArray(arg: unknown): arg is unknown[] {
|
|
|
204
200
|
}
|
|
205
201
|
|
|
206
202
|
/** Initializes an array with all elements containing the specified default value. */
|
|
207
|
-
|
|
208
|
-
export function newArray<T>(length: number, value: T): T[] {
|
|
203
|
+
export function newArray<T>(length: number, value: T): readonly T[] {
|
|
209
204
|
return Array.from({ length }, () => value);
|
|
210
205
|
}
|
|
211
206
|
|
package/src/functions/assert.ts
CHANGED
package/src/functions/enums.ts
CHANGED
package/src/functions/map.ts
CHANGED
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
* If you want to perform a filter and a map at the same time on an array, use the `filterMap`
|
|
15
15
|
* helper function instead.
|
|
16
16
|
*/
|
|
17
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
18
17
|
export function mapFilter<K, V>(
|
|
19
18
|
map: ReadonlyMap<K, V>,
|
|
20
19
|
predicate: (value: V) => boolean,
|
|
21
|
-
): V[] {
|
|
20
|
+
): readonly V[] {
|
|
22
21
|
const array: V[] = [];
|
|
23
22
|
|
|
24
23
|
for (const value of map.values()) {
|
|
@@ -36,13 +35,17 @@ export function mapFilter<K, V>(
|
|
|
36
35
|
* maps.
|
|
37
36
|
*
|
|
38
37
|
* This is efficient such that it avoids converting the map values into an array.
|
|
38
|
+
*
|
|
39
|
+
* @param map The map to search through.
|
|
40
|
+
* @param predicate Function that tests each value for a condition.
|
|
41
|
+
* @returns The first value that satisfies the predicate, or undefined if no values satisfy.
|
|
39
42
|
*/
|
|
40
43
|
export function mapFind<K, V>(
|
|
41
44
|
map: ReadonlyMap<K, V>,
|
|
42
|
-
predicate: (value: V) => boolean,
|
|
45
|
+
predicate: (value: V, key: K, map: ReadonlyMap<K, V>) => boolean,
|
|
43
46
|
): V | undefined {
|
|
44
|
-
for (const value of map
|
|
45
|
-
const match = predicate(value);
|
|
47
|
+
for (const [key, value] of map) {
|
|
48
|
+
const match = predicate(value, key, map);
|
|
46
49
|
if (match) {
|
|
47
50
|
return value;
|
|
48
51
|
}
|
package/src/functions/object.ts
CHANGED
|
@@ -12,11 +12,10 @@ import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
|
12
12
|
*
|
|
13
13
|
* This is efficient such that it avoids converting the object values into an array.
|
|
14
14
|
*/
|
|
15
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
16
15
|
export function objectFilter<K extends string | number | symbol, V>(
|
|
17
16
|
object: ReadonlyRecord<K, V>,
|
|
18
17
|
predicate: (value: V) => boolean,
|
|
19
|
-
): V[] {
|
|
18
|
+
): readonly V[] {
|
|
20
19
|
const array: V[] = [];
|
|
21
20
|
|
|
22
21
|
// eslint-disable-next-line complete/no-for-in
|
|
@@ -41,13 +40,10 @@ export function objectFilter<K extends string | number | symbol, V>(
|
|
|
41
40
|
*
|
|
42
41
|
* Note that the converted map will only have string keys, due to the nature of JavaScript objects
|
|
43
42
|
* only having string keys under the hood.
|
|
44
|
-
*
|
|
45
|
-
* Also see the `objectToReadonlyMap` function.
|
|
46
43
|
*/
|
|
47
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
48
44
|
export function objectToMap<K extends string | number | symbol, V>(
|
|
49
45
|
object: Record<K, V>,
|
|
50
|
-
):
|
|
46
|
+
): ReadonlyMap<K, V> {
|
|
51
47
|
const map = new Map<K, V>();
|
|
52
48
|
|
|
53
49
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -57,38 +53,16 @@ export function objectToMap<K extends string | number | symbol, V>(
|
|
|
57
53
|
return map;
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
/**
|
|
61
|
-
* Helper function to convert an object to a read-only map.
|
|
62
|
-
*
|
|
63
|
-
* This is useful when you need to construct a type safe object with the `satisfies` operator, but
|
|
64
|
-
* then later on you need to query it in a way where you expect the return value to be T or
|
|
65
|
-
* undefined. In this situation, by converting the object to a map, you can avoid unsafe type
|
|
66
|
-
* assertions.
|
|
67
|
-
*
|
|
68
|
-
* Note that the converted map will only have string keys, due to the nature of JavaScript objects
|
|
69
|
-
* only having string keys under the hood.
|
|
70
|
-
*
|
|
71
|
-
* Also see the `objectToMap` function.
|
|
72
|
-
*/
|
|
73
|
-
export function objectToReadonlyMap<K extends string | number | symbol, V>(
|
|
74
|
-
object: Record<K, V>,
|
|
75
|
-
): ReadonlyMap<K, V> {
|
|
76
|
-
return objectToMap(object);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
56
|
/**
|
|
80
57
|
* Helper function to convert an object to a reverse map.
|
|
81
58
|
*
|
|
82
59
|
* Note that the converted map will only have string keys, due to the nature of JavaScript objects
|
|
83
60
|
* only having string keys under the hood.
|
|
84
|
-
*
|
|
85
|
-
* Also see the `objectToReverseReadonlyMap` function.
|
|
86
61
|
*/
|
|
87
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
88
62
|
export function objectToReverseMap<
|
|
89
63
|
K extends string | number | symbol,
|
|
90
64
|
V extends string | number | symbol,
|
|
91
|
-
>(object: Record<K, V>):
|
|
65
|
+
>(object: Record<K, V>): ReadonlyMap<V, K> {
|
|
92
66
|
const map = new Map<V, K>();
|
|
93
67
|
|
|
94
68
|
for (const [key, value] of Object.entries(object)) {
|
|
@@ -97,18 +71,3 @@ export function objectToReverseMap<
|
|
|
97
71
|
|
|
98
72
|
return map;
|
|
99
73
|
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Helper function to convert an object to a reverse read-only map.
|
|
103
|
-
*
|
|
104
|
-
* Note that the converted map will only have string keys, due to the nature of JavaScript objects
|
|
105
|
-
* only having string keys under the hood.
|
|
106
|
-
*
|
|
107
|
-
* Also see the `objectToReverseMap` function.
|
|
108
|
-
*/
|
|
109
|
-
export function objectToReverseReadonlyMap<
|
|
110
|
-
K extends string | number | symbol,
|
|
111
|
-
V extends string | number | symbol,
|
|
112
|
-
>(object: Record<K, V>): ReadonlyMap<V, K> {
|
|
113
|
-
return objectToReverseMap(object);
|
|
114
|
-
}
|
package/src/functions/set.ts
CHANGED
|
@@ -28,8 +28,9 @@ export function addSetsToSet<T>(
|
|
|
28
28
|
*
|
|
29
29
|
* This function is variadic, meaning that you can specify N sets.
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
export function combineSets<T>(
|
|
32
|
+
...sets: ReadonlyArray<ReadonlySet<T>>
|
|
33
|
+
): ReadonlySet<T> {
|
|
33
34
|
const newSet = new Set<T>();
|
|
34
35
|
for (const set of sets) {
|
|
35
36
|
for (const value of set) {
|
|
@@ -41,8 +42,7 @@ export function combineSets<T>(...sets: ReadonlyArray<ReadonlySet<T>>): Set<T> {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/** Helper function to copy a set. (You can also use a Set constructor to accomplish this task.) */
|
|
44
|
-
|
|
45
|
-
export function copySet<T>(oldSet: ReadonlySet<T>): Set<T> {
|
|
45
|
+
export function copySet<T>(oldSet: ReadonlySet<T>): ReadonlySet<T> {
|
|
46
46
|
const newSet = new Set<T>();
|
|
47
47
|
for (const value of oldSet) {
|
|
48
48
|
newSet.add(value);
|
|
@@ -51,26 +51,10 @@ export function copySet<T>(oldSet: ReadonlySet<T>): Set<T> {
|
|
|
51
51
|
return newSet;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* Helper function to convert the keys of an object to a read-only set.
|
|
56
|
-
*
|
|
57
|
-
* Also see the `objectKeysToSet` function.
|
|
58
|
-
*/
|
|
59
|
-
export function objectKeysToReadonlySet<K extends string | number | symbol, V>(
|
|
60
|
-
object: Record<K, V>,
|
|
61
|
-
): ReadonlySet<K> {
|
|
62
|
-
return objectKeysToSet(object);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Helper function to convert the keys of an object to a set.
|
|
67
|
-
*
|
|
68
|
-
* Also see the `objectKeysToReadonlySet` function.
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
54
|
+
/** Helper function to convert the keys of an object to a set. */
|
|
71
55
|
export function objectKeysToSet<K extends string | number | symbol, V>(
|
|
72
56
|
object: Record<K, V>,
|
|
73
|
-
):
|
|
57
|
+
): ReadonlySet<K> {
|
|
74
58
|
const set = new Set<K>();
|
|
75
59
|
|
|
76
60
|
for (const key of Object.keys(object)) {
|
|
@@ -80,27 +64,10 @@ export function objectKeysToSet<K extends string | number | symbol, V>(
|
|
|
80
64
|
return set;
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
/**
|
|
84
|
-
* Helper function to convert the values of an object to a read-only set.
|
|
85
|
-
*
|
|
86
|
-
* Also see the `objectValuesToSet` function.
|
|
87
|
-
*/
|
|
88
|
-
export function objectValuesToReadonlySet<
|
|
89
|
-
K extends string | number | symbol,
|
|
90
|
-
V,
|
|
91
|
-
>(object: Record<K, V>): ReadonlySet<V> {
|
|
92
|
-
return objectValuesToSet(object);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Helper function to convert the values of an object to a set.
|
|
97
|
-
*
|
|
98
|
-
* Also see the `objectValuesToReadonlySet` function.
|
|
99
|
-
*/
|
|
100
|
-
// eslint-disable-next-line complete/no-mutable-return
|
|
67
|
+
/** Helper function to convert the values of an object to a set. */
|
|
101
68
|
export function objectValuesToSet<K extends string | number | symbol, V>(
|
|
102
69
|
object: Record<K, V>,
|
|
103
|
-
):
|
|
70
|
+
): ReadonlySet<V> {
|
|
104
71
|
const set = new Set<V>();
|
|
105
72
|
|
|
106
73
|
for (const key of Object.values(object)) {
|
package/src/functions/sort.ts
CHANGED
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* From:
|
|
12
12
|
* https://stackoverflow.com/questions/8996963/how-to-perform-case-insensitive-sorting-array-of-string-in-javascript
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export function sortCaseInsensitive(
|
|
15
|
+
array: readonly string[],
|
|
16
|
+
): readonly string[] {
|
|
16
17
|
const newArray = [...array];
|
|
17
18
|
newArray.sort((a, b) =>
|
|
18
19
|
a.localeCompare(b, undefined, {
|
package/src/functions/string.ts
CHANGED
|
@@ -126,7 +126,7 @@ export function isSemanticVersion(versionString: string): boolean {
|
|
|
126
126
|
return match !== null;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
/** Helper function to convert a string from kebab-case to
|
|
129
|
+
/** Helper function to convert a string from kebab-case to camelCase. */
|
|
130
130
|
export function kebabCaseToCamelCase(string: string): string {
|
|
131
131
|
return string.replaceAll(/-./g, (match) => {
|
|
132
132
|
const firstLetterOfWord = match[1];
|
|
@@ -136,6 +136,12 @@ export function kebabCaseToCamelCase(string: string): string {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
/** Helper function to convert a string from kebab-case to PascalCase. */
|
|
140
|
+
export function kebabCaseToPascalCase(string: string): string {
|
|
141
|
+
const camelCase = kebabCaseToCamelCase(string);
|
|
142
|
+
return capitalizeFirstLetter(camelCase);
|
|
143
|
+
}
|
|
144
|
+
|
|
139
145
|
/**
|
|
140
146
|
* Helper function to normalize a string. Specifically, this performs the following steps:
|
|
141
147
|
*
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type * from "./types/ObjectValues.js";
|
|
|
24
24
|
export * from "./types/ReadonlyMap.js";
|
|
25
25
|
export type * from "./types/ReadonlyRecord.js";
|
|
26
26
|
export * from "./types/ReadonlySet.js";
|
|
27
|
+
export type * from "./types/TranspiledEnum.js";
|
|
27
28
|
export type * from "./types/Tuple.js";
|
|
28
29
|
export type * from "./types/WidenLiteral.js";
|
|
29
30
|
export type * from "./types/Writeable.js";
|