ts-data-forge 2.0.2 → 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/entry-point.d.mts +27 -0
- package/dist/entry-point.d.mts.map +1 -0
- package/dist/entry-point.mjs +62 -0
- package/dist/entry-point.mjs.map +1 -0
- package/dist/iterator/range.d.mts +5 -2
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +16 -3
- package/dist/iterator/range.mjs.map +1 -1
- package/package.json +11 -11
- package/src/entry-point.mts +43 -0
- package/src/iterator/range.mts +40 -15
- package/src/iterator/range.test.mts +13 -0
- package/dist/globals.d.mts +0 -39
- package/src/globals.d.mts +0 -39
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import 'ts-type-forge';
|
|
2
|
+
export * from './index.mjs';
|
|
3
|
+
declare global {
|
|
4
|
+
type SmallPositiveInt = WithSmallInt<PositiveInt>;
|
|
5
|
+
/**
|
|
6
|
+
* Represents the type of keys that can be used in a standard JavaScript Map.
|
|
7
|
+
*/
|
|
8
|
+
type MapSetKeyType = Primitive;
|
|
9
|
+
namespace SizeType {
|
|
10
|
+
type Arr = Uint32;
|
|
11
|
+
type TypedArray = SafeUint;
|
|
12
|
+
type Str = SafeUint;
|
|
13
|
+
type ArrSearchResult = Arr | -1;
|
|
14
|
+
type TypedArraySearchResult = TypedArray | -1;
|
|
15
|
+
type StrSearchResult = Str | -1;
|
|
16
|
+
type ArgArr = WithSmallInt<Arr>;
|
|
17
|
+
type ArgTypedArray = WithSmallInt<TypedArray>;
|
|
18
|
+
type ArgStr = WithSmallInt<Str>;
|
|
19
|
+
type ArgArrWithNegative = WithSmallInt<NormalizeBrandUnion<NegativeInt32 | Arr>>;
|
|
20
|
+
type ArgTypedArrayWithNegative = WithSmallInt<SafeInt>;
|
|
21
|
+
type ArgStrWithNegative = WithSmallInt<SafeInt>;
|
|
22
|
+
type ArgArrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Arr>>;
|
|
23
|
+
type ArgTypedArrayPositive = WithSmallInt<IntersectBrand<PositiveNumber, TypedArray>>;
|
|
24
|
+
type ArgStrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Str>>;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=entry-point.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,cAAc,aAAa,CAAC;AAE5B,OAAO,CAAC,MAAM,CAAC;IACb,KAAK,gBAAgB,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAElD;;OAEG;IACH,KAAK,aAAa,GAAG,SAAS,CAAC;IAO/B,UAAU,QAAQ,CAAC;QACjB,KAAK,GAAG,GAAG,MAAM,CAAC;QAClB,KAAK,UAAU,GAAG,QAAQ,CAAC;QAC3B,KAAK,GAAG,GAAG,QAAQ,CAAC;QAEpB,KAAK,eAAe,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;QAChC,KAAK,sBAAsB,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC;QAC9C,KAAK,eAAe,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;QAEhC,KAAK,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAChC,KAAK,aAAa,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QAC9C,KAAK,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAEhC,KAAK,kBAAkB,GAAG,YAAY,CACpC,mBAAmB,CAAC,aAAa,GAAG,GAAG,CAAC,CACzC,CAAC;QACF,KAAK,yBAAyB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACvD,KAAK,kBAAkB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAEhD,KAAK,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC;QACxE,KAAK,qBAAqB,GAAG,YAAY,CACvC,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,CAC3C,CAAC;QACF,KAAK,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC;KACzE;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import 'ts-type-forge';
|
|
2
|
+
export { Arr } from './array/array-utils.mjs';
|
|
3
|
+
export { IMapMapped } from './collections/imap-mapped.mjs';
|
|
4
|
+
export { IMap } from './collections/imap.mjs';
|
|
5
|
+
export { ISetMapped } from './collections/iset-mapped.mjs';
|
|
6
|
+
export { ISet } from './collections/iset.mjs';
|
|
7
|
+
export { createQueue } from './collections/queue.mjs';
|
|
8
|
+
export { createStack } from './collections/stack.mjs';
|
|
9
|
+
export { expectType } from './expect-type.mjs';
|
|
10
|
+
export { match } from './functional/match.mjs';
|
|
11
|
+
export { Optional } from './functional/optional.mjs';
|
|
12
|
+
export { pipe } from './functional/pipe.mjs';
|
|
13
|
+
export { Result } from './functional/result.mjs';
|
|
14
|
+
export { hasKey } from './guard/has-key.mjs';
|
|
15
|
+
export { isNonEmptyString } from './guard/is-non-empty-string.mjs';
|
|
16
|
+
export { isNonNullObject } from './guard/is-non-null-object.mjs';
|
|
17
|
+
export { isPrimitive } from './guard/is-primitive.mjs';
|
|
18
|
+
export { isRecord } from './guard/is-record.mjs';
|
|
19
|
+
export { isBigint, isBoolean, isNonNullish, isNotBigint, isNotBoolean, isNotNull, isNotNumber, isNotString, isNotSymbol, isNotUndefined, isNull, isNullish, isNumber, isString, isSymbol, isUndefined } from './guard/is-type.mjs';
|
|
20
|
+
export { keyIsIn } from './guard/key-is-in.mjs';
|
|
21
|
+
export { range } from './iterator/range.mjs';
|
|
22
|
+
export { Json } from './json/json.mjs';
|
|
23
|
+
export { FiniteNumber, asFiniteNumber, isFiniteNumber } from './number/branded-types/finite-number.mjs';
|
|
24
|
+
export { Int, asInt, isInt } from './number/branded-types/int.mjs';
|
|
25
|
+
export { Int16, asInt16, isInt16 } from './number/branded-types/int16.mjs';
|
|
26
|
+
export { Int32, asInt32, isInt32 } from './number/branded-types/int32.mjs';
|
|
27
|
+
export { NonNegativeFiniteNumber, asNonNegativeFiniteNumber, isNonNegativeFiniteNumber } from './number/branded-types/non-negative-finite-number.mjs';
|
|
28
|
+
export { NonNegativeInt16, asNonNegativeInt16, isNonNegativeInt16 } from './number/branded-types/non-negative-int16.mjs';
|
|
29
|
+
export { NonNegativeInt32, asNonNegativeInt32, isNonNegativeInt32 } from './number/branded-types/non-negative-int32.mjs';
|
|
30
|
+
export { NonZeroFiniteNumber, asNonZeroFiniteNumber, isNonZeroFiniteNumber } from './number/branded-types/non-zero-finite-number.mjs';
|
|
31
|
+
export { NonZeroInt, asNonZeroInt, isNonZeroInt } from './number/branded-types/non-zero-int.mjs';
|
|
32
|
+
export { NonZeroInt16, asNonZeroInt16, isNonZeroInt16 } from './number/branded-types/non-zero-int16.mjs';
|
|
33
|
+
export { NonZeroInt32, asNonZeroInt32, isNonZeroInt32 } from './number/branded-types/non-zero-int32.mjs';
|
|
34
|
+
export { NonZeroSafeInt, asNonZeroSafeInt, isNonZeroSafeInt } from './number/branded-types/non-zero-safe-int.mjs';
|
|
35
|
+
export { NonZeroUint16, asNonZeroUint16, isNonZeroUint16 } from './number/branded-types/non-zero-uint16.mjs';
|
|
36
|
+
export { NonZeroUint32, asNonZeroUint32, isNonZeroUint32 } from './number/branded-types/non-zero-uint32.mjs';
|
|
37
|
+
export { PositiveFiniteNumber, asPositiveFiniteNumber, isPositiveFiniteNumber } from './number/branded-types/positive-finite-number.mjs';
|
|
38
|
+
export { PositiveInt, asPositiveInt, isPositiveInt } from './number/branded-types/positive-int.mjs';
|
|
39
|
+
export { PositiveInt16, asPositiveInt16, isPositiveInt16 } from './number/branded-types/positive-int16.mjs';
|
|
40
|
+
export { PositiveInt32, asPositiveInt32, isPositiveInt32 } from './number/branded-types/positive-int32.mjs';
|
|
41
|
+
export { PositiveSafeInt, asPositiveSafeInt, isPositiveSafeInt } from './number/branded-types/positive-safe-int.mjs';
|
|
42
|
+
export { PositiveUint16, asPositiveUint16, isPositiveUint16 } from './number/branded-types/positive-uint16.mjs';
|
|
43
|
+
export { PositiveUint32, asPositiveUint32, isPositiveUint32 } from './number/branded-types/positive-uint32.mjs';
|
|
44
|
+
export { SafeInt, asSafeInt, isSafeInt } from './number/branded-types/safe-int.mjs';
|
|
45
|
+
export { SafeUint, asSafeUint, isSafeUint } from './number/branded-types/safe-uint.mjs';
|
|
46
|
+
export { Uint, asUint, isUint } from './number/branded-types/uint.mjs';
|
|
47
|
+
export { Uint16, asUint16, isUint16 } from './number/branded-types/uint16.mjs';
|
|
48
|
+
export { Uint32, asUint32, isUint32 } from './number/branded-types/uint32.mjs';
|
|
49
|
+
export { Int8, asInt8, isInt8 } from './number/enum/int8.mjs';
|
|
50
|
+
export { Uint8, asUint8, isUint8 } from './number/enum/uint8.mjs';
|
|
51
|
+
export { Num } from './number/num.mjs';
|
|
52
|
+
export { TsDataForgeInternals } from './number/refined-number-utils.mjs';
|
|
53
|
+
export { Obj } from './object/object.mjs';
|
|
54
|
+
export { castDeepMutable, castMutable } from './others/cast-mutable.mjs';
|
|
55
|
+
export { castDeepReadonly, castReadonly } from './others/cast-readonly.mjs';
|
|
56
|
+
export { ifThen } from './others/if-then.mjs';
|
|
57
|
+
export { mapNullable } from './others/map-nullable.mjs';
|
|
58
|
+
export { memoizeFunction } from './others/memoize-function.mjs';
|
|
59
|
+
export { tp } from './others/tuple.mjs';
|
|
60
|
+
export { unknownToString } from './others/unknown-to-string.mjs';
|
|
61
|
+
export { createPromise } from './promise/promise.mjs';
|
|
62
|
+
//# sourceMappingURL=entry-point.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -88,6 +88,9 @@
|
|
|
88
88
|
* }
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
export declare function range(
|
|
92
|
-
export declare function range(start:
|
|
91
|
+
export declare function range(end: WithSmallInt<SafeUint, MaxInt>): Generator<SafeUint, void, unknown>;
|
|
92
|
+
export declare function range(start: WithSmallInt<SafeUint, MaxInt>, end: WithSmallInt<SafeUint, MaxInt>, step?: WithSmallInt<PositiveSafeInt, MaxInt>): Generator<SafeUint, void, unknown>;
|
|
93
|
+
export declare function range(start: WithSmallInt<SafeInt, MaxInt>, end: WithSmallInt<SafeInt, MaxInt>, step?: WithSmallInt<NonZeroSafeInt, MaxInt>): Generator<SafeInt, void, unknown>;
|
|
94
|
+
type MaxInt = 512;
|
|
95
|
+
export {};
|
|
93
96
|
//# sourceMappingURL=range.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.mts","sourceRoot":"","sources":["../../src/iterator/range.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"range.d.mts","sourceRoot":"","sources":["../../src/iterator/range.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,wBAAgB,KAAK,CACnB,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,GAClC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAEtC,wBAAgB,KAAK,CACnB,KAAK,EAAE,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,EACrC,GAAG,EAAE,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,EAEnC,IAAI,CAAC,EAAE,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,GAC3C,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAEtC,wBAAgB,KAAK,CACnB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,EACpC,GAAG,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,EAClC,IAAI,CAAC,EAAE,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,GAC1C,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAkCrC,KAAK,MAAM,GAAG,GAAG,CAAC"}
|
package/dist/iterator/range.mjs
CHANGED
|
@@ -29,9 +29,22 @@ import '../number/enum/uint8.mjs';
|
|
|
29
29
|
import '../number/num.mjs';
|
|
30
30
|
import '../number/refined-number-utils.mjs';
|
|
31
31
|
|
|
32
|
-
function* range(
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
function* range(...args) {
|
|
33
|
+
switch (args.length) {
|
|
34
|
+
case 1: {
|
|
35
|
+
const [end] = args;
|
|
36
|
+
for (const i of range(0, end, 1)) {
|
|
37
|
+
yield i;
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 2:
|
|
42
|
+
case 3: {
|
|
43
|
+
const [start, end, step = 1] = args;
|
|
44
|
+
for (let mut_i = asSafeInt(start); step > 0 ? mut_i < end : mut_i > end; mut_i = SafeInt.add(mut_i, asSafeInt(step))) {
|
|
45
|
+
yield mut_i;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.mjs","sources":["../../src/iterator/range.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"range.mjs","sources":["../../src/iterator/range.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA6GiB,KAAK,CACpB,GAAG,IAME,EAAA;AAEL,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI;AAClB,YAAA,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;AAChC,gBAAA,MAAM,CAAC;YACT;YACA;QACF;AAEA,QAAA,KAAK,CAAC;QACN,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI;AACnC,YAAA,KACE,IAAI,KAAK,GAAY,SAAS,CAAC,KAAK,CAAC,EACrC,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,EACpC,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,EAC3C;AACA,gBAAA,MAAM,KAAK;YACb;QACF;;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-data-forge",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
23
|
"import": {
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"default": "./dist/
|
|
24
|
+
"types": "./dist/entry-point.d.mts",
|
|
25
|
+
"default": "./dist/entry-point.mjs"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
"module": "./dist/
|
|
30
|
-
"types": "./dist/
|
|
29
|
+
"module": "./dist/entry-point.js",
|
|
30
|
+
"types": "./dist/entry-point.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"src",
|
|
33
33
|
"dist",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@emotion/react": "^11.14.0",
|
|
71
71
|
"@emotion/styled": "^11.14.1",
|
|
72
|
-
"@eslint/js": "^9.
|
|
72
|
+
"@eslint/js": "^9.31.0",
|
|
73
73
|
"@mui/material": "^7.2.0",
|
|
74
74
|
"@rollup/plugin-replace": "^6.0.2",
|
|
75
75
|
"@rollup/plugin-strip": "^3.0.4",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@semantic-release/github": "^11.0.3",
|
|
82
82
|
"@semantic-release/npm": "^12.0.2",
|
|
83
83
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
84
|
-
"@types/node": "^20.19.
|
|
84
|
+
"@types/node": "^20.19.7",
|
|
85
85
|
"@vitest/coverage-v8": "^3.2.4",
|
|
86
86
|
"@vitest/ui": "^3.2.4",
|
|
87
87
|
"conventional-changelog-conventionalcommits": "^9.0.0",
|
|
@@ -93,14 +93,14 @@
|
|
|
93
93
|
"prettier": "^3.5.3",
|
|
94
94
|
"prettier-plugin-organize-imports": "^4.1.0",
|
|
95
95
|
"prettier-plugin-packagejson": "^2.5.18",
|
|
96
|
-
"rollup": "^4.
|
|
97
|
-
"semantic-release": "^24.2.
|
|
98
|
-
"ts-repo-utils": "^3.
|
|
96
|
+
"rollup": "^4.45.0",
|
|
97
|
+
"semantic-release": "^24.2.7",
|
|
98
|
+
"ts-repo-utils": "^3.1.1",
|
|
99
99
|
"tsx": "^4.20.3",
|
|
100
100
|
"typedoc": "^0.28.7",
|
|
101
101
|
"typedoc-plugin-markdown": "^4.7.0",
|
|
102
102
|
"typescript": "^5.8.3",
|
|
103
|
-
"typescript-eslint": "^8.
|
|
103
|
+
"typescript-eslint": "^8.36.0",
|
|
104
104
|
"vitest": "^3.2.4"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import 'ts-type-forge';
|
|
2
|
+
|
|
3
|
+
export * from './index.mjs';
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
type SmallPositiveInt = WithSmallInt<PositiveInt>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the type of keys that can be used in a standard JavaScript Map.
|
|
10
|
+
*/
|
|
11
|
+
type MapSetKeyType = Primitive;
|
|
12
|
+
|
|
13
|
+
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
|
|
14
|
+
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/length
|
|
15
|
+
// Max array length : 2^32 - 1
|
|
16
|
+
// Max string length : 2^53 - 1
|
|
17
|
+
|
|
18
|
+
namespace SizeType {
|
|
19
|
+
type Arr = Uint32;
|
|
20
|
+
type TypedArray = SafeUint;
|
|
21
|
+
type Str = SafeUint;
|
|
22
|
+
|
|
23
|
+
type ArrSearchResult = Arr | -1;
|
|
24
|
+
type TypedArraySearchResult = TypedArray | -1;
|
|
25
|
+
type StrSearchResult = Str | -1;
|
|
26
|
+
|
|
27
|
+
type ArgArr = WithSmallInt<Arr>;
|
|
28
|
+
type ArgTypedArray = WithSmallInt<TypedArray>;
|
|
29
|
+
type ArgStr = WithSmallInt<Str>;
|
|
30
|
+
|
|
31
|
+
type ArgArrWithNegative = WithSmallInt<
|
|
32
|
+
NormalizeBrandUnion<NegativeInt32 | Arr>
|
|
33
|
+
>;
|
|
34
|
+
type ArgTypedArrayWithNegative = WithSmallInt<SafeInt>;
|
|
35
|
+
type ArgStrWithNegative = WithSmallInt<SafeInt>;
|
|
36
|
+
|
|
37
|
+
type ArgArrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Arr>>;
|
|
38
|
+
type ArgTypedArrayPositive = WithSmallInt<
|
|
39
|
+
IntersectBrand<PositiveNumber, TypedArray>
|
|
40
|
+
>;
|
|
41
|
+
type ArgStrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Str>>;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/iterator/range.mts
CHANGED
|
@@ -91,27 +91,52 @@ import { SafeInt, asSafeInt } from '../number/index.mjs';
|
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
93
93
|
export function range(
|
|
94
|
-
|
|
95
|
-
end: SafeUintWithSmallInt,
|
|
96
|
-
step?: PositiveSafeIntWithSmallInt,
|
|
94
|
+
end: WithSmallInt<SafeUint, MaxInt>,
|
|
97
95
|
): Generator<SafeUint, void, unknown>;
|
|
98
96
|
|
|
99
97
|
export function range(
|
|
100
|
-
start:
|
|
101
|
-
end:
|
|
102
|
-
|
|
98
|
+
start: WithSmallInt<SafeUint, MaxInt>,
|
|
99
|
+
end: WithSmallInt<SafeUint, MaxInt>,
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
|
101
|
+
step?: WithSmallInt<PositiveSafeInt, MaxInt>,
|
|
102
|
+
): Generator<SafeUint, void, unknown>;
|
|
103
|
+
|
|
104
|
+
export function range(
|
|
105
|
+
start: WithSmallInt<SafeInt, MaxInt>,
|
|
106
|
+
end: WithSmallInt<SafeInt, MaxInt>,
|
|
107
|
+
step?: WithSmallInt<NonZeroSafeInt, MaxInt>,
|
|
103
108
|
): Generator<SafeInt, void, unknown>;
|
|
104
109
|
|
|
105
110
|
export function* range(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
...args:
|
|
112
|
+
| readonly [end: WithSmallInt<SafeInt, MaxInt>]
|
|
113
|
+
| readonly [
|
|
114
|
+
start: WithSmallInt<SafeInt, MaxInt>,
|
|
115
|
+
end: WithSmallInt<SafeInt, MaxInt>,
|
|
116
|
+
step?: WithSmallInt<NonZeroSafeInt, MaxInt>,
|
|
117
|
+
]
|
|
109
118
|
): Generator<SafeInt, void, unknown> {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
switch (args.length) {
|
|
120
|
+
case 1: {
|
|
121
|
+
const [end] = args;
|
|
122
|
+
for (const i of range(0, end, 1)) {
|
|
123
|
+
yield i;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case 2:
|
|
129
|
+
case 3: {
|
|
130
|
+
const [start, end, step = 1] = args;
|
|
131
|
+
for (
|
|
132
|
+
let mut_i: SafeInt = asSafeInt(start);
|
|
133
|
+
step > 0 ? mut_i < end : mut_i > end;
|
|
134
|
+
mut_i = SafeInt.add(mut_i, asSafeInt(step))
|
|
135
|
+
) {
|
|
136
|
+
yield mut_i;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
116
139
|
}
|
|
117
140
|
}
|
|
141
|
+
|
|
142
|
+
type MaxInt = 512;
|
|
@@ -7,6 +7,19 @@ describe('range', () => {
|
|
|
7
7
|
]);
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
+
test('range(10)', () => {
|
|
11
|
+
expect(Array.from(range(10))).toStrictEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('range(0)', () => {
|
|
15
|
+
expect(Array.from(range(0))).toStrictEqual([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('range(0)', () => {
|
|
19
|
+
// @ts-expect-error negative end is not allowed
|
|
20
|
+
expect(Array.from(range(-1))).toStrictEqual([]);
|
|
21
|
+
});
|
|
22
|
+
|
|
10
23
|
test('range(10, 0, -1)', () => {
|
|
11
24
|
expect(Array.from(range(10, 0, -1))).toStrictEqual([
|
|
12
25
|
10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
|
package/dist/globals.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/// <reference types="ts-type-forge" />
|
|
2
|
-
|
|
3
|
-
type SmallPositiveInt = WithSmallInt<PositiveInt>;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents the type of keys that can be used in a standard JavaScript Map.
|
|
7
|
-
*/
|
|
8
|
-
type MapSetKeyType = Primitive;
|
|
9
|
-
|
|
10
|
-
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
|
|
11
|
-
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/length
|
|
12
|
-
// Max array length : 2^32 - 1
|
|
13
|
-
// Max string length : 2^53 - 1
|
|
14
|
-
|
|
15
|
-
declare namespace SizeType {
|
|
16
|
-
type Arr = Uint32;
|
|
17
|
-
type TypedArray = SafeUint;
|
|
18
|
-
type Str = SafeUint;
|
|
19
|
-
|
|
20
|
-
type ArrSearchResult = Arr | -1;
|
|
21
|
-
type TypedArraySearchResult = TypedArray | -1;
|
|
22
|
-
type StrSearchResult = Str | -1;
|
|
23
|
-
|
|
24
|
-
type ArgArr = WithSmallInt<Arr>;
|
|
25
|
-
type ArgTypedArray = WithSmallInt<TypedArray>;
|
|
26
|
-
type ArgStr = WithSmallInt<Str>;
|
|
27
|
-
|
|
28
|
-
type ArgArrWithNegative = WithSmallInt<
|
|
29
|
-
NormalizeBrandUnion<NegativeInt32 | Arr>
|
|
30
|
-
>;
|
|
31
|
-
type ArgTypedArrayWithNegative = WithSmallInt<SafeInt>;
|
|
32
|
-
type ArgStrWithNegative = WithSmallInt<SafeInt>;
|
|
33
|
-
|
|
34
|
-
type ArgArrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Arr>>;
|
|
35
|
-
type ArgTypedArrayPositive = WithSmallInt<
|
|
36
|
-
IntersectBrand<PositiveNumber, TypedArray>
|
|
37
|
-
>;
|
|
38
|
-
type ArgStrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Str>>;
|
|
39
|
-
}
|
package/src/globals.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/// <reference types="ts-type-forge" />
|
|
2
|
-
|
|
3
|
-
type SmallPositiveInt = WithSmallInt<PositiveInt>;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents the type of keys that can be used in a standard JavaScript Map.
|
|
7
|
-
*/
|
|
8
|
-
type MapSetKeyType = Primitive;
|
|
9
|
-
|
|
10
|
-
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
|
|
11
|
-
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/length
|
|
12
|
-
// Max array length : 2^32 - 1
|
|
13
|
-
// Max string length : 2^53 - 1
|
|
14
|
-
|
|
15
|
-
declare namespace SizeType {
|
|
16
|
-
type Arr = Uint32;
|
|
17
|
-
type TypedArray = SafeUint;
|
|
18
|
-
type Str = SafeUint;
|
|
19
|
-
|
|
20
|
-
type ArrSearchResult = Arr | -1;
|
|
21
|
-
type TypedArraySearchResult = TypedArray | -1;
|
|
22
|
-
type StrSearchResult = Str | -1;
|
|
23
|
-
|
|
24
|
-
type ArgArr = WithSmallInt<Arr>;
|
|
25
|
-
type ArgTypedArray = WithSmallInt<TypedArray>;
|
|
26
|
-
type ArgStr = WithSmallInt<Str>;
|
|
27
|
-
|
|
28
|
-
type ArgArrWithNegative = WithSmallInt<
|
|
29
|
-
NormalizeBrandUnion<NegativeInt32 | Arr>
|
|
30
|
-
>;
|
|
31
|
-
type ArgTypedArrayWithNegative = WithSmallInt<SafeInt>;
|
|
32
|
-
type ArgStrWithNegative = WithSmallInt<SafeInt>;
|
|
33
|
-
|
|
34
|
-
type ArgArrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Arr>>;
|
|
35
|
-
type ArgTypedArrayPositive = WithSmallInt<
|
|
36
|
-
IntersectBrand<PositiveNumber, TypedArray>
|
|
37
|
-
>;
|
|
38
|
-
type ArgStrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Str>>;
|
|
39
|
-
}
|