@rtorcato/js-common 1.8.1 โ 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 +17 -0
- package/README.md +53 -62
- package/dist/arrays/index.js +1 -1
- package/dist/boolean/index.js +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/logging/index.js +1 -1
- package/dist/math/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +1 -14
- package/dist/chunks/chunk-DCFILRIS.js +0 -1
- package/dist/math/math.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
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
|
+
|
|
1
18
|
## [1.8.1](https://github.com/rtorcato/js-common/compare/v1.8.0...v1.8.1) (2026-05-29)
|
|
2
19
|
|
|
3
20
|
|
package/README.md
CHANGED
|
@@ -6,20 +6,20 @@
|
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](https://nodejs.org/)
|
|
9
|
+
[](https://codecov.io/gh/rtorcato/js-common)
|
|
9
10
|
[](https://rtorcato.github.io/js-common/)
|
|
10
11
|
|
|
11
12
|
A comprehensive set of common JavaScript and TypeScript utilities for Node.js projects.
|
|
12
13
|
|
|
13
14
|
๐ **Documentation:** <https://rtorcato.github.io/js-common/>
|
|
14
15
|
|
|
15
|
-
##
|
|
16
|
+
## Features
|
|
16
17
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- ๐งช **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.
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
@@ -50,7 +50,7 @@ See [CLI.md](./CLI.md) for complete CLI documentation.
|
|
|
50
50
|
## Library Usage
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
|
-
//
|
|
53
|
+
// Import specific modules (recommended for tree-shaking)
|
|
54
54
|
import { formatDate, today, daysBetween } from '@rtorcato/js-common/date'
|
|
55
55
|
import { validateEmail, isValidEmail } from '@rtorcato/js-common/emails'
|
|
56
56
|
import { generateUUID, isValidUUID } from '@rtorcato/js-common/uuid'
|
|
@@ -58,7 +58,7 @@ import { sum, average, roundTo } from '@rtorcato/js-common/numbers'
|
|
|
58
58
|
import { capitalize, toTitleCase } from '@rtorcato/js-common/formatting'
|
|
59
59
|
|
|
60
60
|
// Example usage
|
|
61
|
-
console.log(today()) // "
|
|
61
|
+
console.log(today()) // "2026-05-29"
|
|
62
62
|
console.log(sum([1, 2, 3, 4, 5])) // 15
|
|
63
63
|
console.log(capitalize('hello world')) // "Hello world"
|
|
64
64
|
console.log(generateUUID()) // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
@@ -68,102 +68,93 @@ console.log(generateUUID()) // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
|
|
|
68
68
|
|
|
69
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).
|
|
70
70
|
|
|
71
|
-
### ๐ฏ **TypeScript Support**
|
|
72
|
-
|
|
73
|
-
This package is built with TypeScript and includes complete type definitions out of the box:
|
|
74
|
-
|
|
75
|
-
- โ
**Full type safety** - All functions have accurate TypeScript types
|
|
76
|
-
- โ
**Generic support** - Functions like `unique<T>()` preserve your data types
|
|
77
|
-
- โ
**JSDoc integration** - Rich documentation in your IDE
|
|
78
|
-
- โ
**Tree-shakable** - Import only what you need with perfect type inference
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
// TypeScript automatically infers types
|
|
82
|
-
const numbers = [1, 2, 3, 4, 5]
|
|
83
|
-
const result: number = sum(numbers) // โ
Type: number
|
|
84
|
-
|
|
85
|
-
const users = [{ name: 'John' }, { name: 'Jane' }]
|
|
86
|
-
const uniqueUsers = unique(users) // โ
Type: { name: string }[]
|
|
87
|
-
|
|
88
|
-
// IDE shows full documentation and type hints
|
|
89
|
-
import { today } from '@rtorcato/js-common/date'
|
|
90
|
-
// ^ JSDoc: Returns today's date as YYYY-MM-DD string
|
|
91
|
-
```
|
|
92
|
-
|
|
93
71
|
## Available Modules
|
|
94
72
|
|
|
95
|
-
###
|
|
73
|
+
### Date & Time
|
|
96
74
|
```typescript
|
|
97
75
|
import { today, formatDate, daysBetween, isLeapYear } from '@rtorcato/js-common/date'
|
|
98
76
|
import { nowIso, formatDateTimeLocal, unixTimestamp } from '@rtorcato/js-common/datetime'
|
|
99
77
|
import { nowTime, parseTime, secondsBetween } from '@rtorcato/js-common/time'
|
|
78
|
+
import { runInterval, clearIntervalById } from '@rtorcato/js-common/interval'
|
|
100
79
|
```
|
|
101
80
|
|
|
102
|
-
###
|
|
81
|
+
### Numbers & Math
|
|
103
82
|
```typescript
|
|
104
83
|
import { sum, average, roundTo, clamp, getRandomInt } from '@rtorcato/js-common/numbers'
|
|
105
84
|
import { add, subtract, multiply, divide } from '@rtorcato/js-common/math'
|
|
85
|
+
import { randomInt, randomFloat, randomBool, randomElement } from '@rtorcato/js-common/random'
|
|
106
86
|
```
|
|
107
87
|
|
|
108
|
-
###
|
|
88
|
+
### Text & Strings
|
|
109
89
|
```typescript
|
|
110
90
|
import { capitalize, toTitleCase, padZero } from '@rtorcato/js-common/formatting'
|
|
111
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'
|
|
112
95
|
```
|
|
113
96
|
|
|
114
|
-
###
|
|
97
|
+
### Security & Validation
|
|
115
98
|
```typescript
|
|
116
99
|
import { isStrongPassword, generateSecureToken } from '@rtorcato/js-common/security'
|
|
117
100
|
import { isValidEmail, validateEmail } from '@rtorcato/js-common/emails'
|
|
118
101
|
import { isValidUrl } from '@rtorcato/js-common/url'
|
|
119
102
|
import { isString, isNumber, isArray, isObject } from '@rtorcato/js-common/validation'
|
|
103
|
+
import { toBoolean, isBoolean, xor } from '@rtorcato/js-common/boolean'
|
|
120
104
|
```
|
|
121
105
|
|
|
122
|
-
###
|
|
106
|
+
### Data Structures
|
|
123
107
|
```typescript
|
|
124
108
|
import { flatten, unique, chunk, groupBy } from '@rtorcato/js-common/arrays'
|
|
125
109
|
import { deepMerge, pick, omit, deepClone } from '@rtorcato/js-common/objects'
|
|
126
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'
|
|
127
113
|
```
|
|
128
114
|
|
|
129
|
-
###
|
|
115
|
+
### Async & Control Flow
|
|
130
116
|
```typescript
|
|
131
117
|
import { delay, timeout, retry } from '@rtorcato/js-common/promises'
|
|
132
118
|
import { debounce, throttle, once } from '@rtorcato/js-common/functions'
|
|
133
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'
|
|
134
123
|
```
|
|
135
124
|
|
|
136
|
-
###
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
+
```
|
|
134
|
+
|
|
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
|
+
```
|
|
140
|
+
|
|
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)
|
|
147
152
|
|
|
148
153
|
## Requirements
|
|
149
154
|
|
|
150
155
|
- **Node.js** >= 22.0.0 (enforced via the `engines` field)
|
|
151
156
|
- **TypeScript** >= 5.0.0 (for TypeScript projects)
|
|
152
157
|
|
|
153
|
-
## Why This Library?
|
|
154
|
-
|
|
155
|
-
### ๐ฏ **Focused & Lightweight**
|
|
156
|
-
Unlike larger utility libraries, js-common is designed for modern applications:
|
|
157
|
-
- **Tiny bundle size** - Won't bloat your application
|
|
158
|
-
- **Tree-shakeable** - Only import what you use
|
|
159
|
-
- **CLI included** - Use utilities in scripts and terminal
|
|
160
|
-
|
|
161
|
-
### ๐ ๏ธ **Modern Development**
|
|
162
|
-
- Built with **TypeScript** for excellent DX
|
|
163
|
-
- **ESM-only**, native subpath exports
|
|
164
|
-
- **Minimal runtime deps** โ CLI packages (`chalk`, `commander`, `figlet`, โฆ) are `optionalDependencies` and only fetched when you opt in to the CLI
|
|
165
|
-
- Comprehensive **test coverage**
|
|
166
|
-
|
|
167
158
|
## Development
|
|
168
159
|
|
|
169
160
|
```bash
|
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};
|
package/dist/errors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as tryWithFallback};
|
package/dist/logging/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function i(o,r="info"){let n=new Date().toISOString();console[r](`[${n}] ${o}`)}function t(o){console.warn(`[WARN] ${o}`)}function s(o){console.error(`[ERROR] ${o}`)}function c(o){console.info(`[INFO] ${o}`)}function l(o){let r={log:console.log,info:console.info,warn:console.warn,error:console.error};return["log","info","warn","error"].forEach(n=>{console[n]=(...e)=>{o(n,...e),r[n](...e)}}),()=>{Object.assign(console,r)}}export{l as captureConsole,s as error,c as info,i as logWithTimestamp,t as warn};
|
package/dist/math/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";var n=(e,r)=>e+r,u=(e,r)=>e-r,b=(e,r)=>e*r,m=(e,r)=>e/r;export{n as add,m as divide,b as multiply,u as subtract};
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function r(n){return n!=null}function e(n){return typeof n=="string"}function t(n){return typeof n=="number"&&!Number.isNaN(n)}function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function r(n){return n!=null}function e(n){return typeof n=="string"}function t(n){return typeof n=="number"&&!Number.isNaN(n)}function o(n){return typeof n=="boolean"}function u(n){return Array.isArray(n)}function i(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function s(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n)}function a(n){try{return new URL(n),!0}catch{return!1}}export{u as isArray,o as isBoolean,r as isDefined,s as isEmail,t as isNumber,i as isObject,e as isString,a as isUrl};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rtorcato/js-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "JavaScript and TypeScript common code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -261,7 +261,6 @@
|
|
|
261
261
|
"husky": "^9.1.7",
|
|
262
262
|
"jsdom": "^29.0.1",
|
|
263
263
|
"knip": "^6.14.2",
|
|
264
|
-
"lint-staged": "^16.2.6",
|
|
265
264
|
"rimraf": "^6.0.1",
|
|
266
265
|
"semantic-release": "^25.0.1",
|
|
267
266
|
"typescript": "^6.0.2",
|
|
@@ -289,18 +288,6 @@
|
|
|
289
288
|
"path": "cz-conventional-changelog"
|
|
290
289
|
}
|
|
291
290
|
},
|
|
292
|
-
"lint-staged": {
|
|
293
|
-
"*.{js,ts,json,md}": [
|
|
294
|
-
"pnpm exec biome lint",
|
|
295
|
-
"pnpm exec biome format",
|
|
296
|
-
"git add"
|
|
297
|
-
]
|
|
298
|
-
},
|
|
299
|
-
"husky": {
|
|
300
|
-
"hooks": {
|
|
301
|
-
"pre-commit": "lint-staged"
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
291
|
"publishConfig": {
|
|
305
292
|
"access": "public"
|
|
306
293
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var n=(e,r)=>e+r,u=(e,r)=>e-r,b=(e,r)=>e*r,m=(e,r)=>e/r;export{n as a,u as b,b as c,m as d};
|
package/dist/math/math.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b,c,d}from"../chunks/chunk-DCFILRIS.js";import"../chunks/chunk-ANN5UYCF.js";export{a as add,d as divide,c as multiply,b as subtract};
|