@stonyx/utils 0.2.3-alpha.1 → 0.2.3-alpha.11

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 CHANGED
@@ -1,3 +1,7 @@
1
+ [![CI](https://github.com/abofs/stonyx-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/abofs/stonyx-utils/actions/workflows/ci.yml)
2
+ [![npm version](https://img.shields.io/npm/v/@stonyx/utils.svg)](https://www.npmjs.com/package/@stonyx/utils)
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+
1
5
  # stonyx-utils
2
6
 
3
7
  Utilities module for the Stonyx Framework. Provides helpers for files, objects, strings, dates, and promises.
@@ -25,10 +29,13 @@ Utilities module for the Stonyx Framework. Provides helpers for files, objects,
25
29
  | | `getOrSet` | Get or set value in a Map. |
26
30
  | **String** | `kebabCaseToCamelCase` | Convert kebab-case to camelCase. |
27
31
  | | `kebabCaseToPascalCase` | Convert kebab-case to PascalCase. |
32
+ | | `camelCaseToKebabCase` | Convert camelCase to kebab-case. |
28
33
  | | `generateRandomString` | Generate a random alphanumeric string. |
29
34
  | | `pluralize` | Return plural form of English nouns. |
30
35
  | **Date** | `getTimestamp` | Return current UNIX timestamp in seconds. |
31
36
  | **Promise** | `sleep` | Async delay for a given number of seconds. |
37
+ | **Prompt** | `confirm` | Prompt user for y/N confirmation. |
38
+ | | `prompt` | Prompt user for free-text input. |
32
39
 
33
40
  ---
34
41
 
@@ -41,6 +48,7 @@ Utilities module for the Stonyx Framework. Provides helpers for files, objects,
41
48
  * [String Utils](#string-utils)
42
49
  * [Date Utils](#date-utils)
43
50
  * [Promise Utils](#promise-utils)
51
+ * [Prompt Utils](#prompt-utils)
44
52
  * [License](#license)
45
53
 
46
54
  ---
@@ -107,6 +115,9 @@ Dynamically imports all `.js` files in a directory and calls `callback(exports,
107
115
  | `fullExport` | Boolean | false | If true, callback receives all exports, not just default. |
108
116
  | `rawName` | Boolean | false | If true, the file name is not converted to camelCase. |
109
117
  | `ignoreAccessFailure` | Boolean | false | If true, directory access errors are ignored. |
118
+ | `recursive` | Boolean | false | If true, recurse into subdirectories. |
119
+ | `recursiveNaming` | Boolean | false | If true, prefix imported names with their directory path. |
120
+ | `namePrefix` | String | `""` | Manual prefix prepended to each imported name. |
110
121
 
111
122
  Example:
112
123
 
@@ -221,6 +232,35 @@ await sleep(2); // waits 2 seconds
221
232
 
222
233
  ---
223
234
 
235
+ ## Prompt Utils
236
+
237
+ Interactive CLI prompt helpers built on Node's `readline`.
238
+
239
+ ### Functions
240
+
241
+ #### `confirm(question, options={})`
242
+
243
+ Prompts the user with `(y/N)` and resolves to `true` only if the answer is `"y"` (case-insensitive).
244
+
245
+ * `options.input` — Readable stream (default: `process.stdin`).
246
+ * `options.output` — Writable stream (default: `process.stdout`).
247
+
248
+ #### `prompt(question, options={})`
249
+
250
+ Prompts the user with a question and resolves to the trimmed input string.
251
+
252
+ * `options.input` — Readable stream (default: `process.stdin`).
253
+ * `options.output` — Writable stream (default: `process.stdout`).
254
+
255
+ ```js
256
+ import { confirm, prompt } from '@stonyx/utils/prompt';
257
+
258
+ const name = await prompt('What is your name?');
259
+ const ok = await confirm('Proceed?');
260
+ ```
261
+
262
+ ---
263
+
224
264
  ## License
225
265
 
226
266
  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.1",
6
+ "version": "0.2.3-alpha.11",
7
7
  "description": "Utils module for Stonyx Framework",
8
8
  "repository": {
9
9
  "type": "git",
10
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 null;
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
+ }
@@ -1,16 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches: [dev, main]
6
-
7
- concurrency:
8
- group: ci-${{ github.head_ref || github.ref }}
9
- cancel-in-progress: true
10
-
11
- permissions:
12
- contents: read
13
-
14
- jobs:
15
- test:
16
- uses: abofs/stonyx-workflows/.github/workflows/ci.yml@main
@@ -1,35 +0,0 @@
1
- name: Publish to NPM
2
-
3
- on:
4
- workflow_dispatch:
5
- inputs:
6
- version-type:
7
- description: 'Version type'
8
- required: true
9
- type: choice
10
- options:
11
- - patch
12
- - minor
13
- - major
14
- custom-version:
15
- description: 'Custom version (optional, overrides version-type)'
16
- required: false
17
- type: string
18
- pull_request:
19
- types: [opened, synchronize, reopened]
20
- branches: [main, dev]
21
- push:
22
- branches: [main]
23
-
24
- permissions:
25
- contents: write
26
- id-token: write
27
- pull-requests: write
28
-
29
- jobs:
30
- publish:
31
- uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
32
- with:
33
- version-type: ${{ github.event.inputs.version-type }}
34
- custom-version: ${{ github.event.inputs.custom-version }}
35
- secrets: inherit