@stonyx/utils 0.2.3-alpha.0 → 0.2.3-alpha.10
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/README.md +36 -0
- package/package.json +7 -2
- package/src/object.js +1 -1
- package/src/prompt.js +29 -0
- package/src/string.js +4 -0
- package/.github/workflows/ci.yml +0 -36
- package/.github/workflows/publish.yml +0 -143
package/README.md
CHANGED
|
@@ -25,10 +25,13 @@ Utilities module for the Stonyx Framework. Provides helpers for files, objects,
|
|
|
25
25
|
| | `getOrSet` | Get or set value in a Map. |
|
|
26
26
|
| **String** | `kebabCaseToCamelCase` | Convert kebab-case to camelCase. |
|
|
27
27
|
| | `kebabCaseToPascalCase` | Convert kebab-case to PascalCase. |
|
|
28
|
+
| | `camelCaseToKebabCase` | Convert camelCase to kebab-case. |
|
|
28
29
|
| | `generateRandomString` | Generate a random alphanumeric string. |
|
|
29
30
|
| | `pluralize` | Return plural form of English nouns. |
|
|
30
31
|
| **Date** | `getTimestamp` | Return current UNIX timestamp in seconds. |
|
|
31
32
|
| **Promise** | `sleep` | Async delay for a given number of seconds. |
|
|
33
|
+
| **Prompt** | `confirm` | Prompt user for y/N confirmation. |
|
|
34
|
+
| | `prompt` | Prompt user for free-text input. |
|
|
32
35
|
|
|
33
36
|
---
|
|
34
37
|
|
|
@@ -41,6 +44,7 @@ Utilities module for the Stonyx Framework. Provides helpers for files, objects,
|
|
|
41
44
|
* [String Utils](#string-utils)
|
|
42
45
|
* [Date Utils](#date-utils)
|
|
43
46
|
* [Promise Utils](#promise-utils)
|
|
47
|
+
* [Prompt Utils](#prompt-utils)
|
|
44
48
|
* [License](#license)
|
|
45
49
|
|
|
46
50
|
---
|
|
@@ -107,6 +111,9 @@ Dynamically imports all `.js` files in a directory and calls `callback(exports,
|
|
|
107
111
|
| `fullExport` | Boolean | false | If true, callback receives all exports, not just default. |
|
|
108
112
|
| `rawName` | Boolean | false | If true, the file name is not converted to camelCase. |
|
|
109
113
|
| `ignoreAccessFailure` | Boolean | false | If true, directory access errors are ignored. |
|
|
114
|
+
| `recursive` | Boolean | false | If true, recurse into subdirectories. |
|
|
115
|
+
| `recursiveNaming` | Boolean | false | If true, prefix imported names with their directory path. |
|
|
116
|
+
| `namePrefix` | String | `""` | Manual prefix prepended to each imported name. |
|
|
110
117
|
|
|
111
118
|
Example:
|
|
112
119
|
|
|
@@ -221,6 +228,35 @@ await sleep(2); // waits 2 seconds
|
|
|
221
228
|
|
|
222
229
|
---
|
|
223
230
|
|
|
231
|
+
## Prompt Utils
|
|
232
|
+
|
|
233
|
+
Interactive CLI prompt helpers built on Node's `readline`.
|
|
234
|
+
|
|
235
|
+
### Functions
|
|
236
|
+
|
|
237
|
+
#### `confirm(question, options={})`
|
|
238
|
+
|
|
239
|
+
Prompts the user with `(y/N)` and resolves to `true` only if the answer is `"y"` (case-insensitive).
|
|
240
|
+
|
|
241
|
+
* `options.input` — Readable stream (default: `process.stdin`).
|
|
242
|
+
* `options.output` — Writable stream (default: `process.stdout`).
|
|
243
|
+
|
|
244
|
+
#### `prompt(question, options={})`
|
|
245
|
+
|
|
246
|
+
Prompts the user with a question and resolves to the trimmed input string.
|
|
247
|
+
|
|
248
|
+
* `options.input` — Readable stream (default: `process.stdin`).
|
|
249
|
+
* `options.output` — Writable stream (default: `process.stdout`).
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
import { confirm, prompt } from '@stonyx/utils/prompt';
|
|
253
|
+
|
|
254
|
+
const name = await prompt('What is your name?');
|
|
255
|
+
const ok = await confirm('Proceed?');
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
224
260
|
## License
|
|
225
261
|
|
|
226
262
|
Apache — do what you want, just keep attribution.
|
package/package.json
CHANGED
|
@@ -3,18 +3,23 @@
|
|
|
3
3
|
"keywords": [
|
|
4
4
|
"stonyx-module"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.2.3-alpha.
|
|
6
|
+
"version": "0.2.3-alpha.10",
|
|
7
7
|
"description": "Utils module for Stonyx Framework",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/abofs/stonyx-utils"
|
|
10
|
+
"url": "https://github.com/abofs/stonyx-utils.git"
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
13
17
|
"exports": {
|
|
14
18
|
"./date": "./src/date.js",
|
|
15
19
|
"./object": "./src/object.js",
|
|
16
20
|
"./file": "./src/file.js",
|
|
17
21
|
"./promise": "./src/promise.js",
|
|
22
|
+
"./prompt": "./src/prompt.js",
|
|
18
23
|
"./string": "./src/string.js"
|
|
19
24
|
},
|
|
20
25
|
"publishConfig": {
|
package/src/object.js
CHANGED
|
@@ -44,7 +44,7 @@ export function get(obj, path) {
|
|
|
44
44
|
if (typeof path !== 'string') return console.error('The path provided to get must be a string.');
|
|
45
45
|
|
|
46
46
|
for (const key of path.split('.')) {
|
|
47
|
-
if (obj[key] === undefined) return
|
|
47
|
+
if (obj[key] === undefined) return;
|
|
48
48
|
|
|
49
49
|
obj = obj[key];
|
|
50
50
|
}
|
package/src/prompt.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createInterface } from 'readline';
|
|
2
|
+
|
|
3
|
+
export function confirm(question, { input, output } = {}) {
|
|
4
|
+
const rl = createInterface({
|
|
5
|
+
input: input ?? process.stdin,
|
|
6
|
+
output: output ?? process.stdout,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return new Promise(resolve => {
|
|
10
|
+
rl.question(`${question} (y/N) `, answer => {
|
|
11
|
+
rl.close();
|
|
12
|
+
resolve(answer.trim().toLowerCase() === 'y');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function prompt(question, { input, output } = {}) {
|
|
18
|
+
const rl = createInterface({
|
|
19
|
+
input: input ?? process.stdin,
|
|
20
|
+
output: output ?? process.stdout,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return new Promise(resolve => {
|
|
24
|
+
rl.question(`${question} `, answer => {
|
|
25
|
+
rl.close();
|
|
26
|
+
resolve(answer.trim());
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
package/src/string.js
CHANGED
|
@@ -23,6 +23,10 @@ export function kebabCaseToPascalCase(str) {
|
|
|
23
23
|
return kebabToCase(str, true);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export function camelCaseToKebabCase(str) {
|
|
27
|
+
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
export function generateRandomString(length=8) {
|
|
27
31
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
28
32
|
return Array(length).fill('').map(() => characters.charAt(Math.floor(Math.random() * characters.length))).join('');
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches:
|
|
6
|
-
- dev
|
|
7
|
-
- main
|
|
8
|
-
|
|
9
|
-
concurrency:
|
|
10
|
-
group: ci-${{ github.head_ref || github.ref }}
|
|
11
|
-
cancel-in-progress: true
|
|
12
|
-
|
|
13
|
-
jobs:
|
|
14
|
-
test:
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
steps:
|
|
18
|
-
- name: Checkout code
|
|
19
|
-
uses: actions/checkout@v3
|
|
20
|
-
|
|
21
|
-
- name: Setup pnpm
|
|
22
|
-
uses: pnpm/action-setup@v4
|
|
23
|
-
with:
|
|
24
|
-
version: 9
|
|
25
|
-
|
|
26
|
-
- name: Set up Node.js
|
|
27
|
-
uses: actions/setup-node@v3
|
|
28
|
-
with:
|
|
29
|
-
node-version: 24.13.0
|
|
30
|
-
cache: 'pnpm'
|
|
31
|
-
|
|
32
|
-
- name: Install dependencies
|
|
33
|
-
run: pnpm install --frozen-lockfile
|
|
34
|
-
|
|
35
|
-
- name: Run tests
|
|
36
|
-
run: pnpm test
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
# Manual trigger (kept for flexibility)
|
|
5
|
-
workflow_dispatch:
|
|
6
|
-
inputs:
|
|
7
|
-
version-type:
|
|
8
|
-
description: 'Version type'
|
|
9
|
-
required: true
|
|
10
|
-
type: choice
|
|
11
|
-
options:
|
|
12
|
-
- alpha
|
|
13
|
-
- patch
|
|
14
|
-
- minor
|
|
15
|
-
- major
|
|
16
|
-
custom-version:
|
|
17
|
-
description: 'Custom version (optional, overrides version-type)'
|
|
18
|
-
required: false
|
|
19
|
-
type: string
|
|
20
|
-
|
|
21
|
-
# Auto-publish alpha on PR
|
|
22
|
-
pull_request:
|
|
23
|
-
types: [opened, synchronize, reopened]
|
|
24
|
-
branches: [main, dev]
|
|
25
|
-
|
|
26
|
-
# Auto-publish stable on merge to main
|
|
27
|
-
push:
|
|
28
|
-
branches: [main]
|
|
29
|
-
|
|
30
|
-
permissions:
|
|
31
|
-
contents: write
|
|
32
|
-
id-token: write # Required for npm provenance
|
|
33
|
-
pull-requests: write # For PR comments
|
|
34
|
-
|
|
35
|
-
jobs:
|
|
36
|
-
publish:
|
|
37
|
-
runs-on: ubuntu-latest
|
|
38
|
-
|
|
39
|
-
steps:
|
|
40
|
-
- name: Checkout code
|
|
41
|
-
uses: actions/checkout@v3
|
|
42
|
-
with:
|
|
43
|
-
fetch-depth: 0
|
|
44
|
-
# For PR events, check out the PR branch
|
|
45
|
-
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
|
|
46
|
-
|
|
47
|
-
- name: Setup pnpm
|
|
48
|
-
uses: pnpm/action-setup@v4
|
|
49
|
-
with:
|
|
50
|
-
version: 9
|
|
51
|
-
|
|
52
|
-
- name: Set up Node.js
|
|
53
|
-
uses: actions/setup-node@v3
|
|
54
|
-
with:
|
|
55
|
-
node-version: 24.13.0
|
|
56
|
-
cache: 'pnpm'
|
|
57
|
-
registry-url: 'https://registry.npmjs.org'
|
|
58
|
-
|
|
59
|
-
- name: Install dependencies
|
|
60
|
-
run: pnpm install --frozen-lockfile
|
|
61
|
-
|
|
62
|
-
- name: Run tests
|
|
63
|
-
run: pnpm test
|
|
64
|
-
|
|
65
|
-
- name: Configure git
|
|
66
|
-
run: |
|
|
67
|
-
git config user.name "github-actions[bot]"
|
|
68
|
-
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
69
|
-
|
|
70
|
-
# Determine version type based on trigger
|
|
71
|
-
- name: Determine version bump type
|
|
72
|
-
id: version-type
|
|
73
|
-
run: |
|
|
74
|
-
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
75
|
-
echo "type=alpha" >> $GITHUB_OUTPUT
|
|
76
|
-
elif [ "${{ github.event_name }}" = "push" ]; then
|
|
77
|
-
echo "type=patch" >> $GITHUB_OUTPUT
|
|
78
|
-
elif [ "${{ github.event.inputs.custom-version }}" != "" ]; then
|
|
79
|
-
echo "type=custom" >> $GITHUB_OUTPUT
|
|
80
|
-
else
|
|
81
|
-
echo "type=${{ github.event.inputs.version-type }}" >> $GITHUB_OUTPUT
|
|
82
|
-
fi
|
|
83
|
-
|
|
84
|
-
# Version bumping
|
|
85
|
-
- name: Bump version (custom)
|
|
86
|
-
if: steps.version-type.outputs.type == 'custom'
|
|
87
|
-
run: pnpm version ${{ github.event.inputs.custom-version }} --no-git-tag-version
|
|
88
|
-
|
|
89
|
-
- name: Bump version (alpha)
|
|
90
|
-
if: steps.version-type.outputs.type == 'alpha'
|
|
91
|
-
run: pnpm version prerelease --preid=alpha --no-git-tag-version
|
|
92
|
-
|
|
93
|
-
- name: Bump version (patch/minor/major)
|
|
94
|
-
if: steps.version-type.outputs.type == 'patch' || steps.version-type.outputs.type == 'minor' || steps.version-type.outputs.type == 'major'
|
|
95
|
-
run: pnpm version ${{ steps.version-type.outputs.type }} --no-git-tag-version
|
|
96
|
-
|
|
97
|
-
- name: Get package version
|
|
98
|
-
id: package-version
|
|
99
|
-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
|
100
|
-
|
|
101
|
-
# Publishing
|
|
102
|
-
- name: Publish to NPM (alpha)
|
|
103
|
-
if: contains(steps.package-version.outputs.version, 'alpha')
|
|
104
|
-
run: pnpm publish --tag alpha --access public --no-git-checks
|
|
105
|
-
|
|
106
|
-
- name: Publish to NPM (stable)
|
|
107
|
-
if: "!contains(steps.package-version.outputs.version, 'alpha')"
|
|
108
|
-
run: pnpm publish --access public
|
|
109
|
-
|
|
110
|
-
# Only commit and tag for stable releases (push to main or manual stable)
|
|
111
|
-
- name: Commit version bump and create tag
|
|
112
|
-
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
|
|
113
|
-
run: |
|
|
114
|
-
git add package.json
|
|
115
|
-
git commit -m "chore: release v${{ steps.package-version.outputs.version }}"
|
|
116
|
-
git tag v${{ steps.package-version.outputs.version }}
|
|
117
|
-
git push origin main --tags
|
|
118
|
-
|
|
119
|
-
- name: Create GitHub Release
|
|
120
|
-
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
|
|
121
|
-
uses: actions/create-release@v1
|
|
122
|
-
env:
|
|
123
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
124
|
-
with:
|
|
125
|
-
tag_name: v${{ steps.package-version.outputs.version }}
|
|
126
|
-
release_name: v${{ steps.package-version.outputs.version }}
|
|
127
|
-
draft: false
|
|
128
|
-
prerelease: false
|
|
129
|
-
|
|
130
|
-
# Add PR comment with alpha version info
|
|
131
|
-
- name: Comment on PR with alpha version
|
|
132
|
-
if: github.event_name == 'pull_request'
|
|
133
|
-
uses: actions/github-script@v6
|
|
134
|
-
with:
|
|
135
|
-
script: |
|
|
136
|
-
const version = '${{ steps.package-version.outputs.version }}';
|
|
137
|
-
const packageName = require('./package.json').name;
|
|
138
|
-
github.rest.issues.createComment({
|
|
139
|
-
issue_number: context.issue.number,
|
|
140
|
-
owner: context.repo.owner,
|
|
141
|
-
repo: context.repo.repo,
|
|
142
|
-
body: `## 🚀 Alpha Version Published\n\n**Version:** \`${version}\`\n\n**Install:**\n\`\`\`bash\npnpm add ${packageName}@${version}\n# or\npnpm add ${packageName}@alpha # latest alpha\n\`\`\`\n\nThis alpha version is now available for testing!`
|
|
143
|
-
});
|