@rtorcato/js-common 1.8.0 โ 2.0.0
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/CHANGELOG.md +25 -0
- package/README.md +59 -85
- package/dist/arrays/index.js +1 -1
- package/dist/boolean/index.js +1 -1
- package/dist/chunks/chunk-6J7HIWG6.js +1 -0
- package/dist/chunks/chunk-FBDKWWIQ.js +3 -0
- package/dist/cli/cli.mjs +439 -0
- package/dist/cli/index.mjs +22 -436
- package/dist/env/index.js +1 -3
- package/dist/errors/index.js +1 -1
- package/dist/index.js +0 -1
- package/dist/logger/index.js +1 -0
- package/dist/logger/logger.js +1 -0
- package/dist/logging/index.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +14 -24
- package/dist/chunks/chunk-DCFILRIS.js +0 -1
- package/dist/helloworld/index.js +0 -1
- package/dist/logging/index1.js +0 -1
- package/dist/math/math.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# [2.0.0](https://github.com/rtorcato/js-common/compare/v1.8.1...v2.0.0) (2026-06-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
* refactor!: maintenance sweep + rename errors.tryCatch ([#47](https://github.com/rtorcato/js-common/issues/47)) ([9bd28a6](https://github.com/rtorcato/js-common/commit/9bd28a68b7566806169812ffed5ccb649d30e6c3))
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **ci:** env-var commit message in check-skip ([#48](https://github.com/rtorcato/js-common/issues/48)) ([1037b0c](https://github.com/rtorcato/js-common/commit/1037b0c31c377bbc80eda57cbe3e411579437685)), closes [#47](https://github.com/rtorcato/js-common/issues/47)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* `tryCatch` from `@rtorcato/js-common/errors` is
|
|
15
|
+
renamed to `tryWithFallback`. For Result-pattern error handling,
|
|
16
|
+
import `tryCatch` from `@rtorcato/js-common/try` instead.
|
|
17
|
+
|
|
18
|
+
## [1.8.1](https://github.com/rtorcato/js-common/compare/v1.8.0...v1.8.1) (2026-05-29)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **deps:** move CLI deps to optionalDependencies ([52d1e9f](https://github.com/rtorcato/js-common/commit/52d1e9feda9ae86dc705f103678024cfb9772c68))
|
|
24
|
+
* publishing bugs and dead-code cleanup ([30b8d69](https://github.com/rtorcato/js-common/commit/30b8d693d6dfcdc4b6044438318f7d5cbaca0e86))
|
|
25
|
+
|
|
1
26
|
# [1.8.0](https://github.com/rtorcato/js-common/compare/v1.7.1...v1.8.0) (2026-05-29)
|
|
2
27
|
|
|
3
28
|
|
package/README.md
CHANGED
|
@@ -5,23 +5,21 @@
|
|
|
5
5
|
[](https://badge.fury.io/js/%40rtorcato%2Fjs-common)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
|
-
[](https://nodejs.org/)
|
|
9
|
+
[](https://codecov.io/gh/rtorcato/js-common)
|
|
10
10
|
[](https://rtorcato.github.io/js-common/)
|
|
11
11
|
|
|
12
12
|
A comprehensive set of common JavaScript and TypeScript utilities for Node.js projects.
|
|
13
13
|
|
|
14
14
|
๐ **Documentation:** <https://rtorcato.github.io/js-common/>
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Features
|
|
17
17
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
- โก **Utility modules have no dependencies** - CLI features use optional packages isolated to the `cli` subpath
|
|
24
|
-
- ๐งช **Well tested** - Comprehensive test coverage
|
|
18
|
+
- **Tree-shakeable** โ import only what you need via subpath exports
|
|
19
|
+
- **TypeScript** โ full type definitions, JSDoc on every public API
|
|
20
|
+
- **CLI included** โ optional binary for use in scripts and terminals
|
|
21
|
+
- **Modular** โ one module per concern, 46 subpaths
|
|
22
|
+
- **Minimal runtime deps** โ only `date-fns`, `date-fns-tz`, `luxon`, `pino`, `uuid`, `short-uuid`, `zod`. CLI packages (`chalk`, `commander`, `figlet`, โฆ) are `optionalDependencies` and only needed for the CLI.
|
|
25
23
|
|
|
26
24
|
## Installation
|
|
27
25
|
|
|
@@ -52,18 +50,15 @@ See [CLI.md](./CLI.md) for complete CLI documentation.
|
|
|
52
50
|
## Library Usage
|
|
53
51
|
|
|
54
52
|
```typescript
|
|
55
|
-
//
|
|
53
|
+
// Import specific modules (recommended for tree-shaking)
|
|
56
54
|
import { formatDate, today, daysBetween } from '@rtorcato/js-common/date'
|
|
57
55
|
import { validateEmail, isValidEmail } from '@rtorcato/js-common/emails'
|
|
58
56
|
import { generateUUID, isValidUUID } from '@rtorcato/js-common/uuid'
|
|
59
57
|
import { sum, average, roundTo } from '@rtorcato/js-common/numbers'
|
|
60
58
|
import { capitalize, toTitleCase } from '@rtorcato/js-common/formatting'
|
|
61
59
|
|
|
62
|
-
// ๐ฆ Or import everything (larger bundle)
|
|
63
|
-
import * as jsCommon from '@rtorcato/js-common'
|
|
64
|
-
|
|
65
60
|
// Example usage
|
|
66
|
-
console.log(today()) // "
|
|
61
|
+
console.log(today()) // "2026-05-29"
|
|
67
62
|
console.log(sum([1, 2, 3, 4, 5])) // 15
|
|
68
63
|
console.log(capitalize('hello world')) // "Hello world"
|
|
69
64
|
console.log(generateUUID()) // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
@@ -71,118 +66,94 @@ console.log(generateUUID()) // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
|
71
66
|
|
|
72
67
|
### Bundle Size Impact
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
// This adds ~50 bytes to your bundle
|
|
78
|
-
import { today } from '@rtorcato/js-common/date'
|
|
79
|
-
|
|
80
|
-
// This adds ~100 bytes to your bundle
|
|
81
|
-
import { sum, average } from '@rtorcato/js-common/numbers'
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### ๐ฏ **TypeScript Support**
|
|
85
|
-
|
|
86
|
-
This package is built with TypeScript and includes complete type definitions out of the box:
|
|
87
|
-
|
|
88
|
-
- โ
**Full type safety** - All functions have accurate TypeScript types
|
|
89
|
-
- โ
**Generic support** - Functions like `unique<T>()` preserve your data types
|
|
90
|
-
- โ
**JSDoc integration** - Rich documentation in your IDE
|
|
91
|
-
- โ
**Tree-shakable** - Import only what you need with perfect type inference
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
// TypeScript automatically infers types
|
|
95
|
-
const numbers = [1, 2, 3, 4, 5]
|
|
96
|
-
const result: number = sum(numbers) // โ
Type: number
|
|
97
|
-
|
|
98
|
-
const users = [{ name: 'John' }, { name: 'Jane' }]
|
|
99
|
-
const uniqueUsers = unique(users) // โ
Type: { name: string }[]
|
|
100
|
-
|
|
101
|
-
// IDE shows full documentation and type hints
|
|
102
|
-
import { today } from '@rtorcato/js-common/date'
|
|
103
|
-
// ^ JSDoc: Returns today's date as YYYY-MM-DD string
|
|
104
|
-
```
|
|
69
|
+
Each module is shipped as its own subpath export so bundlers only include what you import. Individual modules range from ~100 bytes (e.g. `sleep`) to ~2 KB (e.g. `currency`) when minified. Measure against your own bundle with [bundlejs.com](https://bundlejs.com/?q=@rtorcato/js-common/numbers).
|
|
105
70
|
|
|
106
71
|
## Available Modules
|
|
107
72
|
|
|
108
|
-
###
|
|
73
|
+
### Date & Time
|
|
109
74
|
```typescript
|
|
110
75
|
import { today, formatDate, daysBetween, isLeapYear } from '@rtorcato/js-common/date'
|
|
111
76
|
import { nowIso, formatDateTimeLocal, unixTimestamp } from '@rtorcato/js-common/datetime'
|
|
112
77
|
import { nowTime, parseTime, secondsBetween } from '@rtorcato/js-common/time'
|
|
78
|
+
import { runInterval, clearIntervalById } from '@rtorcato/js-common/interval'
|
|
113
79
|
```
|
|
114
80
|
|
|
115
|
-
###
|
|
81
|
+
### Numbers & Math
|
|
116
82
|
```typescript
|
|
117
83
|
import { sum, average, roundTo, clamp, getRandomInt } from '@rtorcato/js-common/numbers'
|
|
118
84
|
import { add, subtract, multiply, divide } from '@rtorcato/js-common/math'
|
|
85
|
+
import { randomInt, randomFloat, randomBool, randomElement } from '@rtorcato/js-common/random'
|
|
119
86
|
```
|
|
120
87
|
|
|
121
|
-
###
|
|
88
|
+
### Text & Strings
|
|
122
89
|
```typescript
|
|
123
90
|
import { capitalize, toTitleCase, padZero } from '@rtorcato/js-common/formatting'
|
|
124
91
|
import { slugify, truncate, removeEmojis } from '@rtorcato/js-common/strings'
|
|
92
|
+
import { escapeHtml, unescapeHtml, stripHtmlTags } from '@rtorcato/js-common/html'
|
|
93
|
+
import { escapeRegExp, matchAll, replaceAllRegex } from '@rtorcato/js-common/regex'
|
|
94
|
+
import { detectLanguage, formatNumber, t, pluralize } from '@rtorcato/js-common/i18n'
|
|
125
95
|
```
|
|
126
96
|
|
|
127
|
-
###
|
|
97
|
+
### Security & Validation
|
|
128
98
|
```typescript
|
|
129
99
|
import { isStrongPassword, generateSecureToken } from '@rtorcato/js-common/security'
|
|
130
100
|
import { isValidEmail, validateEmail } from '@rtorcato/js-common/emails'
|
|
131
101
|
import { isValidUrl } from '@rtorcato/js-common/url'
|
|
132
102
|
import { isString, isNumber, isArray, isObject } from '@rtorcato/js-common/validation'
|
|
103
|
+
import { toBoolean, isBoolean, xor } from '@rtorcato/js-common/boolean'
|
|
133
104
|
```
|
|
134
105
|
|
|
135
|
-
###
|
|
106
|
+
### Data Structures
|
|
136
107
|
```typescript
|
|
137
108
|
import { flatten, unique, chunk, groupBy } from '@rtorcato/js-common/arrays'
|
|
138
109
|
import { deepMerge, pick, omit, deepClone } from '@rtorcato/js-common/objects'
|
|
139
110
|
import { safeJsonParse, safeJsonStringify } from '@rtorcato/js-common/json'
|
|
111
|
+
import { invertMap, mapValues, objectToMap, mapToObject } from '@rtorcato/js-common/maps'
|
|
112
|
+
import { union, intersection, difference, isSubset } from '@rtorcato/js-common/sets'
|
|
140
113
|
```
|
|
141
114
|
|
|
142
|
-
###
|
|
115
|
+
### Async & Control Flow
|
|
143
116
|
```typescript
|
|
144
117
|
import { delay, timeout, retry } from '@rtorcato/js-common/promises'
|
|
145
118
|
import { debounce, throttle, once } from '@rtorcato/js-common/functions'
|
|
146
119
|
import { sleep } from '@rtorcato/js-common/sleep'
|
|
120
|
+
import { tryCatch } from '@rtorcato/js-common/try'
|
|
121
|
+
import { createAbortController, withAbort, abortAfter } from '@rtorcato/js-common/abortController'
|
|
122
|
+
import { createCustomError, getErrorMessage, assert } from '@rtorcato/js-common/errors'
|
|
147
123
|
```
|
|
148
124
|
|
|
149
|
-
###
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
- **Process** - Process and environment utilities
|
|
159
|
-
- **Geometry** - 2D geometry calculations
|
|
160
|
-
|
|
161
|
-
## Requirements
|
|
162
|
-
|
|
163
|
-
- **Node.js** >= 18.0.0
|
|
164
|
-
- **TypeScript** >= 5.0.0 (for TypeScript projects)
|
|
125
|
+
### System & Process
|
|
126
|
+
```typescript
|
|
127
|
+
import { getENV, isDev, isProd, getNodeEnv, checkEnv } from '@rtorcato/js-common/env'
|
|
128
|
+
import { getOsPlatform, getOsArch, getHomeDir } from '@rtorcato/js-common/os'
|
|
129
|
+
import { getNodeMajorVersion, isNode, requireOptional } from '@rtorcato/js-common/node'
|
|
130
|
+
import { getProcessId, getCwd, exitProcess, isCI } from '@rtorcato/js-common/process'
|
|
131
|
+
import { isMacOs, isWindows, isLinux, getPlatform } from '@rtorcato/js-common/system'
|
|
132
|
+
import { disableConsole, clearConsole } from '@rtorcato/js-common/console'
|
|
133
|
+
```
|
|
165
134
|
|
|
166
|
-
|
|
135
|
+
### Logging
|
|
136
|
+
```typescript
|
|
137
|
+
import { logger } from '@rtorcato/js-common/logger' // pino-based
|
|
138
|
+
import { info, warn, error, captureConsole } from '@rtorcato/js-common/logging'
|
|
139
|
+
```
|
|
167
140
|
|
|
168
|
-
###
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
141
|
+
### Other
|
|
142
|
+
- `colors` โ color manipulation and conversion
|
|
143
|
+
- `crypto` โ cryptographic helpers
|
|
144
|
+
- `currency` โ currency formatting and conversion
|
|
145
|
+
- `events` โ event emitter utilities
|
|
146
|
+
- `fetch` โ HTTP request helpers
|
|
147
|
+
- `file` โ file system helpers
|
|
148
|
+
- `geometry` โ 2D geometry calculations
|
|
149
|
+
- `mime-types` โ MIME-type lookup
|
|
150
|
+
- `uuid` โ UUID generation and validation
|
|
151
|
+
- `types` โ shared TypeScript type definitions (types-only export)
|
|
173
152
|
|
|
174
|
-
|
|
175
|
-
```
|
|
176
|
-
lodash: ~70KB (full) / ~25KB (common functions)
|
|
177
|
-
ramda: ~60KB (full) / ~15KB (common functions)
|
|
178
|
-
js-common: 277 bytes (full) / ~50-200 bytes (individual modules)
|
|
179
|
-
```
|
|
153
|
+
## Requirements
|
|
180
154
|
|
|
181
|
-
|
|
182
|
-
-
|
|
183
|
-
- **ESM-first** with CommonJS compatibility
|
|
184
|
-
- **No dependencies in utility modules** โ CLI packages (chalk, commander, etc.) are isolated to the `cli` subpath
|
|
185
|
-
- Comprehensive **test coverage**
|
|
155
|
+
- **Node.js** >= 22.0.0 (enforced via the `engines` field)
|
|
156
|
+
- **TypeScript** >= 5.0.0 (for TypeScript projects)
|
|
186
157
|
|
|
187
158
|
## Development
|
|
188
159
|
|
|
@@ -207,6 +178,9 @@ pnpm run check:fix
|
|
|
207
178
|
|
|
208
179
|
# Type checking
|
|
209
180
|
pnpm run typecheck
|
|
181
|
+
|
|
182
|
+
# Run micro-benchmarks (scripts/benchmark.mjs)
|
|
183
|
+
pnpm run benchmark
|
|
210
184
|
```
|
|
211
185
|
|
|
212
186
|
## Documentation site
|
package/dist/arrays/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function u(n){return n[0]}function T(n){return n.length?n[n.length-1]:void 0}function f(n){return Array.from(new Set(n))}function i(n){return n.flat()}function l(n,e){if(e<1)throw new Error("Chunk size must be at least 1");let t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function s(n){return n.filter(Boolean)}function c(n){let e=n.slice();for(let t=e.length-1;t>0;t--){let r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e}function h(n,e){return n.reduce((t,r)=>{let o=e(r);return t[o]||(t[o]=[]),t[o].push(r),t},{})}export{l as chunk,s as compact,u as first,i as flatten,h as groupBy,T as last,c as shuffle,f as unique};
|
package/dist/boolean/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function e(o){if(typeof o=="boolean")return o;if(typeof o=="string"){let n=o.trim().toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="0")return!1}return typeof o=="number"?o===1:!!o}function r(o){return typeof o=="boolean"}function t(o,n){return!!(o?!n:n)}function a(o,n){return o&&n}function f(o,n){return o||n}function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function e(o){if(typeof o=="boolean")return o;if(typeof o=="string"){let n=o.trim().toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="0")return!1}return typeof o=="number"?o===1:!!o}function r(o){return typeof o=="boolean"}function t(o,n){return!!(o?!n:n)}function a(o,n){return o&&n}function f(o,n){return o||n}function u(o){return!o}export{a as and,r as isBoolean,u as not,f as or,e as toBoolean,t as xor};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as e}from"./chunk-FBDKWWIQ.js";import o from"pino";var i=e()?o({level:"debug",transport:{target:"pino-pretty",options:{colorize:!0,ignore:"pid,hostname,time",levelFirst:!1,singleLine:!0,customColors:"err:red,info:blue",translateTime:"HH:MM:ss"}}}):o({level:"info"});export{i as a};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{z as n}from"zod";var c=(r,o)=>{let e=process.env[r.toString()];if(e===void 0&&o!==void 0)return o;if(e===void 0){let t=`Undefined ENV variable - ${r.toString()}`;throw new Error(t)}return e},d=()=>process.env.NODE_ENV==="development",p=()=>process.env.NODE_ENV==="production",E=()=>process.env.NODE_ENV==="test",u=()=>process.env.NODE_ENV||"development";function a(r,o=process.env){try{return r.parse(o)}catch(e){if(e instanceof n.ZodError){let t=`Missing required values in .env:
|
|
2
|
+
`;t+=Object.keys(e.flatten().fieldErrors).join(`
|
|
3
|
+
`);let s=new Error(t);throw s.stack="",s}throw e}}var f=n.object({NODE_ENV:n.enum(["development","test","production"]).default("development"),LOG_LEVEL:n.enum(["debug","info","warn","error"]).default("info"),PORT:n.coerce.number().default(3e3)});export{c as a,d as b,p as c,E as d,u as e,a as f,f as g};
|