@gzl10/ts-helpers 4.2.1
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 +320 -0
- package/README.md +233 -0
- package/USAGE-GUIDE.md +800 -0
- package/dist/browser/async.js +15 -0
- package/dist/browser/async.js.map +1 -0
- package/dist/browser/chunk-4O7ZPIJN.js +383 -0
- package/dist/browser/chunk-4O7ZPIJN.js.map +1 -0
- package/dist/browser/chunk-75XNTC34.js +60 -0
- package/dist/browser/chunk-75XNTC34.js.map +1 -0
- package/dist/browser/chunk-C3D7YZVE.js +299 -0
- package/dist/browser/chunk-C3D7YZVE.js.map +1 -0
- package/dist/browser/chunk-CZL6C2EI.js +452 -0
- package/dist/browser/chunk-CZL6C2EI.js.map +1 -0
- package/dist/browser/chunk-D4FZFIVA.js +240 -0
- package/dist/browser/chunk-D4FZFIVA.js.map +1 -0
- package/dist/browser/chunk-IL7NG7IC.js +72 -0
- package/dist/browser/chunk-IL7NG7IC.js.map +1 -0
- package/dist/browser/chunk-NSBPE2FW.js +17 -0
- package/dist/browser/chunk-NSBPE2FW.js.map +1 -0
- package/dist/browser/chunk-SLQVNPTH.js +27 -0
- package/dist/browser/chunk-SLQVNPTH.js.map +1 -0
- package/dist/browser/chunk-WG7ILCUB.js +195 -0
- package/dist/browser/chunk-WG7ILCUB.js.map +1 -0
- package/dist/browser/chunk-WJA4JDMZ.js +278 -0
- package/dist/browser/chunk-WJA4JDMZ.js.map +1 -0
- package/dist/browser/chunk-ZFVYLUTT.js +65 -0
- package/dist/browser/chunk-ZFVYLUTT.js.map +1 -0
- package/dist/browser/chunk-ZYTSVMTI.js +263 -0
- package/dist/browser/chunk-ZYTSVMTI.js.map +1 -0
- package/dist/browser/dates.js +78 -0
- package/dist/browser/dates.js.map +1 -0
- package/dist/browser/environment-detection.js +21 -0
- package/dist/browser/environment-detection.js.map +1 -0
- package/dist/browser/environment.js +34 -0
- package/dist/browser/environment.js.map +1 -0
- package/dist/browser/errors.js +18 -0
- package/dist/browser/errors.js.map +1 -0
- package/dist/browser/index.js +412 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/math.js +51 -0
- package/dist/browser/math.js.map +1 -0
- package/dist/browser/number.js +10 -0
- package/dist/browser/number.js.map +1 -0
- package/dist/browser/objects.js +31 -0
- package/dist/browser/objects.js.map +1 -0
- package/dist/browser/strings.js +80 -0
- package/dist/browser/strings.js.map +1 -0
- package/dist/browser/validation-core.js +54 -0
- package/dist/browser/validation-core.js.map +1 -0
- package/dist/browser/validation-crypto.js +28 -0
- package/dist/browser/validation-crypto.js.map +1 -0
- package/dist/browser/validators.js +98 -0
- package/dist/browser/validators.js.map +1 -0
- package/dist/cjs/async.js +86 -0
- package/dist/cjs/async.js.map +1 -0
- package/dist/cjs/dates.js +285 -0
- package/dist/cjs/dates.js.map +1 -0
- package/dist/cjs/environment-detection.js +84 -0
- package/dist/cjs/environment-detection.js.map +1 -0
- package/dist/cjs/environment.js +261 -0
- package/dist/cjs/environment.js.map +1 -0
- package/dist/cjs/errors.js +80 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +2035 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/math.js +388 -0
- package/dist/cjs/math.js.map +1 -0
- package/dist/cjs/number.js +37 -0
- package/dist/cjs/number.js.map +1 -0
- package/dist/cjs/objects.js +249 -0
- package/dist/cjs/objects.js.map +1 -0
- package/dist/cjs/strings.js +253 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/validation.js +450 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/esm/async.js +15 -0
- package/dist/esm/async.js.map +1 -0
- package/dist/esm/chunk-4O7ZPIJN.js +383 -0
- package/dist/esm/chunk-4O7ZPIJN.js.map +1 -0
- package/dist/esm/chunk-75XNTC34.js +60 -0
- package/dist/esm/chunk-75XNTC34.js.map +1 -0
- package/dist/esm/chunk-BDOBKBKA.js +72 -0
- package/dist/esm/chunk-BDOBKBKA.js.map +1 -0
- package/dist/esm/chunk-C3D7YZVE.js +299 -0
- package/dist/esm/chunk-C3D7YZVE.js.map +1 -0
- package/dist/esm/chunk-CZL6C2EI.js +452 -0
- package/dist/esm/chunk-CZL6C2EI.js.map +1 -0
- package/dist/esm/chunk-EBLSTOEC.js +263 -0
- package/dist/esm/chunk-EBLSTOEC.js.map +1 -0
- package/dist/esm/chunk-NSBPE2FW.js +17 -0
- package/dist/esm/chunk-NSBPE2FW.js.map +1 -0
- package/dist/esm/chunk-SLQVNPTH.js +27 -0
- package/dist/esm/chunk-SLQVNPTH.js.map +1 -0
- package/dist/esm/chunk-WG7ILCUB.js +195 -0
- package/dist/esm/chunk-WG7ILCUB.js.map +1 -0
- package/dist/esm/chunk-WJA4JDMZ.js +278 -0
- package/dist/esm/chunk-WJA4JDMZ.js.map +1 -0
- package/dist/esm/chunk-ZFVYLUTT.js +65 -0
- package/dist/esm/chunk-ZFVYLUTT.js.map +1 -0
- package/dist/esm/dates.js +78 -0
- package/dist/esm/dates.js.map +1 -0
- package/dist/esm/environment-detection.js +21 -0
- package/dist/esm/environment-detection.js.map +1 -0
- package/dist/esm/environment.js +34 -0
- package/dist/esm/environment.js.map +1 -0
- package/dist/esm/errors.js +18 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +380 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/math.js +51 -0
- package/dist/esm/math.js.map +1 -0
- package/dist/esm/number.js +10 -0
- package/dist/esm/number.js.map +1 -0
- package/dist/esm/objects.js +31 -0
- package/dist/esm/objects.js.map +1 -0
- package/dist/esm/strings.js +80 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/validation.js +54 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/node/async.js +93 -0
- package/dist/node/async.js.map +1 -0
- package/dist/node/csv.js +102 -0
- package/dist/node/csv.js.map +1 -0
- package/dist/node/data.js +880 -0
- package/dist/node/data.js.map +1 -0
- package/dist/node/dates.js +324 -0
- package/dist/node/dates.js.map +1 -0
- package/dist/node/environment.js +278 -0
- package/dist/node/environment.js.map +1 -0
- package/dist/node/errors.js +89 -0
- package/dist/node/errors.js.map +1 -0
- package/dist/node/index.js +3151 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/json.js +107 -0
- package/dist/node/json.js.map +1 -0
- package/dist/node/math.js +413 -0
- package/dist/node/math.js.map +1 -0
- package/dist/node/number.js +42 -0
- package/dist/node/number.js.map +1 -0
- package/dist/node/objects.js +264 -0
- package/dist/node/objects.js.map +1 -0
- package/dist/node/strings.js +293 -0
- package/dist/node/strings.js.map +1 -0
- package/dist/node/tree.js +89 -0
- package/dist/node/tree.js.map +1 -0
- package/dist/node/validation-core.js +477 -0
- package/dist/node/validation-core.js.map +1 -0
- package/dist/node/validation-crypto.js +179 -0
- package/dist/node/validation-crypto.js.map +1 -0
- package/dist/node/validation.js +677 -0
- package/dist/node/validation.js.map +1 -0
- package/dist/node/validators.js +123 -0
- package/dist/node/validators.js.map +1 -0
- package/dist/node-esm/async.js +15 -0
- package/dist/node-esm/async.js.map +1 -0
- package/dist/node-esm/chunk-3YOF7NPT.js +299 -0
- package/dist/node-esm/chunk-3YOF7NPT.js.map +1 -0
- package/dist/node-esm/chunk-64TBXJQS.js +263 -0
- package/dist/node-esm/chunk-64TBXJQS.js.map +1 -0
- package/dist/node-esm/chunk-75XNTC34.js +60 -0
- package/dist/node-esm/chunk-75XNTC34.js.map +1 -0
- package/dist/node-esm/chunk-C4PKXIPB.js +278 -0
- package/dist/node-esm/chunk-C4PKXIPB.js.map +1 -0
- package/dist/node-esm/chunk-CMDFZME3.js +452 -0
- package/dist/node-esm/chunk-CMDFZME3.js.map +1 -0
- package/dist/node-esm/chunk-DZZPUYMP.js +74 -0
- package/dist/node-esm/chunk-DZZPUYMP.js.map +1 -0
- package/dist/node-esm/chunk-HTSEHRHI.js +195 -0
- package/dist/node-esm/chunk-HTSEHRHI.js.map +1 -0
- package/dist/node-esm/chunk-JCAUVOPH.js +27 -0
- package/dist/node-esm/chunk-JCAUVOPH.js.map +1 -0
- package/dist/node-esm/chunk-KBHE3K2F.js +505 -0
- package/dist/node-esm/chunk-KBHE3K2F.js.map +1 -0
- package/dist/node-esm/chunk-LYTET5NX.js +65 -0
- package/dist/node-esm/chunk-LYTET5NX.js.map +1 -0
- package/dist/node-esm/chunk-PZ5AY32C.js +10 -0
- package/dist/node-esm/chunk-PZ5AY32C.js.map +1 -0
- package/dist/node-esm/chunk-UKGXL2QO.js +383 -0
- package/dist/node-esm/chunk-UKGXL2QO.js.map +1 -0
- package/dist/node-esm/chunk-XAEYT23H.js +164 -0
- package/dist/node-esm/chunk-XAEYT23H.js.map +1 -0
- package/dist/node-esm/csv.js +63 -0
- package/dist/node-esm/csv.js.map +1 -0
- package/dist/node-esm/data.js +32 -0
- package/dist/node-esm/data.js.map +1 -0
- package/dist/node-esm/dates.js +78 -0
- package/dist/node-esm/dates.js.map +1 -0
- package/dist/node-esm/environment.js +34 -0
- package/dist/node-esm/environment.js.map +1 -0
- package/dist/node-esm/errors.js +18 -0
- package/dist/node-esm/errors.js.map +1 -0
- package/dist/node-esm/index.js +426 -0
- package/dist/node-esm/index.js.map +1 -0
- package/dist/node-esm/json.js +68 -0
- package/dist/node-esm/json.js.map +1 -0
- package/dist/node-esm/math.js +51 -0
- package/dist/node-esm/math.js.map +1 -0
- package/dist/node-esm/number.js +10 -0
- package/dist/node-esm/number.js.map +1 -0
- package/dist/node-esm/objects.js +31 -0
- package/dist/node-esm/objects.js.map +1 -0
- package/dist/node-esm/strings.js +80 -0
- package/dist/node-esm/strings.js.map +1 -0
- package/dist/node-esm/tree.js +8 -0
- package/dist/node-esm/tree.js.map +1 -0
- package/dist/node-esm/validation-core.js +54 -0
- package/dist/node-esm/validation-core.js.map +1 -0
- package/dist/node-esm/validation-crypto.js +26 -0
- package/dist/node-esm/validation-crypto.js.map +1 -0
- package/dist/node-esm/validation.js +606 -0
- package/dist/node-esm/validation.js.map +1 -0
- package/dist/node-esm/validators.js +98 -0
- package/dist/node-esm/validators.js.map +1 -0
- package/dist/types/async-C8gvbSG-.d.ts +453 -0
- package/dist/types/async.d.ts +1 -0
- package/dist/types/csv.d.ts +226 -0
- package/dist/types/data.d.ts +1561 -0
- package/dist/types/dates-hTiE0Z11.d.ts +298 -0
- package/dist/types/dates.d.ts +1 -0
- package/dist/types/environment-B8eLS7KT.d.ts +420 -0
- package/dist/types/environment-detection.d.ts +102 -0
- package/dist/types/environment.d.ts +1 -0
- package/dist/types/errors.d.ts +147 -0
- package/dist/types/index.d.ts +211 -0
- package/dist/types/json.d.ts +284 -0
- package/dist/types/math-BQ9Lwdp7.d.ts +2060 -0
- package/dist/types/math.d.ts +1 -0
- package/dist/types/number-CYnQfLWj.d.ts +44 -0
- package/dist/types/number.d.ts +1 -0
- package/dist/types/objects-BohS8GCS.d.ts +1185 -0
- package/dist/types/objects.d.ts +1 -0
- package/dist/types/strings-CiqRPYLL.d.ts +1349 -0
- package/dist/types/strings.d.ts +1 -0
- package/dist/types/tree.d.ts +284 -0
- package/dist/types/validation-core-DfHF8rCG.d.ts +238 -0
- package/dist/types/validation-crypto-browser.d.ts +56 -0
- package/dist/types/validation-crypto-node.d.ts +31 -0
- package/dist/types/validation.d.ts +1 -0
- package/dist/types/validators.d.ts +216 -0
- package/package.json +253 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export { b as generateAlphaNumericString, a as generateAlphaString, c as generateComplexString, l as generateEmail, n as generateHexColor, m as generatePassword, g as generateRandomInteger, i as generateSpanishCIF, k as generateSpanishIBAN, h as generateSpanishNIE, f as generateSpanishNIF, j as generateSpanishPostalCode, e as generateUsername, d as generateUsernameFromEmail, r as isValidCIF, u as isValidEmail, x as isValidJSON, q as isValidNIE, o as isValidNIF, y as isValidSpanishIBAN, t as isValidSpanishPhone, s as isValidSpanishPostalCode, w as isValidURL, p as validateNIF, v as validation } from './validation-core-DfHF8rCG.js';
|
|
2
|
+
export { j as capitalizeEachWord, i as capitalizeFirst, c as cleanJsonChars, o as contains, C as countOccurrences, q as endsWith, e as ensureEndsWith, d as ensureStartsWith, K as envKeyToPath, H as escapeHtmlChars, E as isEmail, D as isEmpty, J as matchPathPattern, v as padEnd, r as padStart, L as pathToEnvKey, G as removeAccents, A as repeatString, B as replaceAllOccurrences, z as reverseString, a as sanitizeString, p as startsWith, s as strings, b as stripFromEnd, f as stripFromStart, k as toCamelCase, m as toKebabCase, g as toLowerCase, n as toPascalCase, l as toSnakeCase, h as toUpperCase, F as toUrlSlug, w as trim, y as trimEnd, x as trimStart, t as truncateString, I as unescapeHtmlChars, u as unescapeUnicode } from './strings-CiqRPYLL.js';
|
|
3
|
+
export { a as calculateDifferences, c as comparator, d as deepEqual, i as deleteArrayElementsBy, f as formatToReadableString, b as generateCrcHash, j as getDeepValue, g as getShallowProperties, h as hasSameType, o as objects, s as setDeepValue, e as updateArrayElementById, u as updateArrayElementsBy } from './objects-BohS8GCS.js';
|
|
4
|
+
export { p as addDays, v as addMonths, s as addNowDays, x as addNowMonths, u as addNowSeconds, z as addNowYears, q as addSeconds, y as addYears, r as areDatesEqualWithTolerance, d as dates, g as dayOfWeek, j as diffBusinessDays, h as diffDays, o as diffMilliSeconds, k as diffMonths, m as diffYears, A as excelToDate, a as format, E as formatForMysql, f as formatNow, e as fromNow, I as getFirstDayOfYear, H as getFirstWorkdayAfterMonths, F as getFirstWorkdayOfMonth, J as getLastDayOfYear, G as getLastWorkdayOfMonth, B as isDateTime, C as isEqualsDateTimeByDay, D as isExpired, i as isNew, K as isWeekday, l as longString, n as now, t as toDate, b as toDateFromString, c as toISO, w as weekOfYear } from './dates-hTiE0Z11.js';
|
|
5
|
+
import { I as IMathOp } from './math-BQ9Lwdp7.js';
|
|
6
|
+
export { c as calculateAggregations, q as calculateAnnuityPayment, k as calculateCorrelation, u as calculateEuclideanDistance, o as calculateFutureValue, t as calculateHistogram, i as calculateIQR, n as calculateIRR, v as calculateManhattanDistance, b as calculateMedian, d as calculateMode, l as calculateNPV, g as calculatePercentile, p as calculatePresentValue, h as calculateQuartiles, e as calculateStandardDeviation, a as calculateTrendSlope, f as calculateVariance, j as detectOutliers, m as math, r as normalizeToRange, s as scaleToRange, w as simpleKMeans } from './math-BQ9Lwdp7.js';
|
|
7
|
+
export { a as async, h as handleOperation, r as runBatch, s as sleep, w as wait } from './async-C8gvbSG-.js';
|
|
8
|
+
import { i as isBrowserEnvironment, a as isNodeEnvironment, E as EnvironmentInfo } from './environment-B8eLS7KT.js';
|
|
9
|
+
export { b as EnvironmentCriteria, j as detectHostname, h as detectProtocol, e as environment, m as getEnvironmentInfo, o as isBrowser, c as isDevelopment, k as isLocalhost, n as isNode, g as isNonProduction, l as isPrivateIP, d as isProduction, f as isTest, p as parseEnvValue } from './environment-B8eLS7KT.js';
|
|
10
|
+
export { i as isNumericValue, n as number, r as roundToDecimals } from './number-CYnQfLWj.js';
|
|
11
|
+
export { getCryptoCapabilities, getEnvironmentType, isBrowserEnv, isNodeCryptoAvailable, isNodeEnv, isWebCryptoAvailable, isWorkerEnvironment } from './environment-detection.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Universal exports - Safe for all environments
|
|
15
|
+
* No crypto dependencies - browser and Node.js compatible
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare const g: {
|
|
19
|
+
isBrowserEnv: typeof isBrowserEnvironment;
|
|
20
|
+
isNodeEnv: typeof isNodeEnvironment;
|
|
21
|
+
isWorkerEnvironment: () => boolean;
|
|
22
|
+
isWebCryptoAvailable: () => boolean;
|
|
23
|
+
isNodeCryptoAvailable: () => boolean;
|
|
24
|
+
getEnvironmentType: () => "node" | "browser" | "worker" | "unknown";
|
|
25
|
+
getCryptoCapabilities: () => {
|
|
26
|
+
webCrypto: boolean;
|
|
27
|
+
nodeCrypto: boolean;
|
|
28
|
+
fallbackOnly: boolean;
|
|
29
|
+
environment: "node" | "browser" | "worker" | "unknown";
|
|
30
|
+
};
|
|
31
|
+
isNodeEnvironment(): boolean;
|
|
32
|
+
isBrowserEnvironment(): boolean;
|
|
33
|
+
isDevelopment(req?: any): boolean;
|
|
34
|
+
isProduction(): boolean;
|
|
35
|
+
isTest(): boolean;
|
|
36
|
+
isNonProduction(): boolean;
|
|
37
|
+
detectProtocol(req?: any): "http" | "https";
|
|
38
|
+
detectHostname(req?: any): string;
|
|
39
|
+
isLocalhost(hostname: string): boolean;
|
|
40
|
+
isPrivateIP(hostname: string): boolean;
|
|
41
|
+
getEnvironmentInfo(req?: any): EnvironmentInfo;
|
|
42
|
+
parseEnvValue(value: string | undefined): any;
|
|
43
|
+
isNode: typeof isNodeEnvironment;
|
|
44
|
+
isBrowser: typeof isBrowserEnvironment;
|
|
45
|
+
isNumericValue(value: any): boolean;
|
|
46
|
+
roundToDecimals(num: number, decimals?: number): number;
|
|
47
|
+
runBatch<T>(jobs: Promise<T>[], batchSize?: number): Promise<T[]>;
|
|
48
|
+
handleOperation<T>(target: Record<string, any>, operation: string, ...args: any[]): Promise<T>;
|
|
49
|
+
sleep: (ms: number) => Promise<void>;
|
|
50
|
+
wait: (ms: number) => Promise<void>;
|
|
51
|
+
calculateTrendSlope(y: number[], x: number[]): number;
|
|
52
|
+
calculateAggregations: (operations: IMathOp, pgroupBy: string[], inData: any[], appendOperationToField?: boolean) => any;
|
|
53
|
+
calculateMedian: (values: number[]) => number;
|
|
54
|
+
calculateMode: (values: number[]) => number | null;
|
|
55
|
+
calculateStandardDeviation: (values: number[], sample?: boolean) => number;
|
|
56
|
+
calculateVariance: (values: number[], sample?: boolean) => number;
|
|
57
|
+
calculatePercentile: (values: number[], percentile: number) => number;
|
|
58
|
+
calculateQuartiles: (values: number[]) => {
|
|
59
|
+
Q1: number;
|
|
60
|
+
Q2: number;
|
|
61
|
+
Q3: number;
|
|
62
|
+
};
|
|
63
|
+
calculateIQR: (values: number[]) => number;
|
|
64
|
+
detectOutliers: (values: number[], multiplier?: number) => number[];
|
|
65
|
+
calculateCorrelation: (x: number[], y: number[]) => number;
|
|
66
|
+
calculateNPV: (cashFlows: number[], discountRate: number) => number;
|
|
67
|
+
calculateIRR: (cashFlows: number[], initialGuess?: number, maxIterations?: number, tolerance?: number) => number;
|
|
68
|
+
calculateFutureValue: (presentValue: number, interestRate: number, periods: number) => number;
|
|
69
|
+
calculatePresentValue: (futureValue: number, interestRate: number, periods: number) => number;
|
|
70
|
+
calculateAnnuityPayment: (presentValue: number, interestRate: number, periods: number) => number;
|
|
71
|
+
normalizeToRange: (values: number[]) => number[];
|
|
72
|
+
scaleToRange: (values: number[], minRange: number, maxRange: number) => number[];
|
|
73
|
+
calculateHistogram: (values: number[], bins: number) => Array<{
|
|
74
|
+
range: [number, number];
|
|
75
|
+
count: number;
|
|
76
|
+
}>;
|
|
77
|
+
calculateEuclideanDistance: (point1: number[], point2: number[]) => number;
|
|
78
|
+
calculateManhattanDistance: (point1: number[], point2: number[]) => number;
|
|
79
|
+
simpleKMeans: (points: number[][], k: number, maxIterations?: number) => {
|
|
80
|
+
centroids: number[][];
|
|
81
|
+
clusters: number[];
|
|
82
|
+
};
|
|
83
|
+
formatNow: (formatStr?: string) => string;
|
|
84
|
+
format: (value: any, formatStr?: string) => string;
|
|
85
|
+
longString: (value?: any) => string;
|
|
86
|
+
toDate: (value: any, isUtc?: boolean) => Date;
|
|
87
|
+
toDateFromString: (dateString: string, format: "DD/MM/YYYY" | "YYYY-MM-DD" | "MM/DD/YYYY" | "YYYY/MM/DD" | "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYYMMDD" | "DDMMYYYY" | "MMDDYYYY" | "YYYY.MM.DD" | "DD.MM.YYYY" | "MM.DD.YYYY") => Date | null;
|
|
88
|
+
now: () => Date;
|
|
89
|
+
isNew: (value: any, daysnew?: number) => boolean;
|
|
90
|
+
toISO: (value?: any, isUtc?: boolean) => string;
|
|
91
|
+
fromNow: (value: any) => string;
|
|
92
|
+
dayOfWeek: (value?: any) => string;
|
|
93
|
+
weekOfYear: (value?: any) => string;
|
|
94
|
+
diffDays: (start: any, end?: any, precise?: boolean) => number;
|
|
95
|
+
diffBusinessDays: (start: any, end?: any, precise?: boolean) => number;
|
|
96
|
+
diffMonths: (value: any, valueRefOrNow?: any, precise?: boolean) => number;
|
|
97
|
+
diffYears: (value: any, valueRefOrNow?: any, precise?: boolean) => number;
|
|
98
|
+
diffMilliSeconds: (value: any, valueRefOrNow?: any) => number;
|
|
99
|
+
addDays: (value: any, nDays?: number) => Date;
|
|
100
|
+
addSeconds: (value: any, nSeconds?: number) => Date;
|
|
101
|
+
areDatesEqualWithTolerance: (date1: Date, date2: Date) => boolean;
|
|
102
|
+
addNowDays: (nDays?: number) => Date;
|
|
103
|
+
addNowSeconds: (nSeconds?: number) => Date;
|
|
104
|
+
addMonths: (value: any, nMonths?: number) => Date;
|
|
105
|
+
addNowMonths: (nMonths?: number) => Date;
|
|
106
|
+
addYears: (value: any, nYears?: number) => Date;
|
|
107
|
+
addNowYears: (nYears?: number) => Date;
|
|
108
|
+
excelToDate: (value: any) => Date | null;
|
|
109
|
+
isDateTime: (value: any) => boolean;
|
|
110
|
+
isEqualsDateTimeByDay: (value1: any, value2: any) => boolean;
|
|
111
|
+
isExpired: (value: any, valueRefOrNow?: any) => boolean;
|
|
112
|
+
formatForMysql: (fecha: Date | null) => string | null;
|
|
113
|
+
getFirstWorkdayOfMonth: (month?: number) => Date;
|
|
114
|
+
getLastWorkdayOfMonth: (month?: number) => Date;
|
|
115
|
+
getFirstWorkdayAfterMonths: (initialDate: Date, n: number) => Date;
|
|
116
|
+
getFirstDayOfYear: () => Date;
|
|
117
|
+
getLastDayOfYear: () => Date;
|
|
118
|
+
isWeekday: (date: any) => boolean;
|
|
119
|
+
setDeepValue<T = any>(obj: T, path: string, value: any): T;
|
|
120
|
+
getDeepValue<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
|
|
121
|
+
comparator: (data1: any, data2: any) => boolean;
|
|
122
|
+
deepEqual: (data1: any, data2: any) => boolean;
|
|
123
|
+
formatToReadableString: (data: {
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
}) => string;
|
|
126
|
+
getShallowProperties: (obj: any) => any;
|
|
127
|
+
calculateDifferences: (oldObj: any, newObj: any) => any;
|
|
128
|
+
generateCrcHash: (str: string | Buffer | Uint8Array | any) => string;
|
|
129
|
+
hasSameType: (sourceTarget: any, destinationTarget: any) => boolean;
|
|
130
|
+
updateArrayElementsBy: (data: any[], objUpd: any, objSearch: any) => any[];
|
|
131
|
+
updateArrayElementById: (data: any[], objUpd: any, idField: string) => void;
|
|
132
|
+
deleteArrayElementsBy: (data: any[], objSearch: any) => any[];
|
|
133
|
+
matchPathPattern(path: string, pattern: string): boolean;
|
|
134
|
+
envKeyToPath(envKey: string, prefix?: string): string;
|
|
135
|
+
pathToEnvKey(path: string, prefix?: string): string;
|
|
136
|
+
sanitizeString: (instr: string | null) => string;
|
|
137
|
+
cleanJsonChars: (texto: string | null) => string;
|
|
138
|
+
truncateString: (str: string, maxlength?: number, suffix?: string) => string;
|
|
139
|
+
unescapeUnicode: (input: string) => string;
|
|
140
|
+
ensureEndsWith: (str: string, trailing: string) => string;
|
|
141
|
+
stripFromEnd: (str: string, trailing: string) => string;
|
|
142
|
+
ensureStartsWith: (str: string, leading: string) => string;
|
|
143
|
+
stripFromStart: (str: string, leading: string) => string;
|
|
144
|
+
toLowerCase: (str: string) => string;
|
|
145
|
+
toUpperCase: (str: string) => string;
|
|
146
|
+
capitalizeFirst: (str: string) => string;
|
|
147
|
+
capitalizeEachWord: (str: string) => string;
|
|
148
|
+
toCamelCase: (str: string) => string;
|
|
149
|
+
toSnakeCase: (str: string) => string;
|
|
150
|
+
toKebabCase: (str: string) => string;
|
|
151
|
+
toPascalCase: (str: string) => string;
|
|
152
|
+
contains: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
|
|
153
|
+
startsWith: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
|
|
154
|
+
endsWith: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
|
|
155
|
+
padStart: (str: string, length: number, padChar?: string) => string;
|
|
156
|
+
padEnd: (str: string, length: number, padChar?: string) => string;
|
|
157
|
+
trim: (str: string) => string;
|
|
158
|
+
trimStart: (str: string) => string;
|
|
159
|
+
trimEnd: (str: string) => string;
|
|
160
|
+
reverseString: (str: string) => string;
|
|
161
|
+
repeatString: (str: string, times: number) => string;
|
|
162
|
+
replaceAllOccurrences: (str: string, searchStr: string, replaceStr: string) => string;
|
|
163
|
+
countOccurrences: (str: string, searchStr: string) => number;
|
|
164
|
+
isEmpty: (str: string | null | undefined) => boolean;
|
|
165
|
+
isEmail: (str: string) => boolean;
|
|
166
|
+
toUrlSlug: (str: string) => string;
|
|
167
|
+
removeAccents: (str: string) => string;
|
|
168
|
+
escapeHtmlChars: (str: string) => string;
|
|
169
|
+
unescapeHtmlChars: (str: string) => string;
|
|
170
|
+
generateRandomInteger: (min?: number, max?: number) => number;
|
|
171
|
+
generateAlphaString: (options?: {
|
|
172
|
+
length?: number;
|
|
173
|
+
casing?: "upper" | "lower" | undefined;
|
|
174
|
+
}) => string;
|
|
175
|
+
generateAlphaNumericString: (options?: {
|
|
176
|
+
length?: number;
|
|
177
|
+
casing?: "upper" | "lower" | undefined;
|
|
178
|
+
}) => string;
|
|
179
|
+
generateComplexString: (options?: {
|
|
180
|
+
length?: number;
|
|
181
|
+
casing?: "upper" | "lower" | undefined;
|
|
182
|
+
}) => string;
|
|
183
|
+
generateUsernameFromEmail: (email: string, randomDigits?: number) => string;
|
|
184
|
+
generateUsername: (separator?: string, randomDigits?: number, length?: number) => string;
|
|
185
|
+
generateSpanishNIF: () => string;
|
|
186
|
+
generateSpanishNIE: () => string;
|
|
187
|
+
generateSpanishCIF: () => string;
|
|
188
|
+
generateSpanishPostalCode: () => string;
|
|
189
|
+
generateSpanishIBAN: () => string;
|
|
190
|
+
generateEmail: (domain?: string) => string;
|
|
191
|
+
generatePassword: (options?: {
|
|
192
|
+
length?: number;
|
|
193
|
+
includeUppercase?: boolean;
|
|
194
|
+
includeLowercase?: boolean;
|
|
195
|
+
includeNumbers?: boolean;
|
|
196
|
+
includeSymbols?: boolean;
|
|
197
|
+
}) => string;
|
|
198
|
+
generateHexColor: (shortFormat?: boolean) => string;
|
|
199
|
+
isValidNIF: (nif: string) => boolean;
|
|
200
|
+
validateNIF: (nif: string) => boolean;
|
|
201
|
+
isValidNIE: (nie: string) => boolean;
|
|
202
|
+
isValidCIF: (cif: string) => boolean;
|
|
203
|
+
isValidSpanishPostalCode: (postalCode: string) => boolean;
|
|
204
|
+
isValidSpanishPhone: (phone: string) => boolean;
|
|
205
|
+
isValidEmail: (email: string) => boolean;
|
|
206
|
+
isValidURL: (url: string) => boolean;
|
|
207
|
+
isValidJSON: (str: string) => boolean;
|
|
208
|
+
isValidSpanishIBAN: (iban: string) => boolean;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export { EnvironmentInfo, IMathOp, g as default, isBrowserEnvironment, isNodeEnvironment };
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Import/Export utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides reliable JSON file operations for both Node.js and Browser environments.
|
|
5
|
+
* Features:
|
|
6
|
+
* - UTF-8 encoding for international character support
|
|
7
|
+
* - Pretty-printing with configurable indentation
|
|
8
|
+
* - Dual-mode: filesystem (Node.js) vs download trigger (Browser)
|
|
9
|
+
* - Native JSON.stringify/parse for maximum compatibility
|
|
10
|
+
*
|
|
11
|
+
* @module json
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Exports data as JSON file with UTF-8 encoding
|
|
15
|
+
*
|
|
16
|
+
* Works in both Node.js (writes to filesystem) and Browser (triggers download).
|
|
17
|
+
* Uses native JSON.stringify for serialization with optional pretty-printing.
|
|
18
|
+
*
|
|
19
|
+
* Features:
|
|
20
|
+
* - UTF-8 encoding for international characters
|
|
21
|
+
* - Configurable indentation (default: 2 spaces)
|
|
22
|
+
* - Automatic filename extraction in browser
|
|
23
|
+
* - Pretty-printed by default for readability
|
|
24
|
+
*
|
|
25
|
+
* Environment behavior:
|
|
26
|
+
* - **Node.js**: Writes file to filesystem at specified path
|
|
27
|
+
* - **Browser**: Triggers automatic download with filename extracted from path
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ WARNING: Cannot serialize:
|
|
30
|
+
* - Functions (removed silently)
|
|
31
|
+
* - Symbols (removed silently)
|
|
32
|
+
* - Circular references (throws TypeError)
|
|
33
|
+
* - undefined values (removed from objects, converted to null in arrays)
|
|
34
|
+
* - BigInt values (throws TypeError unless custom replacer provided)
|
|
35
|
+
*
|
|
36
|
+
* @param data - Any serializable JavaScript value (object, array, primitive)
|
|
37
|
+
* @param filePath - File path (Node.js) or download filename (Browser)
|
|
38
|
+
* @param options - Export options (optional)
|
|
39
|
+
* @param options.indent - Number of spaces for indentation (default: 2, use 0 for compact)
|
|
40
|
+
* @returns Promise that resolves when export completes
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Basic export - Object
|
|
45
|
+
* const config = {
|
|
46
|
+
* database: { host: 'localhost', port: 5432 },
|
|
47
|
+
* features: { auth: true, payments: false }
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Node.js - Write to file
|
|
51
|
+
* await exportJSON(config, './config/app.json')
|
|
52
|
+
* // Creates: ./config/app.json with 2-space indentation
|
|
53
|
+
*
|
|
54
|
+
* // Browser - Trigger download
|
|
55
|
+
* await exportJSON(config, 'app-config.json')
|
|
56
|
+
* // Downloads: app-config.json to browser's download folder
|
|
57
|
+
*
|
|
58
|
+
* // Compact output (no pretty-printing)
|
|
59
|
+
* await exportJSON(config, 'config.json', { indent: 0 })
|
|
60
|
+
* // Single-line JSON: {"database":{"host":"localhost","port":5432}}
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Array export
|
|
66
|
+
* const users = [
|
|
67
|
+
* { id: 1, name: 'Alice', email: 'alice@example.com' },
|
|
68
|
+
* { id: 2, name: 'Bob', email: 'bob@example.com' }
|
|
69
|
+
* ]
|
|
70
|
+
* await exportJSON(users, 'users.json')
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Real-world: Configuration backup system
|
|
76
|
+
* async function backupConfiguration(config: AppConfig) {
|
|
77
|
+
* const timestamp = new Date().toISOString().split('T')[0]
|
|
78
|
+
* const filename = `config-backup-${timestamp}.json`
|
|
79
|
+
*
|
|
80
|
+
* try {
|
|
81
|
+
* await exportJSON(config, `./backups/${filename}`, { indent: 2 })
|
|
82
|
+
* console.log(`✅ Configuration backed up to ${filename}`)
|
|
83
|
+
* } catch (error) {
|
|
84
|
+
* console.error('❌ Backup failed:', error)
|
|
85
|
+
* throw error
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Real-world: Export API response for debugging
|
|
93
|
+
* async function debugApiResponse(endpoint: string, data: any) {
|
|
94
|
+
* const filename = `api-${endpoint.replace(/\//g, '-')}.json`
|
|
95
|
+
* await exportJSON({
|
|
96
|
+
* endpoint,
|
|
97
|
+
* timestamp: new Date().toISOString(),
|
|
98
|
+
* data
|
|
99
|
+
* }, filename)
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Handle circular references
|
|
106
|
+
* const obj = { name: 'test' }
|
|
107
|
+
* obj.self = obj // Circular reference
|
|
108
|
+
*
|
|
109
|
+
* try {
|
|
110
|
+
* await exportJSON(obj, 'circular.json')
|
|
111
|
+
* } catch (error) {
|
|
112
|
+
* console.error('Cannot serialize circular structure')
|
|
113
|
+
* // Use custom replacer to handle circular refs
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Different indentation levels
|
|
120
|
+
* await exportJSON(data, 'compact.json', { indent: 0 }) // Single line
|
|
121
|
+
* await exportJSON(data, 'readable.json', { indent: 2 }) // 2 spaces (default)
|
|
122
|
+
* await exportJSON(data, 'spacious.json', { indent: 4 }) // 4 spaces
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @throws {TypeError} If data contains circular references or BigInt values
|
|
126
|
+
* @throws {Error} If file write fails in Node.js (permissions, disk space, etc.)
|
|
127
|
+
* @see {@link importJSON} for importing JSON files
|
|
128
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify JSON.stringify Documentation}
|
|
129
|
+
*/
|
|
130
|
+
declare function exportJSON(data: any, filePath: string, options?: {
|
|
131
|
+
indent?: number;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Imports JSON file and parses it to JavaScript value
|
|
135
|
+
*
|
|
136
|
+
* Reads JSON file from filesystem (Node.js only) and parses using native JSON.parse.
|
|
137
|
+
* Returns the parsed JavaScript value (object, array, primitive).
|
|
138
|
+
*
|
|
139
|
+
* Features:
|
|
140
|
+
* - UTF-8 encoding support for international characters
|
|
141
|
+
* - Native JSON.parse for standard-compliant parsing
|
|
142
|
+
* - Automatic type inference
|
|
143
|
+
* - Whitespace and comment tolerance (standard JSON only)
|
|
144
|
+
*
|
|
145
|
+
* ⚠️ BROWSER LIMITATION: File reading from filesystem is not supported in browsers
|
|
146
|
+
* for security reasons. For browser file uploads, use `readFileAsText()` with a File object
|
|
147
|
+
* obtained from an input[type="file"] element.
|
|
148
|
+
*
|
|
149
|
+
* @param filePath - Path to JSON file (Node.js only)
|
|
150
|
+
* @param _options - Reserved for future options (currently unused)
|
|
151
|
+
* @returns Promise<any> Parsed JavaScript value (object, array, primitive, null)
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Basic import - Node.js only
|
|
156
|
+
* const config = await importJSON('./config/app.json')
|
|
157
|
+
* // Returns: { database: { host: 'localhost', port: 5432 }, ... }
|
|
158
|
+
*
|
|
159
|
+
* console.log(config.database.host) // 'localhost'
|
|
160
|
+
*
|
|
161
|
+
* // Array import
|
|
162
|
+
* const users = await importJSON('./data/users.json')
|
|
163
|
+
* // Returns: [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
|
|
164
|
+
*
|
|
165
|
+
* // Primitive values (valid JSON)
|
|
166
|
+
* const version = await importJSON('./version.json') // "1.2.3"
|
|
167
|
+
* const enabled = await importJSON('./feature.json') // true
|
|
168
|
+
* const count = await importJSON('./count.json') // 42
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Real-world: Load configuration with fallback
|
|
174
|
+
* async function loadConfiguration(configPath: string): Promise<AppConfig> {
|
|
175
|
+
* try {
|
|
176
|
+
* const config = await importJSON(configPath)
|
|
177
|
+
*
|
|
178
|
+
* // Validate loaded config
|
|
179
|
+
* if (!config.database || !config.database.host) {
|
|
180
|
+
* throw new Error('Invalid configuration: missing database.host')
|
|
181
|
+
* }
|
|
182
|
+
*
|
|
183
|
+
* return config
|
|
184
|
+
* } catch (error) {
|
|
185
|
+
* console.warn(`Failed to load config from ${configPath}:`, error)
|
|
186
|
+
* console.log('Using default configuration')
|
|
187
|
+
* return getDefaultConfig()
|
|
188
|
+
* }
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Real-world: Restore configuration backup
|
|
195
|
+
* async function restoreBackup(backupFile: string) {
|
|
196
|
+
* console.log(`Restoring configuration from ${backupFile}...`)
|
|
197
|
+
*
|
|
198
|
+
* const backup = await importJSON(`./backups/${backupFile}`)
|
|
199
|
+
*
|
|
200
|
+
* // Verify backup integrity
|
|
201
|
+
* if (!backup.timestamp || !backup.config) {
|
|
202
|
+
* throw new Error('Invalid backup file format')
|
|
203
|
+
* }
|
|
204
|
+
*
|
|
205
|
+
* // Restore configuration
|
|
206
|
+
* await saveConfiguration(backup.config)
|
|
207
|
+
*
|
|
208
|
+
* console.log(`✅ Configuration restored from ${backup.timestamp}`)
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* // Browser alternative using File API
|
|
215
|
+
* // HTML: <input type="file" id="jsonFile" accept=".json">
|
|
216
|
+
*
|
|
217
|
+
* document.getElementById('jsonFile').addEventListener('change', async (e) => {
|
|
218
|
+
* const file = e.target.files[0]
|
|
219
|
+
*
|
|
220
|
+
* // Read file content
|
|
221
|
+
* const content = await readFileAsText(file)
|
|
222
|
+
*
|
|
223
|
+
* // Parse JSON
|
|
224
|
+
* try {
|
|
225
|
+
* const data = JSON.parse(content)
|
|
226
|
+
* console.log('Imported JSON:', data)
|
|
227
|
+
* } catch (error) {
|
|
228
|
+
* console.error('Invalid JSON file:', error)
|
|
229
|
+
* }
|
|
230
|
+
* })
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // Handle parsing errors
|
|
236
|
+
* async function safeImportJSON(filePath: string): Promise<any | null> {
|
|
237
|
+
* try {
|
|
238
|
+
* return await importJSON(filePath)
|
|
239
|
+
* } catch (error) {
|
|
240
|
+
* if (error.message.includes('not supported in browser')) {
|
|
241
|
+
* console.error('Use File API for browser uploads')
|
|
242
|
+
* } else if (error.code === 'ENOENT') {
|
|
243
|
+
* console.error(`File not found: ${filePath}`)
|
|
244
|
+
* } else if (error instanceof SyntaxError) {
|
|
245
|
+
* console.error(`Invalid JSON syntax in ${filePath}:`, error.message)
|
|
246
|
+
* } else {
|
|
247
|
+
* console.error('JSON import failed:', error)
|
|
248
|
+
* }
|
|
249
|
+
* return null
|
|
250
|
+
* }
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Type-safe import with validation
|
|
257
|
+
* interface DatabaseConfig {
|
|
258
|
+
* host: string
|
|
259
|
+
* port: number
|
|
260
|
+
* database: string
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* async function loadDatabaseConfig(path: string): Promise<DatabaseConfig> {
|
|
264
|
+
* const raw = await importJSON(path)
|
|
265
|
+
*
|
|
266
|
+
* // Runtime validation
|
|
267
|
+
* if (typeof raw.host !== 'string' || typeof raw.port !== 'number') {
|
|
268
|
+
* throw new Error('Invalid database configuration structure')
|
|
269
|
+
* }
|
|
270
|
+
*
|
|
271
|
+
* return raw as DatabaseConfig
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @throws {Error} 'JSON import not supported in browser' when called in browser environment
|
|
276
|
+
* @throws {SyntaxError} If file contains invalid JSON syntax
|
|
277
|
+
* @throws {Error} File system errors (ENOENT, EACCES, etc.) in Node.js
|
|
278
|
+
* @see {@link exportJSON} for exporting JSON files
|
|
279
|
+
* @see {@link readFileAsText} for browser file reading
|
|
280
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse Documentation}
|
|
281
|
+
*/
|
|
282
|
+
declare function importJSON(filePath: string, _options?: any): Promise<any>;
|
|
283
|
+
|
|
284
|
+
export { exportJSON, importJSON };
|