@planet-matrix/mobius-model 0.3.0 → 0.4.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/CHANGELOG.md +7 -0
- package/README.md +4 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +18 -3
- package/package.json +3 -3
- package/scripts/build.ts +4 -4
- package/src/basic/README.md +143 -0
- package/src/basic/array.ts +872 -0
- package/src/basic/bigint.ts +114 -0
- package/src/basic/boolean.ts +180 -0
- package/src/basic/error.ts +51 -0
- package/src/basic/function.ts +453 -0
- package/src/basic/helper.ts +276 -0
- package/src/basic/index.ts +15 -0
- package/src/basic/is.ts +320 -0
- package/src/basic/number.ts +178 -0
- package/src/basic/object.ts +58 -0
- package/src/basic/promise.ts +464 -0
- package/src/basic/regexp.ts +7 -0
- package/src/basic/stream.ts +140 -0
- package/src/basic/string.ts +308 -0
- package/src/basic/symbol.ts +164 -0
- package/src/basic/temporal.ts +224 -0
- package/src/index.ts +2 -0
- package/src/type/README.md +330 -0
- package/src/type/array.ts +5 -0
- package/src/type/boolean.ts +471 -0
- package/src/type/class.ts +419 -0
- package/src/type/function.ts +1519 -0
- package/src/type/helper.ts +135 -0
- package/src/type/index.ts +14 -0
- package/src/type/intersection.ts +93 -0
- package/src/type/is.ts +247 -0
- package/src/type/iteration.ts +233 -0
- package/src/type/number.ts +732 -0
- package/src/type/object.ts +788 -0
- package/src/type/path.ts +73 -0
- package/src/type/string.ts +1004 -0
- package/src/type/tuple.ts +2424 -0
- package/src/type/union.ts +108 -0
- package/tests/unit/basic/array.spec.ts +290 -0
- package/tests/unit/basic/bigint.spec.ts +50 -0
- package/tests/unit/basic/boolean.spec.ts +74 -0
- package/tests/unit/basic/error.spec.ts +32 -0
- package/tests/unit/basic/function.spec.ts +175 -0
- package/tests/unit/basic/helper.spec.ts +118 -0
- package/tests/unit/basic/number.spec.ts +74 -0
- package/tests/unit/basic/object.spec.ts +15 -0
- package/tests/unit/basic/promise.spec.ts +232 -0
- package/tests/unit/basic/regexp.spec.ts +11 -0
- package/tests/unit/basic/stream.spec.ts +120 -0
- package/tests/unit/basic/string.spec.ts +74 -0
- package/tests/unit/basic/symbol.spec.ts +72 -0
- package/tests/unit/basic/temporal.spec.ts +78 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/reactor/index.d.ts +0 -3
- package/dist/reactor/index.d.ts.map +0 -1
- package/dist/reactor/reactor-core/flags.d.ts +0 -99
- package/dist/reactor/reactor-core/flags.d.ts.map +0 -1
- package/dist/reactor/reactor-core/index.d.ts +0 -4
- package/dist/reactor/reactor-core/index.d.ts.map +0 -1
- package/dist/reactor/reactor-core/primitive.d.ts +0 -276
- package/dist/reactor/reactor-core/primitive.d.ts.map +0 -1
- package/dist/reactor/reactor-core/reactive-system.d.ts +0 -241
- package/dist/reactor/reactor-core/reactive-system.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/branch.d.ts +0 -19
- package/dist/reactor/reactor-operators/branch.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/convert.d.ts +0 -30
- package/dist/reactor/reactor-operators/convert.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/create.d.ts +0 -26
- package/dist/reactor/reactor-operators/create.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/filter.d.ts +0 -269
- package/dist/reactor/reactor-operators/filter.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/index.d.ts +0 -8
- package/dist/reactor/reactor-operators/index.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/join.d.ts +0 -48
- package/dist/reactor/reactor-operators/join.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/map.d.ts +0 -165
- package/dist/reactor/reactor-operators/map.d.ts.map +0 -1
- package/dist/reactor/reactor-operators/utility.d.ts +0 -48
- package/dist/reactor/reactor-operators/utility.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planet-matrix/mobius-model",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Mobius model.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mobius",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@planet-matrix/mobius-mono": "0.
|
|
63
|
+
"@planet-matrix/mobius-mono": "0.7.0",
|
|
64
64
|
"@types/bun": "^1.3.8",
|
|
65
65
|
"oxlint": "^1.42.0",
|
|
66
|
-
"oxlint-tsgolint": "^0.
|
|
66
|
+
"oxlint-tsgolint": "^0.13.0",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
68
|
"@typescript/native-preview": "^7.0.0-dev.20260130.1",
|
|
69
69
|
"vite": "^7.3.1",
|
package/scripts/build.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { $, build } from "bun"
|
|
|
4
4
|
console.log("Cleaning and preparing ./dist directory...")
|
|
5
5
|
await $`rm -rf dist`
|
|
6
6
|
|
|
7
|
-
console.log("Building TypeScript declarations...")
|
|
8
|
-
await $`bun run tsgo --noEmit false`
|
|
7
|
+
// console.log("Building TypeScript declarations...")
|
|
8
|
+
// await $`bun run tsgo --noEmit false`
|
|
9
9
|
|
|
10
10
|
console.log("Building the library with Bun...")
|
|
11
11
|
const builtOutput = await build({
|
|
@@ -36,8 +36,8 @@ const builtOutput = await build({
|
|
|
36
36
|
outdir: "./dist",
|
|
37
37
|
packages: "bundle",
|
|
38
38
|
plugins: [],
|
|
39
|
-
publicPath: undefined,
|
|
40
|
-
root: undefined,
|
|
39
|
+
// publicPath: undefined,
|
|
40
|
+
// root: undefined,
|
|
41
41
|
sourcemap: "linked",
|
|
42
42
|
splitting: true,
|
|
43
43
|
target: "bun",
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Basic
|
|
2
|
+
|
|
3
|
+
Runtime utilities for JavaScript primitives and built-in objects. This module focuses on safe, predictable helpers and type guards that you can use in everyday code.
|
|
4
|
+
|
|
5
|
+
## For Users
|
|
6
|
+
|
|
7
|
+
This module provides runtime utilities organized by domain so you can quickly locate the right tool for a specific problem.
|
|
8
|
+
|
|
9
|
+
### 1. Domain Areas
|
|
10
|
+
|
|
11
|
+
1. Helper: Shared runtime helpers used across other domains.
|
|
12
|
+
2. Is: Predicates and type guards for runtime checks.
|
|
13
|
+
3. String: String manipulation, slicing, and formatting helpers.
|
|
14
|
+
4. Number: Numeric checks, parsing, and math-oriented helpers.
|
|
15
|
+
5. Boolean: Boolean helpers and predicates.
|
|
16
|
+
6. BigInt: BigInt checks and helpers.
|
|
17
|
+
7. Symbol: Symbol checks and helpers.
|
|
18
|
+
8. Array: Array construction, slicing, and transformation helpers.
|
|
19
|
+
9. Object: Object predicates and object utility helpers.
|
|
20
|
+
10. Function: Function predicates and invocation-related helpers.
|
|
21
|
+
11. Temporal: Temporal/date-time predicates and helpers.
|
|
22
|
+
12. Error: Error predicates and helpers.
|
|
23
|
+
13. RegExp: RegExp predicates and helpers.
|
|
24
|
+
14. Promise: Promise predicates and async-related helpers.
|
|
25
|
+
15. Stream: Stream predicates and stream-related helpers.
|
|
26
|
+
|
|
27
|
+
For a full list of exports, see the domain files (Is, String, Number, Temporal, Promise, Stream, etc.).
|
|
28
|
+
|
|
29
|
+
## For Contributors
|
|
30
|
+
|
|
31
|
+
This guide documents the conventions and best practices for implementing runtime utilities in this module. All implementations should follow these patterns for consistency and maintainability.
|
|
32
|
+
|
|
33
|
+
### 1. Documentation and Comments
|
|
34
|
+
|
|
35
|
+
#### 1.1 JSDoc Comment Format
|
|
36
|
+
|
|
37
|
+
Every exported function should have a JSDoc comment following this structure:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
/**
|
|
41
|
+
* Brief one-line description of what the function does.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```
|
|
45
|
+
* // Expect: true
|
|
46
|
+
* const example1 = isString("hello")
|
|
47
|
+
* // Expect: false
|
|
48
|
+
* const example2 = isString(123)
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://……}
|
|
52
|
+
*/
|
|
53
|
+
export const isString = (value: unknown): value is string => {
|
|
54
|
+
...
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Documentation Rules:**
|
|
59
|
+
- First line: Clear, concise description starting with a verb (Check, Get, Convert, etc.)
|
|
60
|
+
- Add a blank line after the description
|
|
61
|
+
- Use `@example` tag followed by triple backticks
|
|
62
|
+
- Include multiple cases showing different scenarios
|
|
63
|
+
- Use comment format: `// Expect: <result>`
|
|
64
|
+
- Assign example results to variables like `example1`, `example2` to keep examples readable
|
|
65
|
+
- Place `@see`(if has) after the `@example` block, separated by a blank line
|
|
66
|
+
- Prefer deterministic examples; avoid randomness or time-dependent output in docs
|
|
67
|
+
- If a function returns a non-scalar, show the expected shape or key properties
|
|
68
|
+
|
|
69
|
+
### 2. Runtime Implementation Patterns
|
|
70
|
+
|
|
71
|
+
#### 2.1 Prefer Type Predicates
|
|
72
|
+
|
|
73
|
+
Use type predicates for validation functions to maximize type safety:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
export const isDate = (value: unknown): value is Date => {
|
|
77
|
+
return Object.prototype.toString.call(value) === "[object Date]"
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### 2.2 Accept `unknown`
|
|
82
|
+
|
|
83
|
+
Public utilities should accept `unknown` unless there is a strong reason to require a narrower input type.
|
|
84
|
+
|
|
85
|
+
#### 2.3 Avoid Side Effects
|
|
86
|
+
|
|
87
|
+
Helpers should be deterministic and should not mutate input values unless explicitly documented.
|
|
88
|
+
|
|
89
|
+
#### 2.4 Helper Placement
|
|
90
|
+
|
|
91
|
+
- If a utility function uses helper variables or helper functions, place those helpers immediately before the utility function.
|
|
92
|
+
- Do not add blank lines between a helper and the utility function it supports.
|
|
93
|
+
- Helper variables and functions must be prefixed with `internal`.
|
|
94
|
+
- Helper variables and functions must never be exported.
|
|
95
|
+
|
|
96
|
+
#### 2.5 Spacing
|
|
97
|
+
|
|
98
|
+
- Separate different utility functions with a single blank line.
|
|
99
|
+
|
|
100
|
+
### 3. Naming Conventions
|
|
101
|
+
|
|
102
|
+
#### 3.1 Function Name Format
|
|
103
|
+
|
|
104
|
+
All functions should follow a consistent naming pattern:
|
|
105
|
+
|
|
106
|
+
**Format:** `<domain><Operation><Qualifier>`
|
|
107
|
+
|
|
108
|
+
- `is*` for predicates and checks (for example, `isPlainObject`, `isFiniteNumber`)
|
|
109
|
+
- `string*` for string utilities (`stringRandom`, `stringTruncate`)
|
|
110
|
+
- `number*` for number utilities (`numberClamp`, `numberInRange`)
|
|
111
|
+
- `boolean*`, `date*`, `regexp*`, `error*`, `symbol*`, `bigint*` for other domains
|
|
112
|
+
|
|
113
|
+
#### 3.2 Common Verb Prefixes
|
|
114
|
+
|
|
115
|
+
- `is*` - Returns boolean for validation
|
|
116
|
+
- `has*` - Returns boolean for existence checks
|
|
117
|
+
- `get*` / `extract*` - Returns a value
|
|
118
|
+
- `to*` - Conversion operations
|
|
119
|
+
|
|
120
|
+
### 4. Export Strategy
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Always export public functions
|
|
124
|
+
export const publicFunction = () => {}
|
|
125
|
+
|
|
126
|
+
// Never export internal helpers
|
|
127
|
+
const internalHelper = () => {}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Keep domain exports in their files and re-export them via the barrel in `index.ts`.
|
|
131
|
+
|
|
132
|
+
### 5. Common Pitfalls to Avoid
|
|
133
|
+
|
|
134
|
+
1. Do not rely on `typeof` alone for objects (for example, `typeof null === "object"`).
|
|
135
|
+
2. Do not confuse `NaN` with numbers that cannot be parsed.
|
|
136
|
+
3. Do not treat boxed objects (`new String("x")`) as primitives without checks.
|
|
137
|
+
4. Do not mutate inputs unless the function name and docs make it explicit.
|
|
138
|
+
5. Do not introduce locale-dependent behavior without documenting it.
|
|
139
|
+
|
|
140
|
+
### 6. Testing Requirements
|
|
141
|
+
|
|
142
|
+
- Write one test per function.
|
|
143
|
+
- If multiple cases are needed, include them within the same test.
|