@ix-xs/node-comfort 1.1.31 → 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.
Files changed (77) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/LICENSE +21 -0
  3. package/README.md +210 -748
  4. package/index.js +84 -13
  5. package/package.json +201 -21
  6. package/src/Arr.js +901 -0
  7. package/src/Async.js +585 -0
  8. package/src/Cache.js +329 -0
  9. package/src/Checker.js +979 -188
  10. package/src/Cli.js +1034 -0
  11. package/src/Color.js +415 -0
  12. package/src/Crypto.js +707 -0
  13. package/src/Emitter.js +289 -0
  14. package/src/Env.js +555 -0
  15. package/src/FS.js +1483 -768
  16. package/src/Func.js +692 -0
  17. package/src/Http.js +538 -0
  18. package/src/Id.js +418 -0
  19. package/src/Logger.js +739 -307
  20. package/src/Num.js +849 -0
  21. package/src/Obj.js +904 -0
  22. package/src/SQLite.js +1308 -994
  23. package/src/Schema.js +1586 -0
  24. package/src/Str.js +999 -0
  25. package/src/Sys.js +511 -0
  26. package/src/Time.js +1323 -0
  27. package/src/Utils.js +321 -325
  28. package/src/errors.js +292 -0
  29. package/types/index.d.ts +693 -120
  30. package/types/src/Arr.d.ts +562 -0
  31. package/types/src/Arr.d.ts.map +1 -0
  32. package/types/src/Async.d.ts +321 -0
  33. package/types/src/Async.d.ts.map +1 -0
  34. package/types/src/Cache.d.ts +195 -0
  35. package/types/src/Cache.d.ts.map +1 -0
  36. package/types/src/Checker.d.ts +609 -81
  37. package/types/src/Checker.d.ts.map +1 -1
  38. package/types/src/Cli.d.ts +582 -0
  39. package/types/src/Cli.d.ts.map +1 -0
  40. package/types/src/Color.d.ts +294 -0
  41. package/types/src/Color.d.ts.map +1 -0
  42. package/types/src/Crypto.d.ts +534 -0
  43. package/types/src/Crypto.d.ts.map +1 -0
  44. package/types/src/Emitter.d.ts +170 -0
  45. package/types/src/Emitter.d.ts.map +1 -0
  46. package/types/src/Env.d.ts +382 -0
  47. package/types/src/Env.d.ts.map +1 -0
  48. package/types/src/FS.d.ts +709 -201
  49. package/types/src/FS.d.ts.map +1 -1
  50. package/types/src/Func.d.ts +455 -0
  51. package/types/src/Func.d.ts.map +1 -0
  52. package/types/src/Http.d.ts +374 -0
  53. package/types/src/Http.d.ts.map +1 -0
  54. package/types/src/Id.d.ts +200 -0
  55. package/types/src/Id.d.ts.map +1 -0
  56. package/types/src/Logger.d.ts +374 -24
  57. package/types/src/Logger.d.ts.map +1 -1
  58. package/types/src/Num.d.ts +578 -0
  59. package/types/src/Num.d.ts.map +1 -0
  60. package/types/src/Obj.d.ts +475 -0
  61. package/types/src/Obj.d.ts.map +1 -0
  62. package/types/src/SQLite.d.ts +647 -305
  63. package/types/src/SQLite.d.ts.map +1 -1
  64. package/types/src/Schema.d.ts +940 -0
  65. package/types/src/Schema.d.ts.map +1 -0
  66. package/types/src/Str.d.ts +696 -0
  67. package/types/src/Str.d.ts.map +1 -0
  68. package/types/src/Sys.d.ts +269 -0
  69. package/types/src/Sys.d.ts.map +1 -0
  70. package/types/src/Time.d.ts +664 -0
  71. package/types/src/Time.d.ts.map +1 -0
  72. package/types/src/Utils.d.ts +154 -102
  73. package/types/src/Utils.d.ts.map +1 -1
  74. package/types/src/errors.d.ts +292 -0
  75. package/types/src/errors.d.ts.map +1 -0
  76. package/tsconfig.json +0 -18
  77. package/types/index.d.ts.map +0 -1
