@stonyx/utils 0.2.3-beta.1 → 0.2.3-beta.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.
@@ -0,0 +1,187 @@
1
+ # Project Structure
2
+
3
+ ## Index
4
+
5
+ - [Overview](#overview)
6
+ - [Tech Stack](#tech-stack)
7
+ - [File Structure](#file-structure)
8
+ - [Package Exports](#package-exports)
9
+ - [Module Documentation](#module-documentation)
10
+ - [date.js](#srcdate.js)
11
+ - [file.js](#srcfile.js)
12
+ - [object.js](#srcobject.js)
13
+ - [plurarize.js](#srcplurarize.js)
14
+ - [promise.js](#srcpromise.js)
15
+ - [prompt.js](#srcprompt.js)
16
+ - [string.js](#srcstring.js)
17
+ - [Dependencies](#dependencies)
18
+ - [Test Patterns](#test-patterns)
19
+ - [CI/CD](#cicd)
20
+
21
+ ---
22
+
23
+ ## Overview
24
+
25
+ `@stonyx/utils` is a utilities module for the Stonyx Framework. It provides pure JavaScript helper functions for file system operations, object manipulation, string transformations, date handling, promises, and interactive CLI prompts.
26
+
27
+ - **Package name:** `@stonyx/utils`
28
+ - **Version:** `0.2.3-beta.1`
29
+ - **License:** Apache-2.0
30
+ - **Module system:** ES Modules (`"type": "module"`)
31
+ - **Node version:** v24.13.0 (`.nvmrc`)
32
+ - **Package manager:** pnpm
33
+ - **Repository:** https://github.com/abofs/stonyx-utils.git
34
+
35
+ ## Tech Stack
36
+
37
+ - **Runtime:** Node.js (ESM)
38
+ - **Test framework:** QUnit 2.x
39
+ - **Test mocking:** Sinon 21.x
40
+ - **CI/CD:** GitHub Actions (reusable workflows from `abofs/stonyx-workflows`)
41
+ - **Publishing:** npm (public, with provenance)
42
+
43
+ ## File Structure
44
+
45
+ ```
46
+ stonyx-utils/
47
+ .claude/ # Claude project memory
48
+ project-structure.md # This file
49
+ .github/
50
+ workflows/
51
+ ci.yml # CI on PRs to dev/main (reusable workflow)
52
+ publish.yml # NPM publish on push to main / manual dispatch
53
+ src/
54
+ date.js # Date utilities
55
+ file.js # File system utilities
56
+ object.js # Object/array utilities
57
+ plurarize.js # Pluralization engine (NOTE: filename typo)
58
+ promise.js # Promise utilities
59
+ prompt.js # CLI prompt utilities
60
+ string.js # String transformation utilities
61
+ test/
62
+ unit/
63
+ file-test.js # Tests for src/file.js
64
+ prompt-test.js # Tests for src/prompt.js
65
+ object/
66
+ get-test.js # Tests for object get()
67
+ getOrSet-test.js # Tests for object getOrSet()
68
+ object-test.js # Tests for mergeObject()
69
+ string/
70
+ plurarize-test.js # Tests for pluralize (NOTE: filename typo)
71
+ string-test.js # Tests for string conversion functions
72
+ .gitignore
73
+ .npmignore # Excludes test/ and .nvmrc from published package
74
+ .nvmrc # Node v24.13.0
75
+ LICENSE.md # Apache-2.0
76
+ README.md
77
+ package.json
78
+ pnpm-lock.yaml
79
+ ```
80
+
81
+ ## Package Exports
82
+
83
+ Defined in `package.json` under `"exports"`:
84
+
85
+ | Import path | File |
86
+ | ---------------------- | ---------------- |
87
+ | `@stonyx/utils/date` | `src/date.js` |
88
+ | `@stonyx/utils/object` | `src/object.js` |
89
+ | `@stonyx/utils/file` | `src/file.js` |
90
+ | `@stonyx/utils/promise`| `src/promise.js` |
91
+ | `@stonyx/utils/prompt` | `src/prompt.js` |
92
+ | `@stonyx/utils/string` | `src/string.js` |
93
+
94
+ ## Module Documentation
95
+
96
+ ### `src/date.js`
97
+
98
+ | Export | Signature | Description |
99
+ | ------ | --------- | ----------- |
100
+ | `getTimestamp` | `getTimestamp(dateObject?: Date): number` | Returns UNIX timestamp in seconds. If `dateObject` is provided, uses that date; otherwise uses `Date.now()`. |
101
+
102
+ ### `src/file.js`
103
+
104
+ Imports: `@stonyx/utils/date`, `@stonyx/utils/string`, `@stonyx/utils/object`, `fs`, `path`
105
+
106
+ | Export | Signature | Description |
107
+ | ------ | --------- | ----------- |
108
+ | `createFile` | `createFile(filePath, data, options?): Promise<void>` | Creates a file. `options.json` serializes data as JSON. Auto-creates parent directories. |
109
+ | `updateFile` | `updateFile(filePath, data, options?): Promise<void>` | Atomically updates an existing file via temp-file swap. `options.json` for JSON serialization. Throws if file does not exist. |
110
+ | `copyFile` | `copyFile(sourcePath, targetPath, options?): Promise<boolean>` | Copies a file. Returns `false` if target exists and `options.overwrite` is not `true`. |
111
+ | `readFile` | `readFile(filePath, options?): Promise<string\|object>` | Reads a file. `options.json` parses as JSON. `options.missingFileCallback(filePath)` called on ENOENT. |
112
+ | `deleteFile` | `deleteFile(filePath, options?): Promise<void>` | Deletes a file. `options.ignoreAccessFailure` silences missing-file errors. |
113
+ | `deleteDirectory` | `deleteDirectory(dir): Promise<void>` | Recursively deletes a directory (`rm -rf`). |
114
+ | `createDirectory` | `createDirectory(dir): Promise<void>` | Recursively creates a directory (`mkdir -p`). |
115
+ | `forEachFileImport` | `forEachFileImport(dir, callback, options?): Promise<void>` | Dynamically imports all `.js` files in a directory and invokes `callback(exports, { name, stats, path })`. Options: `fullExport`, `rawName`, `ignoreAccessFailure`, `recursive`, `recursiveNaming`, `namePrefix`. |
116
+ | `fileExists` | `fileExists(filePath): Promise<boolean>` | Returns `true` if file exists, `false` otherwise. |
117
+
118
+ ### `src/object.js`
119
+
120
+ | Export | Signature | Description |
121
+ | ------ | --------- | ----------- |
122
+ | `deepCopy` | `deepCopy(obj): any` | Deep clones via `JSON.parse(JSON.stringify())`. |
123
+ | `objToJson` | `objToJson(obj, format?): string` | Stringifies object with formatting (default: tab). |
124
+ | `makeArray` | `makeArray(obj): Array` | Wraps value in array if not already an array. |
125
+ | `mergeObject` | `mergeObject(obj1, obj2, options?): object` | Deep merges two objects. `options.ignoreNewKeys` skips keys not in `obj1`. Throws on array input. |
126
+ | `get` | `get(obj, path): any\|null` | Safely traverses dot-notation path. Returns `null` if any segment is `undefined`. Uses `console.error` for validation (does not throw). |
127
+ | `getOrSet` | `getOrSet(map, key, defaultValue): any` | Gets from a `Map`, or sets `defaultValue` (or calls it if function) when key is missing. Throws if not a `Map`. |
128
+
129
+ ### `src/plurarize.js`
130
+
131
+ | Export | Signature | Description |
132
+ | ------ | --------- | ----------- |
133
+ | `default` (pluralize) | `pluralize(word): string` | Returns plural form of an English noun. Handles irregular nouns, uncountable nouns, and rule-based suffixes (s/x/ch/sh, y, f/fe, o, z). Preserves casing. |
134
+
135
+ ### `src/promise.js`
136
+
137
+ | Export | Signature | Description |
138
+ | ------ | --------- | ----------- |
139
+ | `sleep` | `sleep(seconds): Promise<void>` | Async delay for the given number of seconds. |
140
+
141
+ ### `src/prompt.js`
142
+
143
+ | Export | Signature | Description |
144
+ | ------ | --------- | ----------- |
145
+ | `confirm` | `confirm(question, options?): Promise<boolean>` | Prompts user with `(y/N)` and returns `true` only if input is `"y"` (case-insensitive). Options: `{ input, output }` for custom streams. |
146
+ | `prompt` | `prompt(question, options?): Promise<string>` | Prompts user with a question and returns trimmed input. Options: `{ input, output }` for custom streams. |
147
+
148
+ ### `src/string.js`
149
+
150
+ Re-exports `pluralize` from `./plurarize.js`.
151
+
152
+ | Export | Signature | Description |
153
+ | ------ | --------- | ----------- |
154
+ | `kebabCaseToCamelCase` | `kebabCaseToCamelCase(str): string` | Converts `kebab-case` to `camelCase`. |
155
+ | `kebabCaseToPascalCase` | `kebabCaseToPascalCase(str): string` | Converts `kebab-case` to `PascalCase`. |
156
+ | `camelCaseToKebabCase` | `camelCaseToKebabCase(str): string` | Converts `camelCase` to `kebab-case`. |
157
+ | `generateRandomString` | `generateRandomString(length?): string` | Generates random alphanumeric string (default length: 8). |
158
+ | `pluralize` | (re-export) | Re-exported from `./plurarize.js`. |
159
+
160
+ ## Dependencies
161
+
162
+ ### Runtime
163
+
164
+ None (`"dependencies": {}`).
165
+
166
+ ### Dev
167
+
168
+ | Package | Version | Purpose |
169
+ | ------- | ------- | ------- |
170
+ | `qunit` | `^2.24.1` | Test framework |
171
+ | `sinon` | `^21.0.0` | Stubs/spies for tests |
172
+ | `fs` | `^0.0.1-security` | Placeholder (Node built-in) |
173
+
174
+ ## Test Patterns
175
+
176
+ - **Framework:** QUnit with nested `module()` blocks
177
+ - **Mocking:** Sinon spies/stubs (used for `console.error` spying in `get-test.js`, stub factories in `getOrSet-test.js`)
178
+ - **Stream mocking:** Custom `Readable`/`Writable` streams in `prompt-test.js`
179
+ - **File tests:** Create temp directory in `beforeEach`, clean up in `afterEach`
180
+ - **Run command:** `pnpm test` (which runs `qunit`)
181
+ - **Import style:** Tests import from package exports (e.g., `@stonyx/utils/object`)
182
+
183
+ ## CI/CD
184
+
185
+ - **CI workflow** (`ci.yml`): Runs on PRs to `dev` and `main` branches. Uses reusable workflow from `abofs/stonyx-workflows/.github/workflows/ci.yml@main`. Concurrency grouping cancels in-progress runs for the same branch.
186
+ - **Publish workflow** (`publish.yml`): Triggers on push to `main`, PR events, or manual dispatch. Supports `patch`/`minor`/`major` version bumps and custom version strings. Uses reusable workflow from `abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main`. Requires `contents: write`, `id-token: write`, and `pull-requests: write` permissions.
187
+ - **Prepublish hook:** `npm test` runs before publish via `prepublishOnly` script.
@@ -17,7 +17,7 @@ on:
17
17
  type: string
18
18
  pull_request:
19
19
  types: [opened, synchronize, reopened]
20
- branches: [main, dev]
20
+ branches: [main]
21
21
  push:
22
22
  branches: [main]
23
23
 
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,7 +3,7 @@
3
3
  "keywords": [
4
4
  "stonyx-module"
5
5
  ],
6
- "version": "0.2.3-beta.1",
6
+ "version": "0.2.3-beta.2",
7
7
  "description": "Utils module for Stonyx Framework",
8
8
  "repository": {
9
9
  "type": "git",
@@ -15,6 +15,7 @@
15
15
  "./object": "./src/object.js",
16
16
  "./file": "./src/file.js",
17
17
  "./promise": "./src/promise.js",
18
+ "./prompt": "./src/prompt.js",
18
19
  "./string": "./src/string.js"
19
20
  },
20
21
  "publishConfig": {
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
+ }