@joookiwi/type 1.0.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.
Files changed (53) hide show
  1. package/README.md +107 -0
  2. package/dist/boolean (false).d.ts +28 -0
  3. package/dist/boolean (false).d.ts.map +1 -0
  4. package/dist/boolean (true).d.ts +29 -0
  5. package/dist/boolean (true).d.ts.map +1 -0
  6. package/dist/boolean.d.ts +42 -0
  7. package/dist/boolean.d.ts.map +1 -0
  8. package/dist/empty.d.ts +51 -0
  9. package/dist/empty.d.ts.map +1 -0
  10. package/dist/index.d.ts +23 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/mixed.d.ts +594 -0
  13. package/dist/mixed.d.ts.map +1 -0
  14. package/dist/nullable.d.ts +769 -0
  15. package/dist/nullable.d.ts.map +1 -0
  16. package/dist/numeric (-1).d.ts +86 -0
  17. package/dist/numeric (-1).d.ts.map +1 -0
  18. package/dist/numeric (0).d.ts +88 -0
  19. package/dist/numeric (0).d.ts.map +1 -0
  20. package/dist/numeric (1).d.ts +88 -0
  21. package/dist/numeric (1).d.ts.map +1 -0
  22. package/dist/numeric (2).d.ts +84 -0
  23. package/dist/numeric (2).d.ts.map +1 -0
  24. package/dist/numeric (bigint).d.ts +41 -0
  25. package/dist/numeric (bigint).d.ts.map +1 -0
  26. package/dist/numeric (number).d.ts +42 -0
  27. package/dist/numeric (number).d.ts.map +1 -0
  28. package/dist/numeric.d.ts +51 -0
  29. package/dist/numeric.d.ts.map +1 -0
  30. package/dist/string (individual).d.ts +33 -0
  31. package/dist/string (individual).d.ts.map +1 -0
  32. package/dist/string.d.ts +43 -0
  33. package/dist/string.d.ts.map +1 -0
  34. package/dist/symbol.d.ts +38 -0
  35. package/dist/symbol.d.ts.map +1 -0
  36. package/package.json +65 -0
  37. package/src/boolean (false).ts +30 -0
  38. package/src/boolean (true).ts +31 -0
  39. package/src/boolean.ts +45 -0
  40. package/src/empty.ts +57 -0
  41. package/src/index.ts +23 -0
  42. package/src/mixed.ts +642 -0
  43. package/src/nullable.ts +837 -0
  44. package/src/numeric (-1).ts +88 -0
  45. package/src/numeric (0).ts +90 -0
  46. package/src/numeric (1).ts +90 -0
  47. package/src/numeric (2).ts +86 -0
  48. package/src/numeric (bigint).ts +44 -0
  49. package/src/numeric (number).ts +45 -0
  50. package/src/numeric.ts +55 -0
  51. package/src/string (individual).ts +35 -0
  52. package/src/string.ts +59 -0
  53. package/src/symbol.ts +40 -0
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Types (javascript version)
2
+ [![downloads](https://img.shields.io/npm/dt/@joookiwi/type.svg)](https://npm-stat.com/charts.html?package=@joookiwi/type)
3
+
4
+ ## Table of content
5
+ * [Installation](#installation)
6
+ * [Usage](#usage)
7
+ * [Chart](#chart)
8
+ * [Combination](#combination)
9
+ * [Contribution](#contribution)
10
+
11
+ ## Installation
12
+ ```
13
+ npm install @joookiwi/type
14
+ npm i @joookiwi/type
15
+
16
+ npm install --save @joookiwi/type
17
+ npm i -S @joookiwi/type
18
+
19
+ npm install --save-dev @joookiwi/type
20
+ npm i -D @joookiwi/type
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ The usage of the types is mostly for Typescript only.
26
+ But if it can be used in the Javascript documentation if needed.
27
+
28
+ It can be used directly without an argument or with a specialized argument.
29
+
30
+ ```typescript
31
+ import type {Nullable, NullOrString, UndefinedOrNumeric, Template} from "@joookiwi/type"
32
+
33
+ type Correct1 = Nullable<| 'a' | 2 | false> // = 'a' | 2 | false | null | undefined
34
+ type Incorrect1 = Nullable // The argument is required. (Just like NullOr or UndefinedOr)
35
+
36
+ type Correct2a = NullOrString // = string | null
37
+ type Correct2b = NullOrString<'a'> // = 'a'| null
38
+ type Incorrect2 = NullOrString<2> // It can only receive a string as an argument
39
+
40
+ type Correct3a = UndefinedOrNumeric // = number | bigint | undefined
41
+ type Correct3b = UndefinedOrNumeric<2> // = 2 | undefined
42
+ type Correct3c = UndefinedOrNumeric<2n> // = 2n | undefined
43
+ type Correct3c = UndefinedOrNumeric<| 2 | 2n> // = 2 | 2n | undefined
44
+ type Incorrect3 = UndefinedOrNumeric<boolean> // It can only receive a number or bigint as an argument
45
+
46
+ type Correct4a = Template // = `${string | boolean | number | bigint | null | undefined}`
47
+ type Correct4b = Template<'a'> // = 'a' (but is redontant, just 'a' should suffice)
48
+ type Correct4c = Template<2 | 3n> // = '2' | '3'
49
+ type Incorrect4 = Template<symbol> // A symbol cannot be in a string template
50
+ ```
51
+
52
+ ## Chart
53
+
54
+ To be coherent across the different types,
55
+ a simplified chart of the types has been made on their associable values.
56
+
57
+ The only exception is the **null** and **undefined**.
58
+
59
+ | | Nullable | String<br/>template | number<br/>value | bigint<br/>value | Object |
60
+ |----------------------------------------------------------------------------------------------------------|:--------:|:-------------------:|:----------------:|:----------------:|:------:|
61
+ | **null** | | ✓* | | | |
62
+ | **undefined** | | ✓* | | | |
63
+ | | | | | | |
64
+ | **string** | ✓ | | | | ✓ |
65
+ | | | | | | |
66
+ | **boolean** | ✓ | ✓ | | | ✓ |
67
+ | **true** | ✓ | ✓ | | | |
68
+ | **false** | ✓ | ✓ | | | |
69
+ | | | | | | |
70
+ | **numeric<br/>(number & bigint)** | ✓ | ✓ | | | ✓ |
71
+ | **number** | ✓ | ✓ | | | ✓ |
72
+ | **bigint** | ✓ | ✓ | | | ✓ |
73
+ | **-1** | ✓ | ✓ | ✓ | ✓ | |
74
+ | **0** | ✓ | ✓ | ✓ | ✓ | |
75
+ | **1** | ✓ | ✓ | ✓ | ✓ | |
76
+ | **2** | ✓ | ✓ | ✓ | ✓ | |
77
+ | | | | | | |
78
+ | **symbol** | ✓ | | | | ✓ |
79
+ | **known [js](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol) symbol** | ✓ | | | | |
80
+ | **known [ts](https://www.typescriptlang.org/docs/handbook/symbols.html) symbol** | ✓ | | | | |
81
+ <small>*: In a template, but not with a mix of the values</small>
82
+
83
+ ## Combination
84
+
85
+ Almost each value can be associated with each other,
86
+ but some defined values are not associated by design.
87
+ It is to give simplicity and not too many types.
88
+
89
+ | | nullable | string | boolean | true<br/>false | numeric | number | bigint | -1 0<br/>1 2 | symbol | known [js](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol) / [ts](https://www.typescriptlang.org/docs/handbook/symbols.html) symbol |
90
+ |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:--------:|:------:|:-------:|:--------------:|:-------:|:------:|:-------|:------------:|:------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
91
+ | **nullable** | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
92
+ | **string** | ✓ | | ✓ | | ✓ | ✓ | ✓ | | ✓ | |
93
+ | **boolean** | ✓ | ✓ | | | ✓ | ✓ | ✓ | | ✓ | |
94
+ | **true<br/>false** | ✓ | | | | | | | | | |
95
+ | **numeric** | ✓ | ✓ | ✓ | | | ✓ | ✓ | | ✓ | |
96
+ | **number** | ✓ | ✓ | ✓ | | ✓ | | ✓ | | ✓ | |
97
+ | **bigint** | ✓ | ✓ | ✓ | | ✓ | ✓ | | | ✓ | |
98
+ | **-1 0<br/>1 2** | ✓ | | | | | | | | | |
99
+ | **symbol** | ✓ | ✓ | ✓ | | ✓ | ✓ | ✓ | | | |
100
+ | **known [js](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol) / [ts](https://www.typescriptlang.org/docs/handbook/symbols.html) symbol** | ✓ | | | | | | | | | |
101
+
102
+ ## Contribution
103
+ You can contribute to great simple packages.
104
+ All with similar behaviour, accessibility and usage (like Java, Kotlin, C# and PHP).
105
+ It can be done 2 different ways:
106
+ - [GitHub sponsor](https://github.com/sponsors/joooKiwi) or
107
+ - [!["Buy me a Coffee"](https://img.buymeacoffee.com/button-api/?&button_colour=40DCA5&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00)](https://www.buymeacoffee.com/joookiwi)
@@ -0,0 +1,28 @@
1
+ /*******************************************************************************
2
+ Copyright (c) 2023-2024. Jonathan Bédard ~ JóôòKiwi
3
+
4
+ This project is free to use.
5
+ All the right is reserved to the author of this project.
6
+ ******************************************************************************/
7
+ /** A type-alias for the {@link Boolean} <b>false</b> as a primitive */
8
+ export type False<T extends false = false> = T;
9
+ /**
10
+ * A type-alias for the {@link Boolean} <b>false</b>
11
+ * in a {@link String} template
12
+ *
13
+ * @see False
14
+ * @see Template
15
+ * @see BooleanTemplate
16
+ */
17
+ export type FalseTemplate<T extends false = false> = `${T}`;
18
+ /**
19
+ * A type-alias for the {@link Boolean} <b>false</b>
20
+ * as a primitive or in a {@link String} template
21
+ *
22
+ * @see False
23
+ * @see Template
24
+ * @see FalseOrTemplateOrObject
25
+ * @see TemplateOrBoolean
26
+ */
27
+ export type TemplateOrFalse<T extends false = false> = T | `${T}`;
28
+ //# sourceMappingURL=boolean%20(false).d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean (false).d.ts","sourceRoot":"","sources":["../src/boolean (false).ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF,uEAAuE;AACvE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,IAAM,CAAC,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,IAAM,GAAG,CAAC,EAAE,CAAA;AAE7D;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,IAAQ,CAAC,GAAG,GAAG,CAAC,EAAE,CAAA"}
@@ -0,0 +1,29 @@
1
+ /*******************************************************************************
2
+ Copyright (c) 2023-2024. Jonathan Bédard ~ JóôòKiwi
3
+
4
+ This project is free to use.
5
+ All the right is reserved to the author of this project.
6
+ ******************************************************************************/
7
+ /** A type-alias for the {@link Boolean} <b>true</b> as a primitive */
8
+ export type True<T extends true = true> = T;
9
+ /**
10
+ * A type-alias for the {@link Boolean} <b>true</b>
11
+ * in a {@link String} template
12
+ *
13
+ * @see True
14
+ * @see Template
15
+ * @see BooleanTemplate
16
+ */
17
+ export type TrueTemplate<T extends true = true> = `${T}`;
18
+ /**
19
+ * A type-alias for the {@link Boolean} <b>true</b>
20
+ * in a {@link String} template
21
+ *
22
+ * @see True
23
+ * @see Template
24
+ * @see TrueTemplate
25
+ * @see TrueOrTemplateOrObject
26
+ * @see TemplateOrBoolean
27
+ */
28
+ export type TemplateOrTrue<T extends true = true> = T | `${T}`;
29
+ //# sourceMappingURL=boolean%20(true).d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean (true).d.ts","sourceRoot":"","sources":["../src/boolean (true).ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF,sEAAsE;AACtE,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,IAAM,CAAC,CAAA;AAE7C;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,IAAM,GAAG,CAAC,EAAE,CAAA;AAE1D;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,IAAQ,CAAC,GAAG,GAAG,CAAC,EAAE,CAAA"}
@@ -0,0 +1,42 @@
1
+ /*******************************************************************************
2
+ Copyright (c) 2023-2024. Jonathan Bédard ~ JóôòKiwi
3
+
4
+ This project is free to use.
5
+ All the right is reserved to the author of this project.
6
+ ******************************************************************************/
7
+ /**
8
+ * A type-alias for a {@link Boolean}
9
+ * in a {@link String} template
10
+ *
11
+ * @see Template
12
+ * @see TrueTemplate
13
+ * @see FalseTemplate
14
+ */
15
+ export type BooleanTemplate<T extends boolean = boolean> = `${T}`;
16
+ /**
17
+ * A type-alias for a {@link Boolean}
18
+ * as a primitive or in a {@link String} template
19
+ *
20
+ * @see Template
21
+ * @see TemplateOrTrue
22
+ * @see TemplateOrFalse
23
+ * @see TemplateOrBooleanOrObject
24
+ */
25
+ export type TemplateOrBoolean<T extends boolean = boolean> = T | `${T}`;
26
+ /**
27
+ * A type-alias for a {@link Boolean}
28
+ * as a primitive or an object
29
+ *
30
+ * @see TemplateOrBooleanOrObject
31
+ */
32
+ export type BooleanOrObject<T extends boolean = boolean> = T | Boolean;
33
+ /**
34
+ * A type-alias for a {@link Boolean}
35
+ * as a primitive, an object or in a {@link String} template
36
+ *
37
+ * @see Template
38
+ * @see BooleanOrObject
39
+ * @see TemplateOrBoolean
40
+ */
41
+ export type TemplateOrBooleanOrObject<T extends boolean = boolean> = T | `${T}` | Boolean;
42
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../src/boolean.ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAM,GAAG,CAAC,EAAE,CAAA;AAEnE;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAQ,CAAC,GAAG,GAAG,CAAC,EAAE,CAAA;AAE3E;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAQ,CAAC,GAAG,OAAO,CAAA;AAE1E;;;;;;;GAOG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAQ,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA"}
@@ -0,0 +1,51 @@
1
+ /*******************************************************************************
2
+ Copyright (c) 2023-2024. Jonathan Bédard ~ JóôòKiwi
3
+
4
+ This project is free to use.
5
+ All the right is reserved to the author of this project.
6
+ ******************************************************************************/
7
+ /** A type-alias for an empty {@link String} */
8
+ export type EmptyString = "";
9
+ /**
10
+ * A type-alias for an empty {@link ReadonlyArray Array}
11
+ *
12
+ * @see EmptyMutableArray
13
+ */
14
+ export type EmptyArray = readonly [];
15
+ /**
16
+ * A type-alias for an empty {@link Array MutableArray}
17
+ *
18
+ * @see EmptyArray
19
+ */
20
+ export type EmptyMutableArray = [];
21
+ /** A type-alias for an empty {@link ReadonlySet Set} */
22
+ export type EmptySet = ReadonlySet<never>;
23
+ /** A type-alias for an empty {@link WeakSet} */
24
+ export type EmptyWeakSet = Readonly<WeakSet<WeakKey>>;
25
+ /**
26
+ * A type-alias for an empty {@link ReadonlyMap Map}
27
+ *
28
+ * @see EmptyMutableMap
29
+ */
30
+ export type EmptyMap = ReadonlyMap<any, never>;
31
+ /**
32
+ * A type-alias for an empty {@link Map MutableMap}
33
+ *
34
+ * @see EmptyMap
35
+ */
36
+ export type EmptyMutableMap = Map<any, never>;
37
+ /** A type-alias for an empty {@link WeakMap} */
38
+ export type EmptyWeakMap = Readonly<WeakMap<WeakKey, never>>;
39
+ /**
40
+ * A type-alias for an empty {@link Object}
41
+ *
42
+ * @see EmptyMutableObject
43
+ */
44
+ export type EmptyObject = Readonly<{}>;
45
+ /**
46
+ * A type-alias for an empty {@link Object} (that can be modified)
47
+ *
48
+ * @see EmptyObject
49
+ */
50
+ export type EmptyMutableObject = {};
51
+ //# sourceMappingURL=empty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empty.d.ts","sourceRoot":"","sources":["../src/empty.ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF,+CAA+C;AAC/C,MAAM,MAAM,WAAW,GAAG,EAAE,CAAA;AAE5B;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,EAAE,CAAA;AACpC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAElC,wDAAwD;AACxD,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;AAEzC,gDAAgD;AAChD,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAErD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC9C;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAE7C,gDAAgD;AAChD,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AAE5D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;AACtC;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,EAAE,CAAA"}
@@ -0,0 +1,23 @@
1
+ /*******************************************************************************
2
+ Copyright (c) 2023-2024. Jonathan Bédard ~ JóôòKiwi
3
+
4
+ This project is free to use.
5
+ All the right is reserved to the author of this project.
6
+ ******************************************************************************/
7
+ export type * from "./boolean";
8
+ export type * from "./boolean (false)";
9
+ export type * from "./boolean (true)";
10
+ export type * from "./empty";
11
+ export type * from "./mixed";
12
+ export type * from "./nullable";
13
+ export type * from "./numeric";
14
+ export type * from "./numeric (0)";
15
+ export type * from "./numeric (1)";
16
+ export type * from "./numeric (2)";
17
+ export type * from "./numeric (-1)";
18
+ export type * from "./numeric (bigint)";
19
+ export type * from "./numeric (number)";
20
+ export type * from "./string";
21
+ export type * from "./string (individual)";
22
+ export type * from "./symbol";
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF,mBAAmB,WAAW,CAAA;AAC9B,mBAAmB,mBAAmB,CAAA;AACtC,mBAAmB,kBAAkB,CAAA;AACrC,mBAAmB,SAAS,CAAA;AAC5B,mBAAmB,SAAS,CAAA;AAC5B,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,WAAW,CAAA;AAC9B,mBAAmB,eAAe,CAAA;AAClC,mBAAmB,eAAe,CAAA;AAClC,mBAAmB,eAAe,CAAA;AAClC,mBAAmB,gBAAgB,CAAA;AACnC,mBAAmB,oBAAoB,CAAA;AACvC,mBAAmB,oBAAoB,CAAA;AACvC,mBAAmB,UAAU,CAAA;AAC7B,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,UAAU,CAAA"}