@gunshi/combinators 0.28.2

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 kazuya kawaguchi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # `@gunshi/combinators`
2
+
3
+ [![Version][npm-version-src]][npm-version-href]
4
+ [![InstallSize][install-size-src]][install-size-src]
5
+ [![JSR][jsr-src]][jsr-href]
6
+
7
+ > parser combinators for gunshi argument schema
8
+
9
+ <!-- eslint-disable markdown/no-missing-label-refs -->
10
+
11
+ > [!WARNING]
12
+ > This package is currently **experimental**. The API may change in future versions.
13
+
14
+ <!-- eslint-enable markdown/no-missing-label-refs -->
15
+
16
+ This package provides composable factory functions for building type-safe argument schemas.
17
+
18
+ - **Base combinators**: `string`, `number`, `integer`, `float`, `boolean`, `choice`, `positional`, `combinator`
19
+ - **Modifier combinators**: `required`, `unrequired`, `withDefault`, `multiple`, `short`, `describe`, `map`
20
+ - **Schema combinators**: `args`, `merge`, `extend`
21
+
22
+ <!-- eslint-disable markdown/no-missing-label-refs -->
23
+
24
+ > [!TIP]
25
+ > **The APIs and type definitions available in this package are the same as those in the `gunshi/combinators` entry in the `gunshi` package.**
26
+ > This package is smaller in file size than the `gunshi` package, making it suitable for use when you want to reduce the size of the `node_modules` in your command you are creating.
27
+
28
+ <!-- eslint-enable markdown/no-missing-label-refs -->
29
+
30
+ ## 💿 Installation
31
+
32
+ ```sh
33
+ # npm
34
+ npm install --save @gunshi/combinators
35
+
36
+ ## pnpm
37
+ pnpm add @gunshi/combinators
38
+
39
+ ## yarn
40
+ yarn add @gunshi/combinators
41
+
42
+ ## deno
43
+ deno add jsr:@gunshi/combinators
44
+
45
+ ## bun
46
+ bun add @gunshi/combinators
47
+ ```
48
+
49
+ ## 🚀 Usage
50
+
51
+ ```ts
52
+ import { define } from '@gunshi/definition'
53
+ import {
54
+ args,
55
+ boolean,
56
+ choice,
57
+ integer,
58
+ merge,
59
+ required,
60
+ short,
61
+ string,
62
+ withDefault
63
+ } from '@gunshi/combinators'
64
+
65
+ // Define reusable schema groups
66
+ const common = args({
67
+ verbose: short(boolean(), 'v')
68
+ })
69
+
70
+ const network = args({
71
+ host: withDefault(string(), 'localhost'),
72
+ port: withDefault(integer({ min: 1, max: 65535 }), 3000)
73
+ })
74
+
75
+ // Compose schemas with merge()
76
+ export default define({
77
+ name: 'serve',
78
+ args: merge(
79
+ common,
80
+ network,
81
+ args({
82
+ mode: choice(['development', 'production'] as const),
83
+ entry: required(string())
84
+ })
85
+ ),
86
+ run: ctx => {
87
+ // ctx.values is fully typed:
88
+ // - host: string, port: number (always defined due to withDefault)
89
+ // - verbose: boolean | undefined
90
+ // - mode: 'development' | 'production' | undefined
91
+ // - entry: string (always defined due to required)
92
+ console.log(`${ctx.values.host}:${ctx.values.port}`)
93
+ }
94
+ })
95
+ ```
96
+
97
+ About details, See the below official docs sections:
98
+
99
+ - Experimentals:
100
+ - [Parser Combinators](https://gunshi.dev/guide/experimentals/parser-combinators)
101
+
102
+ ## ©️ License
103
+
104
+ [MIT](http://opensource.org/licenses/MIT)
105
+
106
+ <!-- Badges -->
107
+
108
+ [npm-version-src]: https://img.shields.io/npm/v/@gunshi/combinators?style=flat
109
+ [npm-version-href]: https://npmjs.com/package/@gunshi/combinators@alpha
110
+ [jsr-src]: https://jsr.io/badges/@gunshi/combinators
111
+ [jsr-href]: https://jsr.io/@gunshi/combinators
112
+ [install-size-src]: https://pkg-size.dev/badge/install/23122