complete-common 2.21.0 → 2.22.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.
@@ -4,6 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import type { TranspiledEnum } from "../types/TranspiledEnum.js";
7
+ import type { Tuple } from "../types/Tuple.js";
7
8
  /** Helper function to throw an error if the provided value is not an array. */
8
9
  export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
9
10
  "The assertion is useless because the provided value is already an array."
@@ -15,6 +16,13 @@ export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly
15
16
  export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
16
17
  "The assertion is useless because the provided value is already a boolean array."
17
18
  ] : [string]): asserts value is T & boolean[];
19
+ /**
20
+ * Helper function to throw an error if the provided array does not have the specified length. Will
21
+ * also type narrow the array into a tuple of the specified length.
22
+ */
23
+ export declare function assertArrayLength<E, N extends number>(value: E[], // eslint-disable-line complete/prefer-readonly-parameter-types
24
+ length: N, msg: string): asserts value is Tuple<E, N>;
25
+ export declare function assertArrayLength<E, N extends number>(value: readonly E[], length: N, msg: string): asserts value is Readonly<Tuple<E, N>>;
18
26
  /**
19
27
  * Helper function to throw an error if the provided value is not an array with every element being
20
28
  * a number.
@@ -4,6 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import type { TranspiledEnum } from "../types/TranspiledEnum.js";
7
+ import type { Tuple } from "../types/Tuple.js";
7
8
  /** Helper function to throw an error if the provided value is not an array. */
8
9
  export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
9
10
  "The assertion is useless because the provided value is already an array."
@@ -15,6 +16,13 @@ export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly
15
16
  export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
16
17
  "The assertion is useless because the provided value is already a boolean array."
17
18
  ] : [string]): asserts value is T & boolean[];
19
+ /**
20
+ * Helper function to throw an error if the provided array does not have the specified length. Will
21
+ * also type narrow the array into a tuple of the specified length.
22
+ */
23
+ export declare function assertArrayLength<E, N extends number>(value: E[], // eslint-disable-line complete/prefer-readonly-parameter-types
24
+ length: N, msg: string): asserts value is Tuple<E, N>;
25
+ export declare function assertArrayLength<E, N extends number>(value: readonly E[], length: N, msg: string): asserts value is Readonly<Tuple<E, N>>;
18
26
  /**
19
27
  * Helper function to throw an error if the provided value is not an array with every element being
20
28
  * a number.
@@ -4,6 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import type { TranspiledEnum } from "../types/TranspiledEnum.js";
7
+ import type { Tuple } from "../types/Tuple.js";
7
8
  /** Helper function to throw an error if the provided value is not an array. */