package/index.js CHANGED
@@ -1,13 +1,84 @@
1
- const Logger = require("./src/Logger");
2
- const FS = require("./src/FS");
3
- const Checker = require("./src/Checker");
4
- const Utils = require("./src/Utils");
5
- const SQLite = require("./src/SQLite");
6
-
7
- module.exports = {
8
- ...Logger,
9
- ...FS,
10
- ...Checker,
11
- ...Utils,
12
- SQLite,
13
- };
1
+ "use strict";
2
+
3
+ // Every namespace is loaded the first time you touch it, so requiring the
4
+ // package costs almost nothing.
5
+
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+
9
+ // The .env file must be applied before any user code reads process.env.
10
+ if (String(process.env.NODE_COMFORT_DOTENV).toLowerCase() !== "false" && fs.existsSync(path.join(process.cwd(), ".env"))) {
11
+ require("./src/Env.js");
12
+ }
13
+
14
+ /** @type {Record<string, () => any>} */
15
+ const modules = {
16
+ logger: () => require("./src/Logger.js"),
17
+ fs: () => require("./src/FS.js"),
18
+ checker: () => require("./src/Checker.js"),
19
+ utils: () => require("./src/Utils.js"),
20
+ str: () => require("./src/Str.js"),
21
+ num: () => require("./src/Num.js"),
22
+ arr: () => require("./src/Arr.js"),
23
+ obj: () => require("./src/Obj.js"),
24
+ func: () => require("./src/Func.js"),
25
+ time: () => require("./src/Time.js"),
26
+ id: () => require("./src/Id.js"),
27
+ crypto: () => require("./src/Crypto.js"),
28
+ color: () => require("./src/Color.js"),
29
+ cli: () => require("./src/Cli.js"),
30
+ sys: () => require("./src/Sys.js"),
31
+ async: () => require("./src/Async.js"),
32
+ schema: () => require("./src/Schema.js"),
33
+ http: () => require("./src/Http.js"),
34
+ env: () => require("./src/Env.js"),
35
+ errors: () => require("./src/errors.js"),
36
+ SQLite: () => require("./src/SQLite.js"),
37
+ Cache: () => require("./src/Cache.js"),
38
+ Emitter: () => require("./src/Emitter.js"),
39
+ };
40
+
41
+ // Helpers that are also available at the top level (nc.info, nc.readJSON...).
42
+ const flat = {
43
+ logger: ["log", "trace", "debug", "info", "success", "warn", "error", "fatal", "group", "groupEnd", "timeStart", "timeEnd", "table", "box", "divider", "setLevel", "getLevel", "isLevelEnabled", "configure", "setTimestamp", "setDelimiter", "createLogger"],
44
+ fs: ["getEnv", "createPath", "getFolder", "getFile", "getFoldersIn", "getFilesIn", "glob", "find", "readFile", "readLines", "readJSON", "writeFile", "writeJSON", "appendFile", "createFile", "createFolder", "ensureFolder", "ensureFile", "touch", "deleteFolder", "deleteFile", "remove", "deleteFoldersIn", "deleteFilesIn", "emptyFolder", "copy", "move", "copyFoldersIn", "copyFolder", "copyFilesIn", "copyFile", "moveFoldersIn", "moveFolder", "moveFilesIn", "moveFile", "exists", "isFile", "isFolder", "stat", "fileSize", "folderSize", "hashFile", "tempFolder", "sanitizeFilename", "watch"],
45
+ checker: ["isArray", "isNumber", "isFinite", "isInteger", "isSafeInteger", "isFloat", "isPositive", "isNegative", "isBoolean", "isString", "isSymbol", "isBigInt", "isUndefined", "isNull", "isNil", "isDefined", "isPrimitive", "isFunction", "isAsyncFunction", "isGeneratorFunction", "isGenerator", "isClass", "isObject", "isPlainObject", "isPromise", "isRegExp", "isDate", "isValidDate", "isMap", "isSet", "isWeakMap", "isWeakSet", "isIterable", "isAsyncIterable", "isBuffer", "isTypedArray", "isError", "isEmpty", "isBlank", "isArrayOf", "isOneOf", "isEmail", "isURL", "isUUID", "isJSON", "isNumeric", "isIP", "isIPv4", "isIPv6", "isPort", "isHex", "isHexColor", "isBase64", "isSemver", "isISODate", "isSlug", "isAlpha", "isAlphanumeric", "isCreditCard", "isJWT", "assert", "assertType"],
46
+ utils: ["wait", "when", "dontCrash", "JSONString", "JSONParse"],
47
+ };
48
+
49
+ /**
50
+ * @param {string} name
51
+ * @param {() => unknown} load
52
+ */
53
+ const lazy = (name, load) => {
54
+ let loaded = false;
55
+ /** @type {unknown} */
56
+ let value;
57
+ Object.defineProperty(exports, name, {
58
+ get: () => {
59
+ if (!loaded) {
60
+ value = load();
61
+ loaded = true;
62
+ }
63
+ return value;
64
+ },
65
+ set: (replacement) => {
66
+ value = replacement;
67
+ loaded = true;
68
+ },
69
+ enumerable: true,
70
+ configurable: true,
71
+ });
72
+ };
73
+
74
+ for (const [namespace, names] of Object.entries(flat)) {
75
+ for (const name of names) lazy(name, () => modules[namespace]()[name]);
76
+ }
77
+ for (const [name, load] of Object.entries(modules)) lazy(name, load);
78
+
79
+ exports.nc = exports;
80
+ exports.nodeComfort = exports;
81
+
82
+ // Never runs. Node reads this line to know the named exports of the package
83
+ // when it is imported from an ES module.
84
+ 0 && (module.exports = { log, trace, debug, info, success, warn, error, fatal, group, groupEnd, timeStart, timeEnd, table, box, divider, setLevel, getLevel, isLevelEnabled, configure, setTimestamp, setDelimiter, createLogger, getEnv, createPath, getFolder, getFile, getFoldersIn, getFilesIn, glob, find, readFile, readLines, readJSON, writeFile, writeJSON, appendFile, createFile, createFolder, ensureFolder, ensureFile, touch, deleteFolder, deleteFile, remove, deleteFoldersIn, deleteFilesIn, emptyFolder, copy, move, copyFoldersIn, copyFolder, copyFilesIn, copyFile, moveFoldersIn, moveFolder, moveFilesIn, moveFile, exists, isFile, isFolder, stat, fileSize, folderSize, hashFile, tempFolder, sanitizeFilename, watch, isArray, isNumber, isFinite, isInteger, isSafeInteger, isFloat, isPositive, isNegative, isBoolean, isString, isSymbol, isBigInt, isUndefined, isNull, isNil, isDefined, isPrimitive, isFunction, isAsyncFunction, isGeneratorFunction, isGenerator, isClass, isObject, isPlainObject, isPromise, isRegExp, isDate, isValidDate, isMap, isSet, isWeakMap, isWeakSet, isIterable, isAsyncIterable, isBuffer, isTypedArray, isError, isEmpty, isBlank, isArrayOf, isOneOf, isEmail, isURL, isUUID, isJSON, isNumeric, isIP, isIPv4, isIPv6, isPort, isHex, isHexColor, isBase64, isSemver, isISODate, isSlug, isAlpha, isAlphanumeric, isCreditCard, isJWT, assert, assertType, wait, when, dontCrash, JSONString, JSONParse, logger, fs, checker, utils, str, num, arr, obj, func, time, id, crypto, color, cli, sys, async, schema, http, env, errors, SQLite, Cache, Emitter, nc, nodeComfort });
package/package.json CHANGED
@@ -1,21 +1,201 @@
1
- {
2
- "name": "@ix-xs/node-comfort",
3
- "version": "1.1.31",
4
- "description": "Small collection of Node.js utilities: colorful logger, filesystem helper, SQLite wrapper, runtime type checks and async/process helpers.",
5
- "main": "index.js",
6
- "types": "types/index.d.ts",
7
- "keywords": [],
8
- "author": "ix-xs",
9
- "type": "commonjs",
10
- "engines": {
11
- "node": ">=20.12.0"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/ix-xs/node-comfort.git"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/ix-xs/node-comfort/issues"
19
- },
20
- "homepage": "https://github.com/ix-xs/node-comfort#readme"
21
- }
1
+ {
2
+ "name": "@ix-xs/node-comfort",
3
+ "version": "2.0.0",
4
+ "description": "The zero-dependency standard library for Node.js: logger, filesystem, SQLite, schema validation, HTTP client, CLI toolkit, cache, env, async pools, colors, events, i18n dates, ids, crypto and hundreds of fully typed helpers.",
5
+ "keywords": [
6
+ "utils",
7
+ "utilities",
8
+ "helpers",
9
+ "toolkit",
10
+ "stdlib",
11
+ "standard-library",
12
+ "zero-dependency",
13
+ "no-dependencies",
14
+ "typescript",
15
+ "logger",
16
+ "colors",
17
+ "ansi",
18
+ "cli",
19
+ "spinner",
20
+ "progress-bar",
21
+ "prompt",
22
+ "filesystem",
23
+ "fs",
24
+ "glob",
25
+ "sqlite",
26
+ "database",
27
+ "schema",
28
+ "validation",
29
+ "http",
30
+ "fetch",
31
+ "retry",
32
+ "cache",
33
+ "lru",
34
+ "env",
35
+ "dotenv",
36
+ "async",
37
+ "concurrency",
38
+ "queue",
39
+ "events",
40
+ "emitter",
41
+ "date",
42
+ "i18n",
43
+ "timezone",
44
+ "duration",
45
+ "string",
46
+ "slugify",
47
+ "array",
48
+ "object",
49
+ "deep-merge",
50
+ "debounce",
51
+ "throttle",
52
+ "memoize",
53
+ "uuid",
54
+ "ulid",
55
+ "nanoid",
56
+ "crypto",
57
+ "encryption",
58
+ "password-hashing"
59
+ ],
60
+ "homepage": "https://ix-xs.github.io/node-comfort/",
61
+ "bugs": {
62
+ "url": "https://github.com/ix-xs/node-comfort/issues"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "git+https://github.com/ix-xs/node-comfort.git"
67
+ },
68
+ "license": "MIT",
69
+ "author": "ix-xs",
70
+ "type": "commonjs",
71
+ "main": "./index.js",
72
+ "types": "./types/index.d.ts",
73
+ "exports": {
74
+ ".": {
75
+ "types": "./types/index.d.ts",
76
+ "default": "./index.js"
77
+ },
78
+ "./logger": {
79
+ "types": "./types/src/Logger.d.ts",
80
+ "default": "./src/Logger.js"
81
+ },
82
+ "./fs": {
83
+ "types": "./types/src/FS.d.ts",
84
+ "default": "./src/FS.js"
85
+ },
86
+ "./checker": {
87
+ "types": "./types/src/Checker.d.ts",
88
+ "default": "./src/Checker.js"
89
+ },
90
+ "./utils": {
91
+ "types": "./types/src/Utils.d.ts",
92
+ "default": "./src/Utils.js"
93
+ },
94
+ "./str": {
95
+ "types": "./types/src/Str.d.ts",
96
+ "default": "./src/Str.js"
97
+ },
98
+ "./num": {
99
+ "types": "./types/src/Num.d.ts",
100
+ "default": "./src/Num.js"
101
+ },
102
+ "./arr": {
103
+ "types": "./types/src/Arr.d.ts",
104
+ "default": "./src/Arr.js"
105
+ },
106
+ "./obj": {
107
+ "types": "./types/src/Obj.d.ts",
108
+ "default": "./src/Obj.js"
109
+ },
110
+ "./func": {
111
+ "types": "./types/src/Func.d.ts",
112
+ "default": "./src/Func.js"
113
+ },
114
+ "./time": {
115
+ "types": "./types/src/Time.d.ts",
116
+ "default": "./src/Time.js"
117
+ },
118
+ "./id": {
119
+ "types": "./types/src/Id.d.ts",
120
+ "default": "./src/Id.js"
121
+ },
122
+ "./crypto": {
123
+ "types": "./types/src/Crypto.d.ts",
124
+ "default": "./src/Crypto.js"
125
+ },
126
+ "./color": {
127
+ "types": "./types/src/Color.d.ts",
128
+ "default": "./src/Color.js"
129
+ },
130
+ "./cli": {
131
+ "types": "./types/src/Cli.d.ts",
132
+ "default": "./src/Cli.js"
133
+ },
134
+ "./sys": {
135
+ "types": "./types/src/Sys.d.ts",
136
+ "default": "./src/Sys.js"
137
+ },
138
+ "./async": {
139
+ "types": "./types/src/Async.d.ts",
140
+ "default": "./src/Async.js"
141
+ },
142
+ "./schema": {
143
+ "types": "./types/src/Schema.d.ts",
144
+ "default": "./src/Schema.js"
145
+ },
146
+ "./http": {
147
+ "types": "./types/src/Http.d.ts",
148
+ "default": "./src/Http.js"
149
+ },
150
+ "./env": {
151
+ "types": "./types/src/Env.d.ts",
152
+ "default": "./src/Env.js"
153
+ },
154
+ "./errors": {
155
+ "types": "./types/src/errors.d.ts",
156
+ "default": "./src/errors.js"
157
+ },
158
+ "./sqlite": {
159
+ "types": "./types/src/SQLite.d.ts",
160
+ "default": "./src/SQLite.js"
161
+ },
162
+ "./cache": {
163
+ "types": "./types/src/Cache.d.ts",
164
+ "default": "./src/Cache.js"
165
+ },
166
+ "./emitter": {
167
+ "types": "./types/src/Emitter.d.ts",
168
+ "default": "./src/Emitter.js"
169
+ },
170
+ "./package.json": "./package.json"
171
+ },
172
+ "files": [
173
+ "index.js",
174
+ "src/",
175
+ "types/",
176
+ "README.md",
177
+ "CHANGELOG.md",
178
+ "LICENSE"
179
+ ],
180
+ "engines": {
181
+ "node": ">=22.13.0"
182
+ },
183
+ "publishConfig": {
184
+ "access": "public"
185
+ },
186
+ "scripts": {
187
+ "build": "node scripts/build-types.js && node scripts/build-docs.js",
188
+ "build:types": "node scripts/build-types.js",
189
+ "build:docs": "node scripts/build-docs.js",
190
+ "build:site": "node scripts/build-site.js",
191
+ "site:serve": "node scripts/serve-site.js",
192
+ "test": "node --test \"test/**/*.test.js\"",
193
+ "test:types": "node scripts/check-types.js",
194
+ "check": "npm run build && npm run build:site && npm test && npm run test:types",
195
+ "prepublishOnly": "npm run check"
196
+ },
197
+ "devDependencies": {
198
+ "@types/node": "^22.13.0",
199
+ "typescript": "~6.0.3"
200
+ }
201
+ }