@stonyx/utils 0.2.3-beta.7 → 0.2.3-beta.9
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/package.json
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
"keywords": [
|
|
4
4
|
"stonyx-module"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.2.3-beta.
|
|
6
|
+
"version": "0.2.3-beta.9",
|
|
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",
|
|
@@ -1,187 +0,0 @@
|
|
|
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.
|
package/.github/workflows/ci.yml
DELETED
|
@@ -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,51 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
repository_dispatch:
|
|
5
|
-
types: [cascade-publish]
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
inputs:
|
|
8
|
-
version-type:
|
|
9
|
-
description: 'Version type'
|
|
10
|
-
required: true
|
|
11
|
-
type: choice
|
|
12
|
-
options:
|
|
13
|
-
- patch
|
|
14
|
-
- minor
|
|
15
|
-
- major
|
|
16
|
-
custom-version:
|
|
17
|
-
description: 'Custom version (optional, overrides version-type)'
|
|
18
|
-
required: false
|
|
19
|
-
type: string
|
|
20
|
-
pull_request:
|
|
21
|
-
types: [opened, synchronize, reopened]
|
|
22
|
-
branches: [main]
|
|
23
|
-
push:
|
|
24
|
-
branches: [main]
|
|
25
|
-
|
|
26
|
-
concurrency:
|
|
27
|
-
group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
|
|
28
|
-
cancel-in-progress: false
|
|
29
|
-
|
|
30
|
-
permissions:
|
|
31
|
-
contents: write
|
|
32
|
-
id-token: write
|
|
33
|
-
pull-requests: write
|
|
34
|
-
|
|
35
|
-
jobs:
|
|
36
|
-
publish:
|
|
37
|
-
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
|
38
|
-
uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
|
|
39
|
-
with:
|
|
40
|
-
version-type: ${{ github.event.inputs.version-type }}
|
|
41
|
-
custom-version: ${{ github.event.inputs.custom-version }}
|
|
42
|
-
cascade-source: ${{ github.event.client_payload.source_package || '' }}
|
|
43
|
-
secrets: inherit
|
|
44
|
-
|
|
45
|
-
cascade:
|
|
46
|
-
needs: publish
|
|
47
|
-
uses: abofs/stonyx-workflows/.github/workflows/cascade.yml@main
|
|
48
|
-
with:
|
|
49
|
-
package-name: ${{ needs.publish.outputs.package-name }}
|
|
50
|
-
published-version: ${{ needs.publish.outputs.published-version }}
|
|
51
|
-
secrets: inherit
|