8
9
  export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly unknown[]] ? [
9
10
  "The assertion is useless because the provided value is already an array."
@@ -15,6 +16,13 @@ export declare function assertArray<T>(value: T, ...[msg]: [T] extends [readonly
15
16
  export declare function assertArrayBoolean<T>(value: T, ...[msg]: [T] extends [readonly boolean[]] ? [
16
17
  "The assertion is useless because the provided value is already a boolean array."
17
18
  ] : [string]): asserts value is T & boolean[];
19
+ /**
20
+ * Helper function to throw an error if the provided array does not have the specified length. Will
21
+ * also type narrow the array into a tuple of the specified length.
22
+ */
23
+ export declare function assertArrayLength<E, N extends number>(value: E[], // eslint-disable-line complete/prefer-readonly-parameter-types
24
+ length: N, msg: string): asserts value is Tuple<E, N>;
25
+ export declare function assertArrayLength<E, N extends number>(value: readonly E[], length: N, msg: string): asserts value is Readonly<Tuple<E, N>>;
18
26
  /**
19
27
  * Helper function to throw an error if the provided value is not an array with every element being
20
28
  * a number.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/functions/assert.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,+EAA+E;AAC/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R,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAC1B;IACE,0EAA0E;CAC3E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,MAAM,CAI7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC3C;IACE,2EAA2E;CAC5E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9C;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAC1B;IACE,0EAA0E;CAC3E,GACD,CAAC,MAAM,CAAC,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,MAAM,CAI7B;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,KAAK,IAAI,MAAM,CAMzB"}
package/dist/index.cjs CHANGED
@@ -49,6 +49,11 @@ function assertArrayBoolean(value, ...[msg]) {
49
49
  throw new TypeError(msg);
50
50
  }
51
51
  }
52
+ function assertArrayLength(value, length, msg) {
53
+ if (value.length !== length) {
54
+ throw new TypeError(msg);
55
+ }
56
+ }
52
57
  function assertArrayNumber(value, ...[msg]) {
53
58
  if (!Array.isArray(value)) {
54
59
  throw new TypeError(msg);
@@ -677,6 +682,7 @@ exports.arrayRemoveAllInPlace = arrayRemoveAllInPlace;
677
682
  exports.arrayRemoveInPlace = arrayRemoveInPlace;
678
683
  exports.assertArray = assertArray;
679
684
  exports.assertArrayBoolean = assertArrayBoolean;
685
+ exports.assertArrayLength = assertArrayLength;
680
686
  exports.assertArrayNumber = assertArrayNumber;
681
687
  exports.assertArrayObject = assertArrayObject;
682
688
  exports.assertArrayString = assertArrayString;
package/dist/index.mjs CHANGED
@@ -47,6 +47,11 @@ function assertArrayBoolean(value, ...[msg]) {
47
47
  throw new TypeError(msg);
48
48
  }
49
49
  }
50
+ function assertArrayLength(value, length, msg) {
51
+ if (value.length !== length) {
52
+ throw new TypeError(msg);
53
+ }
54
+ }
50
55
  function assertArrayNumber(value, ...[msg]) {
51
56
  if (!Array.isArray(value)) {
52
57
  throw new TypeError(msg);
@@ -662,4 +667,4 @@ function* tupleKeys(tuple) {
662
667
 
663
668
  const ReadonlyMap = Map;
664
669
 
665
- export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, getWidenedObjectValue, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayObject, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, reverseObject, satisfiesSemanticVersion, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
670
+ export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayLength, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, getWidenedObjectValue, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayObject, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, reverseObject, satisfiesSemanticVersion, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "complete-common",
3
- "version": "2.21.0",
3
+ "version": "2.22.1",
4
4
  "description": "Helper functions for TypeScript projects.",
5
5
  "homepage": "https://complete-ts.github.io/",
6
6
  "bugs": {
@@ -29,15 +29,14 @@
29
29
  "build": "bun run ./scripts/build.ts",
30
30
  "docs": "typedoc",
31
31
  "lint": "bun run ./scripts/lint.ts",
32
- "test": "bun test"
32
+ "test": "bun test ./tests"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "25.4.0",
36
- "complete-node": "16.3.1",
37
- "eslint-plugin-sort-exports": "0.9.1",
38
- "typedoc": "0.28.17",
39
- "typedoc-plugin-markdown": "4.10.0",
40
- "typescript": "5.9.3",
35
+ "@types/node": "25.5.0",
36
+ "complete-node": "16.4.0",
37
+ "typedoc": "0.28.18",
38
+ "typedoc-plugin-markdown": "4.11.0",
39
+ "typescript": "6.0.2",
41
40
  "unbuild": "3.6.1"
42
41
  }
43
42
  }
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import type { TranspiledEnum } from "../types/TranspiledEnum.js";
12
+ import type { Tuple } from "../types/Tuple.js";
12
13
  import { isEnumValue } from "./enums.js";
13
14
  import { isObject } from "./types.js";
14
15
 
@@ -47,6 +48,30 @@ export function assertArrayBoolean<T>(
47
48
  }
48
49
  }
49
50
 
51
+ /**
52
+ * Helper function to throw an error if the provided array does not have the specified length. Will
53
+ * also type narrow the array into a tuple of the specified length.
54
+ */
55
+ export function assertArrayLength<E, N extends number>(
56
+ value: E[], // eslint-disable-line complete/prefer-readonly-parameter-types
57
+ length: N,
58
+ msg: string,
59
+ ): asserts value is Tuple<E, N>;
60
+ export function assertArrayLength<E, N extends number>(
61
+ value: readonly E[],
62
+ length: N,
63
+ msg: string,
64
+ ): asserts value is Readonly<Tuple<E, N>>;
65
+ export function assertArrayLength(
66
+ value: readonly unknown[],
67
+ length: number,
68
+ msg: string,
69
+ ): asserts value is unknown[] {
70
+ if (value.length !== length) {
71
+ throw new TypeError(msg);
72
+ }
73
+ }
74
+
50
75
  /**
51
76
  * Helper function to throw an error if the provided value is not an array with every element being
52
77
  * a number.
@@ -10,7 +10,7 @@ type TupleKey<T extends readonly unknown[]> = {
10
10
  [L in T["length"]]: Exclude<Partial<Tuple<unknown, L>>["length"], L>;
11
11
  }[T["length"]];
12
12
  type TupleValue<T extends readonly unknown[]> = T[0];
13
- type TupleEntry<T extends readonly unknown[]> = [TupleKey<T>, TupleValue<T>];
13
+ type TupleEntry<T extends readonly unknown[]> = [TupleKey<T>, TupleValue<T>]; // eslint-disable-line perfectionist/sort-modules
14
14
 
15
15
  /**
16
16
  * Helper function to get the entries (i.e. indexes and values) of a tuple in a type-safe way.
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=string.test.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=string.test.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=string.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.test.d.ts","sourceRoot":"","sources":["../../src/functions/string.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utils.test.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utils.test.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utils.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/functions/utils.test.ts"],"names":[],"mappings":""}
@@ -1,205 +0,0 @@
1
- /* eslint-disable complete/require-ascii */
2
-
3
- import { equal } from "node:assert";
4
- import { describe, test } from "node:test";
5
- import {
6
- hasDiacritic,
7
- hasEmoji,
8
- isASCII,
9
- isKebabCase,
10
- titleCaseToKebabCase,
11
- trimPrefix,
12
- trimSuffix,
13
- } from "./string.js";
14
-
15
- describe("hasEmoji", () => {
16
- test("should return true for string with normal emoji", () => {
17
- equal(hasEmoji("Hello 😃 World"), true);
18
- });
19
-
20
- test("should return true for string with keycap emoji", () => {
21
- equal(hasEmoji("This is a keycap emoji: #️⃣"), true);
22
- });
23
-
24
- test("should return false for string without emoji", () => {
25
- equal(hasEmoji("Hello World"), false);
26
- equal(
27
- hasEmoji(`
28
- # Some Markdown Title
29
-
30
- This page is for people who like [cake](https://en.wikipedia.org/wiki/Cake).
31
-
32
- - Run \`command cake\` to get cake.
33
- - Run \`command pie\` to get pie.
34
- `),
35
- false,
36
- );
37
- });
38
-
39
- test("should handle empty string", () => {
40
- equal(hasEmoji(""), false);
41
- });
42
-
43
- test("should handle strings with only emoji", () => {
44
- equal(hasEmoji("😊"), true);
45
- equal(hasEmoji("🚀"), true);
46
- });
47
- });
48
-
49
- describe("hasDiacritic", () => {
50
- test("should return true for diacritic character", () => {
51
- equal(hasDiacritic("á"), true);
52
- equal(hasDiacritic("è"), true);
53
- equal(hasDiacritic("ô"), true);
54
- });
55
-
56
- test("should return false for non-diacritic character", () => {
57
- equal(hasDiacritic("A"), false);
58
- equal(hasDiacritic("1"), false);
59
- equal(hasDiacritic("!"), false);
60
- });
61
-
62
- test("should handle empty string", () => {
63
- equal(hasDiacritic(""), false);
64
- });
65
- });
66
-
67
- describe("isASCII", () => {
68
- test("should return true for ASCII strings", () => {
69
- equal(isASCII("Hello World"), true);
70
- equal(isASCII("1234567890"), true);
71
- equal(isASCII("!@#$%^&*()_+"), true);
72
- equal(isASCII(" \n\t\r"), true);
73
- });
74
-
75
- test("should return false for non-ASCII strings", () => {
76
- equal(isASCII("Hello World 😃"), false);
77
- equal(isASCII("á"), false);
78
- equal(isASCII("è"), false);
79
- equal(isASCII("ô"), false);
80
- equal(isASCII("😊"), false);
81
- });
82
-
83
- test("should handle empty string", () => {
84
- equal(isASCII(""), true);
85
- });
86
- });
87
-
88
- describe("isKebabCase", () => {
89
- test("should return true for valid kebab-case strings", () => {
90
- equal(isKebabCase("hello-world"), true);
91
- equal(isKebabCase("lowercase"), true);
92
- equal(isKebabCase("item-123-abc"), true);
93
- equal(isKebabCase("section-1a"), true);
94
- equal(isKebabCase("segment-1-2-3"), true);
95
- equal(isKebabCase("1-2-3"), true);
96
- equal(isKebabCase("12345"), true);
97
- equal(isKebabCase("fix-k8s"), true);
98
- });
99
-
100
- test("should return false for strings with uppercase letters", () => {
101
- equal(isKebabCase("HelloWorld"), false);
102
- equal(isKebabCase("helloWorld"), false);
103
- equal(isKebabCase("Hello-World"), false);
104
- equal(isKebabCase("kebab-Case"), false);
105
- equal(isKebabCase("HELLO-WORLD"), false);
106
- equal(isKebabCase("UPPERCASE"), false);
107
- });
108
-
109
- test("should return false for strings with spaces", () => {
110
- equal(isKebabCase("hello world"), false);
111
- equal(isKebabCase(" hello-world"), false);
112
- equal(isKebabCase("hello-world "), false);
113
- equal(isKebabCase("hello - world"), false);
114
- });
115
-
116
- test("should return false for strings with underscores", () => {
117
- equal(isKebabCase("hello_world"), false);
118
- equal(isKebabCase("snake_case_example"), false);
119
- });
120
-
121
- test("should return false for strings with consecutive hyphens", () => {
122
- equal(isKebabCase("hello--world"), false);
123
- equal(isKebabCase("a--b--c"), false);
124
- });
125
-
126
- test("should return false for strings starting or ending with a hyphen", () => {
127
- equal(isKebabCase("-hello-world"), false);
128
- equal(isKebabCase("hello-world-"), false);
129
- equal(isKebabCase("-start"), false);
130
- equal(isKebabCase("end-"), false);
131
- equal(isKebabCase("-"), false);
132
- });
133
-
134
- test("should return false for strings with special characters other than hyphens", () => {
135
- equal(isKebabCase("hello-world!"), false);
136
- equal(isKebabCase("test@example"), false);
137
- equal(isKebabCase("kebab$case"), false);
138
- equal(isKebabCase("has-#-symbol"), false);
139
- equal(isKebabCase("dot.case"), false);
140
- equal(isKebabCase("slash/case"), false);
141
- });
142
-
143
- test("should return false for mixed separators", () => {
144
- equal(isKebabCase("hello_world-foo"), false);
145
- equal(isKebabCase("hello-world_bar"), false);
146
- });
147
-
148
- test("should return false for an empty string", () => {
149
- equal(isKebabCase(""), false);
150
- });
151
- });
152
-
153
- describe("titleCaseToKebabCase", () => {
154
- test("should convert a single TitleCase word to lowercase", () => {
155
- equal(titleCaseToKebabCase("Foo"), "foo");
156
- });
157
-
158
- test("should convert two TitleCase words to kebab-case", () => {
159
- equal(titleCaseToKebabCase("FooBar"), "foo-bar");
160
- });
161
-
162
- test("should convert multiple TitleCase words to kebab-case", () => {
163
- equal(titleCaseToKebabCase("FooBarBaz"), "foo-bar-baz");
164
- });
165
-
166
- test("should handle an empty string", () => {
167
- equal(titleCaseToKebabCase(""), "");
168
- });
169
-
170
- test("should handle a string that is already lowercase", () => {
171
- equal(titleCaseToKebabCase("foo"), "foo");
172
- });
173
-
174
- test("should handle a string with digits", () => {
175
- equal(titleCaseToKebabCase("Foo2Bar"), "foo2-bar");
176
- });
177
-
178
- test("should handle spaces", () => {
179
- equal(titleCaseToKebabCase("Foo Bar"), "foo-bar");
180
- });
181
-
182
- test("should handle multiple spaces", () => {
183
- equal(titleCaseToKebabCase("Foo Bar"), "foo-bar");
184
- });
185
- });
186
-
187
- describe("trimPrefix", () => {
188
- test(() => {
189
- equal(trimPrefix("foo", ""), "foo");
190
- equal(trimPrefix("foo", "f"), "oo");
191
- equal(trimPrefix("foo", "fo"), "o");
192
- equal(trimPrefix("foo", "foo"), "");
193
- equal(trimPrefix("foo", "foo1"), "foo");
194
- });
195
- });
196
-
197
- describe("trimSuffix", () => {
198
- test(() => {
199
- equal(trimSuffix("foo", ""), "foo");
200
- equal(trimSuffix("foo", "o"), "fo");
201
- equal(trimSuffix("foo", "oo"), "f");
202
- equal(trimSuffix("foo", "foo"), "");
203
- equal(trimSuffix("foo", "1foo"), "foo");
204
- });
205
- });
@@ -1,904 +0,0 @@
1
- import { deepStrictEqual, strictEqual } from "node:assert";
2
- import { describe, test } from "node:test";
3
- import { assertDefined, assertNotNull } from "./assert.js";
4
- import { eRange, iRange, parseFloatSafe, parseIntSafe } from "./utils.js";
5
-
6
- describe("assertsDefined", () => {
7
- /** We use a value of null since it is the least arbitrary non-undefined value. */
8
- const value = null as unknown; // eslint-disable-line unicorn/no-null
9
-
10
- // @ts-expect-error Should fail since we are not in a union with undefined.
11
- assertDefined(value as boolean, "");
12
- // @ts-expect-error Should fail since we are not in a union with undefined.
13
- assertDefined(value as number, "");
14
- // @ts-expect-error Should fail since we are not in a union with undefined.
15
- assertDefined(value as string, "");
16
- // @ts-expect-error Should fail since we are not in a union with undefined.
17
- assertDefined(value as Function, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
18
-
19
- assertDefined(value as boolean | undefined, "");
20
- assertDefined(value as number | undefined, "");
21
- assertDefined(value as string | undefined, "");
22
- assertDefined(value as Function | undefined, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
23
-
24
- // @ts-expect-error Should fail because we are in a union with null instead of undefined.
25
- assertDefined(value as boolean | null, "");
26
- // @ts-expect-error Should fail because we are in a union with null instead of undefined.
27
- assertDefined(value as number | null, "");
28
- // @ts-expect-error Should fail because we are in a union with null instead of undefined.
29
- assertDefined(value as string | null, "");
30
- // @ts-expect-error Should fail because we are in a union with null instead of undefined.
31
- assertDefined(value as Function | null, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
32
-
33
- assertDefined(value as boolean | undefined | null, "");
34
- assertDefined(value as number | undefined | null, "");
35
- assertDefined(value as string | undefined | null, "");
36
- assertDefined(value as Function | undefined | null, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
37
-
38
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
39
- function _genericFunction<T>(_arg: T) {
40
- const t = undefined as T | undefined;
41
- assertDefined(t, "");
42
- }
43
- });
44
-
45
- describe("assertsNull", () => {
46
- const value = undefined as unknown;
47
-
48
- // @ts-expect-error Should fail since we are not in a union with null.
49
- assertNotNull(value as boolean, "");
50
- // @ts-expect-error Should fail since we are not in a union with null.
51
- assertNotNull(value as number, "");
52
- // @ts-expect-error Should fail since we are not in a union with null.
53
- assertNotNull(value as string, "");
54
- // @ts-expect-error Should fail since we are not in a union with null.
55
- assertNotNull(value as Function, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
56
-
57
- assertNotNull(value as boolean | null, "");
58
- assertNotNull(value as number | null, "");
59
- assertNotNull(value as string | null, "");
60
- assertNotNull(value as Function | null, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
61
-
62
- // @ts-expect-error Should fail because we are in a union with undefined instead of null.
63
- assertNotNull(value as boolean | undefined, "");
64
- // @ts-expect-error Should fail because we are in a union with undefined instead of null.
65
- assertNotNull(value as number | undefined, "");
66
- // @ts-expect-error Should fail because we are in a union with undefined instead of null.
67
- assertNotNull(value as string | undefined, "");
68
- // @ts-expect-error Should fail because we are in a union with undefined instead of null.
69
- assertNotNull(value as Function | undefined, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
70
-
71
- assertNotNull(value as boolean | null | undefined, "");
72
- assertNotNull(value as number | null | undefined, "");
73
- assertNotNull(value as string | null | undefined, "");
74
- assertNotNull(value as Function | null | undefined, ""); // eslint-disable-line @typescript-eslint/no-unsafe-function-type
75
-
76
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
77
- function _genericFunction<T>(_arg: T) {
78
- const t = null as T | null; // eslint-disable-line unicorn/no-null
79
- assertNotNull(t, "");
80
- }
81
- });
82
-
83
- describe("eRange", () => {
84
- describe("1 arg 0", () => {
85
- test("0", () => {
86
- const result = [...eRange(0)];
87
- deepStrictEqual(result, []);
88
- });
89
- });
90
-
91
- describe("1 arg positive", () => {
92
- test("1", () => {
93
- const result = [...eRange(1)];
94
- deepStrictEqual(result, [0]);
95
- });
96
-
97
- test("2", () => {
98
- const result = [...eRange(2)];
99
- deepStrictEqual(result, [0, 1]);
100
- });
101
-
102
- test("3", () => {
103
- const result = [...eRange(3)];
104
- deepStrictEqual(result, [0, 1, 2]);
105
- });
106
- });
107
-
108
- describe("1 arg negative", () => {
109
- test("-1", () => {
110
- const result = [...eRange(-1)];
111
- deepStrictEqual(result, []);
112
- });
113
- });
114
-
115
- describe("2 args same", () => {
116
- test("0, 0", () => {
117
- const result = [...eRange(0, 0)];
118
- deepStrictEqual(result, []);
119
- });
120
-
121
- test("1, 1", () => {
122
- const result = [...eRange(1, 1)];
123
- deepStrictEqual(result, []);
124
- });
125
-
126
- test("2, 2", () => {
127
- const result = [...eRange(2, 2)];
128
- deepStrictEqual(result, []);
129
- });
130
-
131
- test("3, 3", () => {
132
- const result = [...eRange(3, 3)];
133
- deepStrictEqual(result, []);
134
- });
135
-
136
- test("-1, -1", () => {
137
- const result = [...eRange(-1, -1)];
138
- deepStrictEqual(result, []);
139
- });
140
-
141
- test("-2, -2", () => {
142
- const result = [...eRange(-2, -2)];
143
- deepStrictEqual(result, []);
144
- });
145
-
146
- test("-3, -3", () => {
147
- const result = [...eRange(-3, -3)];
148
- deepStrictEqual(result, []);
149
- });
150
- });
151
-
152
- describe("2 args increasing", () => {
153
- test("0, 1", () => {
154
- const result = [...eRange(0, 1)];
155
- deepStrictEqual(result, [0]);
156
- });
157
-
158
- test("0, 2", () => {
159
- const result = [...eRange(0, 2)];
160
- deepStrictEqual(result, [0, 1]);
161
- });
162
-
163
- test("0, 3", () => {
164
- const result = [...eRange(0, 3)];
165
- deepStrictEqual(result, [0, 1, 2]);
166
- });
167
-
168
- test("1, 2", () => {
169
- const result = [...eRange(1, 2)];
170
- deepStrictEqual(result, [1]);
171
- });
172
-
173
- test("1, 3", () => {
174
- const result = [...eRange(1, 3)];
175
- deepStrictEqual(result, [1, 2]);
176
- });
177
-
178
- test("1, 4", () => {
179
- const result = [...eRange(1, 4)];
180
- deepStrictEqual(result, [1, 2, 3]);
181
- });
182
-
183
- test("2, 3", () => {
184
- const result = [...eRange(2, 3)];
185
- deepStrictEqual(result, [2]);
186
- });
187
-
188
- test("2, 4", () => {
189
- const result = [...eRange(2, 4)];
190
- deepStrictEqual(result, [2, 3]);
191
- });
192
-
193
- test("2, 5", () => {
194
- const result = [...eRange(2, 5)];
195
- deepStrictEqual(result, [2, 3, 4]);
196
- });
197
-
198
- test("-3, -1", () => {
199
- const result = [...eRange(-3, -1)];
200
- deepStrictEqual(result, [-3, -2]);
201
- });
202
-
203
- test("-3, 3", () => {
204
- const result = [...eRange(-3, 3)];
205
- deepStrictEqual(result, [-3, -2, -1, 0, 1, 2]);
206
- });
207
- });
208
-
209
- describe("2 args decreasing", () => {
210
- test("1, 0", () => {
211
- const result = [...eRange(1, 0)];
212
- deepStrictEqual(result, []);
213
- });
214
-
215
- test("-1, -2", () => {
216
- const result = [...eRange(-1, -3)];
217
- deepStrictEqual(result, []);
218
- });
219
- });
220
- });
221
-
222
- describe("iRange", () => {
223
- describe("1 arg 0", () => {
224
- test("0", () => {
225
- const result = [...iRange(0)];
226
- deepStrictEqual(result, [0]);
227
- });
228
- });
229
-
230
- describe("1 arg positive", () => {
231
- test("1", () => {
232
- const result = [...iRange(1)];
233
- deepStrictEqual(result, [0, 1]);
234
- });
235
-
236
- test("2", () => {
237
- const result = [...iRange(2)];
238
- deepStrictEqual(result, [0, 1, 2]);
239
- });
240
-
241
- test("3", () => {
242
- const result = [...iRange(3)];
243
- deepStrictEqual(result, [0, 1, 2, 3]);
244
- });
245
- });
246
-
247
- describe("1 arg negative", () => {
248
- test("-1", () => {
249
- const result = [...iRange(-1)];
250
- deepStrictEqual(result, []);
251
- });
252
- });
253
-
254
- describe("2 args same", () => {
255
- test("0, 0", () => {
256
- const result = [...iRange(0, 0)];
257
- deepStrictEqual(result, [0]);
258
- });
259
-
260
- test("1, 1", () => {
261
- const result = [...iRange(1, 1)];
262
- deepStrictEqual(result, [1]);
263
- });
264
-
265
- test("2, 2", () => {
266
- const result = [...iRange(2, 2)];
267
- deepStrictEqual(result, [2]);
268
- });
269
-
270
- test("3, 3", () => {
271
- const result = [...iRange(3, 3)];
272
- deepStrictEqual(result, [3]);
273
- });
274
-
275
- test("-1, -1", () => {
276
- const result = [...iRange(-1, -1)];
277
- deepStrictEqual(result, [-1]);
278
- });
279
-
280
- test("-2, -2", () => {
281
- const result = [...iRange(-2, -2)];
282
- deepStrictEqual(result, [-2]);
283
- });
284
-
285
- test("-3, -3", () => {
286
- const result = [...iRange(-3, -3)];
287
- deepStrictEqual(result, [-3]);
288
- });
289
- });
290
-
291
- describe("2 args increasing", () => {
292
- test("0, 1", () => {
293
- const result = [...iRange(0, 1)];
294
- deepStrictEqual(result, [0, 1]);
295
- });
296
-
297
- test("0, 2", () => {
298
- const result = [...iRange(0, 2)];
299
- deepStrictEqual(result, [0, 1, 2]);
300
- });
301
-
302
- test("0, 3", () => {
303
- const result = [...iRange(0, 3)];
304
- deepStrictEqual(result, [0, 1, 2, 3]);
305
- });
306
-
307
- test("1, 2", () => {
308
- const result = [...iRange(1, 2)];
309
- deepStrictEqual(result, [1, 2]);
310
- });
311
-
312
- test("1, 3", () => {
313
- const result = [...iRange(1, 3)];
314
- deepStrictEqual(result, [1, 2, 3]);
315
- });
316
-
317
- test("1, 4", () => {
318
- const result = [...iRange(1, 4)];
319
- deepStrictEqual(result, [1, 2, 3, 4]);
320
- });
321
-
322
- test("2, 3", () => {
323
- const result = [...iRange(2, 3)];
324
- deepStrictEqual(result, [2, 3]);
325
- });
326
-
327
- test("2, 4", () => {
328
- const result = [...iRange(2, 4)];
329
- deepStrictEqual(result, [2, 3, 4]);
330
- });
331
-
332
- test("2, 5", () => {
333
- const result = [...iRange(2, 5)];
334
- deepStrictEqual(result, [2, 3, 4, 5]);
335
- });
336
-
337
- test("-3, -1", () => {
338
- const result = [...iRange(-3, -1)];
339
- deepStrictEqual(result, [-3, -2, -1]);
340
- });
341
-
342
- test("-3, 3", () => {
343
- const result = [...iRange(-3, 3)];
344
- deepStrictEqual(result, [-3, -2, -1, 0, 1, 2, 3]);
345
- });
346
- });
347
-
348
- describe("2 args decreasing", () => {
349
- test("1, 0", () => {
350
- const result = [...iRange(1, 0)];
351
- deepStrictEqual(result, []);
352
- });
353
-
354
- test("-1, -2", () => {
355
- const result = [...iRange(-1, -3)];
356
- deepStrictEqual(result, []);
357
- });
358
- });
359
- });
360
-
361
- describe("parseFloatSafe", () => {
362
- describe("non valid types", () => {
363
- test("undefined", () => {
364
- const result = parseFloatSafe(undefined as unknown as string);
365
- strictEqual(result, undefined);
366
- });
367
-
368
- test("null", () => {
369
- // eslint-disable-next-line unicorn/no-null
370
- const result = parseFloatSafe(null as unknown as string);
371
- strictEqual(result, undefined);
372
- });
373
-
374
- test("bigint", () => {
375
- const result = parseFloatSafe(1n as unknown as string);
376
- strictEqual(result, undefined);
377
- });
378
-
379
- test("false", () => {
380
- const result = parseFloatSafe(false as unknown as string);
381
- strictEqual(result, undefined);
382
- });
383
-
384
- test("true", () => {
385
- const result = parseFloatSafe(true as unknown as string);
386
- strictEqual(result, undefined);
387
- });
388
-
389
- test("function", () => {
390
- // eslint-disable-next-line @typescript-eslint/no-empty-function
391
- const result = parseFloatSafe((() => {}) as unknown as string);
392
- strictEqual(result, undefined);
393
- });
394
-
395
- test("number", () => {
396
- const result = parseFloatSafe(1 as unknown as string);
397
- strictEqual(result, undefined);
398
- });
399
-
400
- test("object", () => {
401
- const result = parseFloatSafe({} as string);
402
- strictEqual(result, undefined);
403
- });
404
-
405
- test("symbol", () => {
406
- const result = parseFloatSafe(Symbol("1") as unknown as string);
407
- strictEqual(result, undefined);
408
- });
409
- });
410
-
411
- describe("spaces", () => {
412
- test("space", () => {
413
- const result = parseFloatSafe(" ");
414
- strictEqual(result, undefined);
415
- });
416
-
417
- test("space + 1", () => {
418
- const result = parseFloatSafe(" 1");
419
- strictEqual(result, 1);
420
- });
421
-
422
- test("1 + space", () => {
423
- const result = parseFloatSafe("1 ");
424
- strictEqual(result, 1);
425
- });
426
-
427
- test("space + 1 + space", () => {
428
- const result = parseFloatSafe(" 1 ");
429
- strictEqual(result, 1);
430
- });
431
-
432
- test("space + -1", () => {
433
- const result = parseFloatSafe(" -1");
434
- strictEqual(result, -1);
435
- });
436
-
437
- test("-1 + space", () => {
438
- const result = parseFloatSafe("-1 ");
439
- strictEqual(result, -1);
440
- });
441
-
442
- test("space + -1 + space", () => {
443
- const result = parseFloatSafe(" -1 ");
444
- strictEqual(result, -1);
445
- });
446
-
447
- test("space + 1.0", () => {
448
- const result = parseFloatSafe(" 1.0");
449
- strictEqual(result, 1);
450
- });
451
-
452
- test("1.0 + space", () => {
453
- const result = parseFloatSafe("1.0 ");
454
- strictEqual(result, 1);
455
- });
456
-
457
- test("space + 1.0 + space", () => {
458
- const result = parseFloatSafe(" 1.0 ");
459
- strictEqual(result, 1);
460
- });
461
-
462
- test("space + -1.0", () => {
463
- const result = parseFloatSafe(" -1.0");
464
- strictEqual(result, -1);
465
- });
466
-
467
- test("-1.0 + space", () => {
468
- const result = parseFloatSafe("-1.0 ");
469
- strictEqual(result, -1);
470
- });
471
-
472
- test("space + -1.0 + space", () => {
473
- const result = parseFloatSafe(" -1.0 ");
474
- strictEqual(result, -1);
475
- });
476
- });
477
-
478
- describe("tabs", () => {
479
- test("tab", () => {
480
- const result = parseFloatSafe(" ");
481
- strictEqual(result, undefined);
482
- });
483
-
484
- test("tab + 1", () => {
485
- const result = parseFloatSafe(" 1");
486
- strictEqual(result, 1);
487
- });
488
-
489
- test("1 + tab", () => {
490
- const result = parseFloatSafe("1 ");
491
- strictEqual(result, 1);
492
- });
493
-
494
- test("tab + 1 + tab", () => {
495
- const result = parseFloatSafe(" 1 ");
496
- strictEqual(result, 1);
497
- });
498
-
499
- test("tab + -1", () => {
500
- const result = parseFloatSafe(" -1");
501
- strictEqual(result, -1);
502
- });
503
-
504
- test("-1 + tab", () => {
505
- const result = parseFloatSafe("-1 ");
506
- strictEqual(result, -1);
507
- });
508
-
509
- test("tab + -1 + tab", () => {
510
- const result = parseFloatSafe(" -1 ");
511
- strictEqual(result, -1);
512
- });
513
-
514
- test("tab + 1.0", () => {
515
- const result = parseFloatSafe(" 1.0");
516
- strictEqual(result, 1);
517
- });
518
-
519
- test("1.0 + tab", () => {
520
- const result = parseFloatSafe("1.0 ");
521
- strictEqual(result, 1);
522
- });
523
-
524
- test("tab + 1.0 + tab", () => {
525
- const result = parseFloatSafe(" 1.0 ");
526
- strictEqual(result, 1);
527
- });
528
-
529
- test("tab + -1.0", () => {
530
- const result = parseFloatSafe(" -1.0");
531
- strictEqual(result, -1);
532
- });
533
-
534
- test("-1.0 + tab", () => {
535
- const result = parseFloatSafe("-1.0 ");
536
- strictEqual(result, -1);
537
- });
538
-
539
- test("tab + -1.0 + tab", () => {
540
- const result = parseFloatSafe(" -1.0 ");
541
- strictEqual(result, -1);
542
- });
543
- });
544
-
545
- describe("invalid input", () => {
546
- test("empty string", () => {
547
- const result = parseFloatSafe("");
548
- strictEqual(result, undefined);
549
- });
550
-
551
- test(".", () => {
552
- const result = parseFloatSafe(".");
553
- strictEqual(result, undefined);
554
- });
555
-
556
- test("1.", () => {
557
- const result = parseFloatSafe("1.");
558
- strictEqual(result, undefined);
559
- });
560
-
561
- test("-", () => {
562
- const result = parseFloatSafe("-");
563
- strictEqual(result, undefined);
564
- });
565
-
566
- test("1-", () => {
567
- const result = parseFloatSafe("1-");
568
- strictEqual(result, undefined);
569
- });
570
-
571
- test("- 1", () => {
572
- const result = parseFloatSafe("- 1");
573
- strictEqual(result, undefined);
574
- });
575
-
576
- test("--", () => {
577
- const result = parseFloatSafe("--");
578
- strictEqual(result, undefined);
579
- });
580
-
581
- test("--1", () => {
582
- const result = parseFloatSafe("--1");
583
- strictEqual(result, undefined);
584
- });
585
-
586
- test("1--", () => {
587
- const result = parseFloatSafe("--1");
588
- strictEqual(result, undefined);
589
- });
590
-
591
- test("-- 1", () => {
592
- const result = parseFloatSafe("-- 1");
593
- strictEqual(result, undefined);
594
- });
595
- });
596
-
597
- describe("normal integers", () => {
598
- test("1", () => {
599
- const result = parseFloatSafe("1");
600
- strictEqual(result, 1);
601
- });
602
-
603
- test("-1", () => {
604
- const result = parseFloatSafe("-1");
605
- strictEqual(result, -1);
606
- });
607
-
608
- test("10", () => {
609
- const result = parseFloatSafe("10");
610
- strictEqual(result, 10);
611
- });
612
-
613
- test("-10", () => {
614
- const result = parseFloatSafe("-10");
615
- strictEqual(result, -10);
616
- });
617
-
618
- test("01", () => {
619
- const result = parseFloatSafe("01");
620
- strictEqual(result, 1);
621
- });
622
-
623
- test("-01", () => {
624
- const result = parseFloatSafe("-01");
625
- strictEqual(result, -1);
626
- });
627
- });
628
-
629
- describe("normal floats", () => {
630
- test(".1", () => {
631
- const result = parseFloatSafe(".1");
632
- strictEqual(result, 0.1);
633
- });
634
-
635
- test("1.0", () => {
636
- const result = parseFloatSafe("1.0");
637
- strictEqual(result, 1);
638
- });
639
-
640
- test("1.1", () => {
641
- const result = parseFloatSafe("1.1");
642
- strictEqual(result, 1.1);
643
- });
644
-
645
- test("0.1", () => {
646
- const result = parseFloatSafe("0.1");
647
- strictEqual(result, 0.1);
648
- });
649
-
650
- test("10.0", () => {
651
- const result = parseFloatSafe("10.0");
652
- strictEqual(result, 10);
653
- });
654
-
655
- test("10.1", () => {
656
- const result = parseFloatSafe("10.1");
657
- strictEqual(result, 10.1);
658
- });
659
-
660
- test("-10.0", () => {
661
- const result = parseFloatSafe("-10.0");
662
- strictEqual(result, -10);
663
- });
664
-
665
- test("-10.1", () => {
666
- const result = parseFloatSafe("-10.1");
667
- strictEqual(result, -10.1);
668
- });
669
-
670
- test("01.0", () => {
671
- const result = parseFloatSafe("01.0");
672
- strictEqual(result, 1);
673
- });
674
-
675
- test("-01.0", () => {
676
- const result = parseFloatSafe("-01.0");
677
- strictEqual(result, -1);
678
- });
679
- });
680
- });
681
-
682
- describe("parseIntSafe", () => {
683
- describe("non valid types", () => {
684
- test("undefined", () => {
685
- const result = parseIntSafe(undefined as unknown as string);
686
- strictEqual(result, undefined);
687
- });
688
-
689
- test("null", () => {
690
- // eslint-disable-next-line unicorn/no-null
691
- const result = parseIntSafe(null as unknown as string);
692
- strictEqual(result, undefined);
693
- });
694
-
695
- test("bigint", () => {
696
- const result = parseIntSafe(1n as unknown as string);
697
- strictEqual(result, undefined);
698
- });
699
-
700
- test("false", () => {
701
- const result = parseIntSafe(false as unknown as string);
702
- strictEqual(result, undefined);
703
- });
704
-
705
- test("true", () => {
706
- const result = parseIntSafe(true as unknown as string);
707
- strictEqual(result, undefined);
708
- });
709
-
710
- test("function", () => {
711
- // eslint-disable-next-line @typescript-eslint/no-empty-function
712
- const result = parseIntSafe((() => {}) as unknown as string);
713
- strictEqual(result, undefined);
714
- });
715
-
716
- test("number", () => {
717
- const result = parseIntSafe(1 as unknown as string);
718
- strictEqual(result, undefined);
719
- });
720
-
721
- test("object", () => {
722
- const result = parseIntSafe({} as string);
723
- strictEqual(result, undefined);
724
- });
725
-
726
- test("symbol", () => {
727
- const result = parseIntSafe(Symbol("1") as unknown as string);
728
- strictEqual(result, undefined);
729
- });
730
- });
731
-
732
- describe("spaces", () => {
733
- test("space", () => {
734
- const result = parseIntSafe(" ");
735
- strictEqual(result, undefined);
736
- });
737
-
738
- test("space + 1", () => {
739
- const result = parseIntSafe(" 1");
740
- strictEqual(result, 1);
741
- });
742
-
743
- test("1 + space", () => {
744
- const result = parseIntSafe("1 ");
745
- strictEqual(result, 1);
746
- });
747
-
748
- test("space + 1 + space", () => {
749
- const result = parseIntSafe(" 1 ");
750
- strictEqual(result, 1);
751
- });
752
-
753
- test("space + -1", () => {
754
- const result = parseIntSafe(" -1");
755
- strictEqual(result, -1);
756
- });
757
-
758
- test("-1 + space", () => {
759
- const result = parseIntSafe("-1 ");
760
- strictEqual(result, -1);
761
- });
762
-
763
- test("space + -1 + space", () => {
764
- const result = parseIntSafe(" -1 ");
765
- strictEqual(result, -1);
766
- });
767
- });
768
-
769
- describe("tabs", () => {
770
- test("tab", () => {
771
- const result = parseIntSafe(" ");
772
- strictEqual(result, undefined);
773
- });
774
-
775
- test("tab + 1", () => {
776
- const result = parseIntSafe(" 1");
777
- strictEqual(result, 1);
778
- });
779
-
780
- test("1 + tab", () => {
781
- const result = parseIntSafe("1 ");
782
- strictEqual(result, 1);
783
- });
784
-
785
- test("tab + 1 + tab", () => {
786
- const result = parseIntSafe(" 1 ");
787
- strictEqual(result, 1);
788
- });
789
-
790
- test("tab + -1", () => {
791
- const result = parseIntSafe(" -1");
792
- strictEqual(result, -1);
793
- });
794
-
795
- test("-1 + tab", () => {
796
- const result = parseIntSafe("-1 ");
797
- strictEqual(result, -1);
798
- });
799
-
800
- test("tab + -1 + tab", () => {
801
- const result = parseIntSafe(" -1 ");
802
- strictEqual(result, -1);
803
- });
804
- });
805
-
806
- describe("invalid input", () => {
807
- test("empty string", () => {
808
- const result = parseIntSafe("");
809
- strictEqual(result, undefined);
810
- });
811
-
812
- test(".", () => {
813
- const result = parseIntSafe(".");
814
- strictEqual(result, undefined);
815
- });
816
-
817
- test(".1", () => {
818
- const result = parseIntSafe(".1");
819
- strictEqual(result, undefined);
820
- });
821
-
822
- test("1.", () => {
823
- const result = parseIntSafe("1.");
824
- strictEqual(result, undefined);
825
- });
826
-
827
- test("1.0", () => {
828
- const result = parseIntSafe("1.0");
829
- strictEqual(result, undefined);
830
- });
831
-
832
- test("0.1", () => {
833
- const result = parseIntSafe("0.1");
834
- strictEqual(result, undefined);
835
- });
836
-
837
- test("-", () => {
838
- const result = parseIntSafe("-");
839
- strictEqual(result, undefined);
840
- });
841
-
842
- test("1-", () => {
843
- const result = parseIntSafe("1-");
844
- strictEqual(result, undefined);
845
- });
846
-
847
- test("- 1", () => {
848
- const result = parseIntSafe("- 1");
849
- strictEqual(result, undefined);
850
- });
851
-
852
- test("--", () => {
853
- const result = parseIntSafe("--");
854
- strictEqual(result, undefined);
855
- });
856
-
857
- test("--1", () => {
858
- const result = parseIntSafe("--1");
859
- strictEqual(result, undefined);
860
- });
861
-
862
- test("1--", () => {
863
- const result = parseIntSafe("--1");
864
- strictEqual(result, undefined);
865
- });
866
-
867
- test("-- 1", () => {
868
- const result = parseIntSafe("-- 1");
869
- strictEqual(result, undefined);
870
- });
871
- });
872
-
873
- describe("normal", () => {
874
- test("1", () => {
875
- const result = parseIntSafe("1");
876
- strictEqual(result, 1);
877
- });
878
-
879
- test("-1", () => {
880
- const result = parseIntSafe("-1");
881
- strictEqual(result, -1);
882
- });
883
-
884
- test("10", () => {
885
- const result = parseIntSafe("10");
886
- strictEqual(result, 10);
887
- });
888
-
889
- test("-10", () => {
890
- const result = parseIntSafe("-10");
891
- strictEqual(result, -10);
892
- });
893
-
894
- test("01", () => {
895
- const result = parseIntSafe("01");
896
- strictEqual(result, 1);
897
- });
898
-
899
- test("-01", () => {
900
- const result = parseIntSafe("-01");
901
- strictEqual(result, -1);
902
- });
903
- });
904
- });