Skip to content

Commit 8194a83

Browse files
committed
docs, publish : change README.md file and re-publish
1 parent f9ebf15 commit 8194a83

File tree

5 files changed

+80
-3
lines changed

5 files changed

+80
-3
lines changed

README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,51 @@
33
Utility types and implementations based on JavaScript prototypes.
44
I plan to share the features that are officially available from 2.0.0.
55

6+
# TypedClass
67

7-
You can use the same method as the prototype of JavaScript.
8+
## prototype methods
9+
10+
```ts
11+
new TypedArray([1, 2, 3] as const).unshift(4 as const); // TypedArray<[4, 1, 2, 3]>
12+
```
13+
14+
```ts
15+
new TypedArray([1, 2, 3] as const).join(','); // TypedString<'1,2,3'>
16+
```
17+
18+
The return result of 'TypeClass' returns one of the instances of TypeClass again. Therefore, those who know the grammar of JavaScript can use it immediately.
19+
20+
## `refined` methods
21+
22+
```ts
23+
/**
24+
* error case
25+
*/
26+
new TypedArray<'1-3'>([1, 2, 3]).refine([1, 2, 3] as const).join('-');
27+
new TypedArray<'1-3'>([]).refine([1, 2, 3] as const).join('-');
28+
new TypedArray<'1-3'>().refine([1, 2, 3, 4] as const).join('-');
29+
new TypedArray<'1-3'>().refine([0, 1, 2, 3] as const).join('-');
30+
31+
/**
32+
* right case
33+
*/
34+
new TypedArray<'1-3'>().refine([2, 3] as const).join('-');
35+
```
36+
37+
`TypedArray`, `TypedNumber` has the `refine` method, which serves to further narrow down the generic type received as a factor. This helps reduce developer mistakes, but it should be careful because it cannot guarantee actual runtime behavior.
38+
39+
> In the future, improvements will be made at the type level.
40+
41+
## toPrimitive method
42+
43+
```ts
44+
new TypedString('abcdef').toPrimitive(); // 'abcdef'
45+
```
46+
47+
You can change it to the primitive type of JavaScript.
48+
49+
```ts
50+
const arr = [...new TypedArray([1, 2, 3, 4, 5] as const)]; // (1 | 2 | 3 | 4 | 5)[]
51+
```
52+
53+
`Iterable/Iterator` is supported.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kakasoo/proto-typescript",
3-
"version": "1.26.3",
3+
"version": "1.26.4",
44
"publishConfig": {
55
"access": "public"
66
},
@@ -21,7 +21,9 @@
2121
"keywords": [
2222
"type-safe",
2323
"prototype",
24-
"utility-types"
24+
"utility-types",
25+
"iterable/iterator",
26+
"ES6"
2527
],
2628
"author": "kakasoo",
2729
"license": "ISC",

src/classes/typed-boolean.class.ts

+24
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ export class TypedBoolean<T extends boolean = false> extends TypedObject<T> impl
2323
* @param map Defines the key name that you want to specify with true and false.
2424
* @returns
2525
*/
26+
refine<T extends string, F extends string>(map: { true: T; false: F }) {
27+
return function <Choice extends T | F | boolean>(data: Choice | boolean) {
28+
type RETURN_TYPE = Equal<Choice, T> extends true
29+
? true
30+
: Equal<Choice, F> extends true
31+
? false
32+
: Equal<Choice, true> extends true
33+
? T
34+
: Equal<Choice, false> extends true
35+
? F
36+
: never;
37+
38+
if (data === map.true) {
39+
return true as RETURN_TYPE;
40+
} else if (data === map.false) {
41+
return false as RETURN_TYPE;
42+
} else if (data === true) {
43+
return map.true as RETURN_TYPE;
44+
} else {
45+
return map.false as RETURN_TYPE;
46+
}
47+
};
48+
}
49+
2650
static refine<T extends string, F extends string>(map: { true: T; false: F }) {
2751
return function <Choice extends T | F | boolean>(data: Choice | boolean) {
2852
type RETURN_TYPE = Equal<Choice, T> extends true

src/interfaces/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
export * from './index-signature.interface';
12
export * from './is-typed.interface';
23
export * from './to-primitive.interface';
4+
export * from './to-typed-number.interface';

src/types/arithmetic.type.ts

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export namespace Math {
113113
: N
114114
: N;
115115

116+
/**
117+
* @todo Implement. Currently, It's not enough.
118+
*/
116119
export type Round<N extends number, TargetDigit extends number> = _Round<
117120
StringType.ToNumber<StringType.Take<`${N}`, NumberType.Add<TargetDigit, 3>>>,
118121
TargetDigit

0 commit comments

Comments
 (0)