@lichens-innovation/ts-common 1.16.0 → 1.18.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/dist/index.d.cts CHANGED
@@ -1,4 +1,7 @@
1
- export { D as Dimensions } from './dimensions.utils-BwIBA5op.cjs';
1
+ export { D as Dimensions, N as NormalizedRgb, R as RgbColor, a as RgbaColor, l as getColorForPercentage, i as getContrastTextColor, f as getLuminance, g as getOpacityHexValue, j as hexToNormalizedRgb, h as hexToRgb, k as isLightColor, r as rgbToHex, d as rgbToString, b as rgbaToHex, c as rgbaToHexWithAlpha, e as rgbaToString } from './dimensions.utils-BSm9gmWz.cjs';
2
+
3
+ declare const encodeBase64: (text: string) => string;
4
+ declare const decodeBase64: (base64: string) => string;
2
5
 
3
6
  interface ToleranceArea {
4
7
  flow: number;
@@ -46,47 +49,6 @@ declare const roundToNiceNumber: (rawValue: number) => number;
46
49
  */
47
50
  declare const buildTicksForChart: (max: number, targetTickCount?: number) => number[];
48
51
 
49
- interface RgbColor {
50
- r: number;
51
- g: number;
52
- b: number;
53
- }
54
- interface RgbaColor extends RgbColor {
55
- a: number;
56
- }
57
- declare const rgbToHex: (r: number, g: number, b: number) => string;
58
- declare const hexToRgb: (hex: string) => RgbColor;
59
- declare const rgbaToHex: (color: RgbaColor) => string;
60
- declare const getOpacityHexValue: (opacity: number) => string;
61
- declare const rgbaToHexWithAlpha: (color: RgbaColor) => string;
62
- declare const rgbToString: (color: RgbColor) => string;
63
- declare const rgbaToString: (color: RgbaColor) => string;
64
- declare const getLuminance: (r: number, g: number, b: number) => number;
65
- declare const getContrastTextColor: (hexColor: string) => string;
66
- /**
67
- * Normalized RGB color with values between 0 and 1.
68
- * Useful for graphics libraries like Three.js.
69
- */
70
- interface NormalizedRgb {
71
- r: number;
72
- g: number;
73
- b: number;
74
- }
75
- /**
76
- * Convert a hex color string to normalized RGB values (0-1 range).
77
- * @param hex - Hex color string (with or without # prefix)
78
- * @returns Normalized RGB object with values between 0 and 1
79
- */
80
- declare const hexToNormalizedRgb: (hex: string) => NormalizedRgb;
81
- /**
82
- * Determine if a color is light or dark based on relative luminance.
83
- * Useful for choosing contrasting text colors.
84
- * @param hex - Hex color string
85
- * @returns True if the color is considered light (luminance > 0.5)
86
- */
87
- declare const isLightColor: (hex: string) => boolean;
88
- declare const getColorForPercentage: (percent: number) => string;
89
-
90
52
  type DateInput = Date | string | number | null;
91
53
  declare const dateAs_HHMMSS: (value?: DateInput) => string;
92
54
  declare const dateAs_YYYYMMDD: (value?: DateInput) => string;
@@ -133,10 +95,27 @@ declare const toFormString: (n?: number | null) => string;
133
95
  */
134
96
  declare const toFormStringInteger: (n?: number | null) => string;
135
97
 
98
+ declare const escapeHtml: (text: string) => string;
99
+ declare const unescapeHtml: (text: string) => string;
100
+
136
101
  declare const isHttpSuccessStatus: (status?: number | null) => boolean;
137
102
  declare const isHttpClientErrorStatus: (status?: number | null) => boolean;
138
103
  declare const isHttpServerErrorStatus: (status?: number | null) => boolean;
139
104
 
105
+ declare const safeJsonParse: <T>(value: string, fallback?: T) => T | undefined;
106
+ declare const safeJsonStringify: (obj: unknown, space?: number) => string;
107
+ declare const sortObjectKeys: (_key: string, value: unknown) => unknown;
108
+ interface FormatJsonArgs {
109
+ value?: string;
110
+ space?: number;
111
+ sortKeys?: boolean;
112
+ }
113
+ declare const formatJson: ({ value, space, sortKeys }: FormatJsonArgs) => string;
114
+ declare const prettifyJson: (value?: string) => string;
115
+ declare const minifyJson: (value?: string) => string;
116
+ declare const isValidJson: (value: string) => boolean;
117
+ declare const isMinifiedJson: (value: string) => boolean;
118
+
140
119
  /**
141
120
  * Returns true if the input string is a valid number (blank and non-numeric strings are invalid).
142
121
  */
@@ -159,6 +138,14 @@ declare const isInputValidNegativeInteger: (value: string) => boolean;
159
138
  declare const formatIntegerDisplay: (value?: number | null) => string;
160
139
  declare const toFixed: (value?: number | null, decimals?: number) => number;
161
140
  declare const roundUpToNearest10: (value?: number | null) => number;
141
+ /**
142
+ * Format a number with K (thousands) or M (millions) suffix.
143
+ */
144
+ declare const formatCount: (count: number) => string;
145
+ /**
146
+ * Format a duration in milliseconds to a human-readable string.
147
+ */
148
+ declare const formatDuration: (ms: number) => string;
162
149
  declare const getOrderOfMagnitudeExponent: (n?: number | null) => number;
163
150
 
164
151
  declare const REGEX_ALPHANUMERIC: RegExp;
@@ -257,6 +244,8 @@ declare const SCHEME_PREFIXES: {
257
244
  readonly sftp: "sftp";
258
245
  readonly smb: "smb";
259
246
  };
247
+ declare const DATA_URI_PATTERN: RegExp;
248
+ declare const isValidDataUri: (uri?: string | null) => boolean;
260
249
  declare const hasScheme: (uri?: string | null) => boolean;
261
250
  /**
262
251
  * Extracts the base64 data from a data URI string.
@@ -267,9 +256,17 @@ declare const hasScheme: (uri?: string | null) => boolean;
267
256
  * @returns The base64 data without the data URI prefix, or the original string if no comma is found
268
257
  */
269
258
  declare const extractBase64FromDataUri: (dataUri: string) => string;
259
+ declare const encodeUrl: (value?: string) => string;
260
+ declare const decodeUrl: (value?: string) => string;
261
+ interface FormatDataUriArgs {
262
+ mimeType: string;
263
+ base64: string;
264
+ }
265
+ declare const formatDataUri: ({ mimeType, base64 }: FormatDataUriArgs) => string;
266
+ declare const getBase64ApproxSize: (base64: string) => number;
270
267
 
271
268
  declare const isWsClosable: (ws?: WebSocket | null) => ws is WebSocket;
272
269
  declare const isWsOpenOrConnecting: (ws?: WebSocket | null) => ws is WebSocket;
273
270
  declare const closeWebSocket: (ws?: WebSocket | null) => void;
274
271
 
275
- export { type ChartPoint, type DateInput, HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, type NormalizedRgb, type NullableChartPoint, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, type RgbColor, type RgbaColor, SCHEME_PREFIXES, type ToleranceArea, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, extractBase64FromDataUri, formatIntegerDisplay, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getColorForPercentage, getContrastTextColor, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getLuminance, getOpacityHexValue, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, hexToNormalizedRgb, hexToRgb, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isLightColor, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isWsClosable, isWsOpenOrConnecting, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, removeDiacriticalMarks, rgbToHex, rgbToString, rgbaToHex, rgbaToHexWithAlpha, rgbaToString, roundToNiceNumber, roundUpToNearest10, sleep, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, yieldToMainThread };
272
+ export { type ChartPoint, DATA_URI_PATTERN, type DateInput, HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, type NullableChartPoint, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, SCHEME_PREFIXES, type ToleranceArea, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, decodeBase64, decodeUrl, encodeBase64, encodeUrl, escapeHtml, extractBase64FromDataUri, formatCount, formatDataUri, formatDuration, formatIntegerDisplay, formatJson, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getBase64ApproxSize, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isMinifiedJson, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isValidDataUri, isValidJson, isWsClosable, isWsOpenOrConnecting, minifyJson, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, prettifyJson, removeDiacriticalMarks, roundToNiceNumber, roundUpToNearest10, safeJsonParse, safeJsonStringify, sleep, sortObjectKeys, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, unescapeHtml, yieldToMainThread };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export { D as Dimensions } from './dimensions.utils-BwIBA5op.js';
1
+ export { D as Dimensions, N as NormalizedRgb, R as RgbColor, a as RgbaColor, l as getColorForPercentage, i as getContrastTextColor, f as getLuminance, g as getOpacityHexValue, j as hexToNormalizedRgb, h as hexToRgb, k as isLightColor, r as rgbToHex, d as rgbToString, b as rgbaToHex, c as rgbaToHexWithAlpha, e as rgbaToString } from './dimensions.utils-BSm9gmWz.js';
2
+
3
+ declare const encodeBase64: (text: string) => string;
4
+ declare const decodeBase64: (base64: string) => string;
2
5
 
3
6
  interface ToleranceArea {
4
7
  flow: number;
@@ -46,47 +49,6 @@ declare const roundToNiceNumber: (rawValue: number) => number;
46
49
  */
47
50
  declare const buildTicksForChart: (max: number, targetTickCount?: number) => number[];
48
51
 
49
- interface RgbColor {
50
- r: number;
51
- g: number;
52
- b: number;
53
- }
54
- interface RgbaColor extends RgbColor {
55
- a: number;
56
- }
57
- declare const rgbToHex: (r: number, g: number, b: number) => string;
58
- declare const hexToRgb: (hex: string) => RgbColor;
59
- declare const rgbaToHex: (color: RgbaColor) => string;
60
- declare const getOpacityHexValue: (opacity: number) => string;
61
- declare const rgbaToHexWithAlpha: (color: RgbaColor) => string;
62
- declare const rgbToString: (color: RgbColor) => string;
63
- declare const rgbaToString: (color: RgbaColor) => string;
64
- declare const getLuminance: (r: number, g: number, b: number) => number;
65
- declare const getContrastTextColor: (hexColor: string) => string;
66
- /**
67
- * Normalized RGB color with values between 0 and 1.
68
- * Useful for graphics libraries like Three.js.
69
- */
70
- interface NormalizedRgb {
71
- r: number;
72
- g: number;
73
- b: number;
74
- }
75
- /**
76
- * Convert a hex color string to normalized RGB values (0-1 range).
77
- * @param hex - Hex color string (with or without # prefix)
78
- * @returns Normalized RGB object with values between 0 and 1
79
- */
80
- declare const hexToNormalizedRgb: (hex: string) => NormalizedRgb;
81
- /**
82
- * Determine if a color is light or dark based on relative luminance.
83
- * Useful for choosing contrasting text colors.
84
- * @param hex - Hex color string
85
- * @returns True if the color is considered light (luminance > 0.5)
86
- */
87
- declare const isLightColor: (hex: string) => boolean;
88
- declare const getColorForPercentage: (percent: number) => string;
89
-
90
52
  type DateInput = Date | string | number | null;
91
53
  declare const dateAs_HHMMSS: (value?: DateInput) => string;
92
54
  declare const dateAs_YYYYMMDD: (value?: DateInput) => string;
@@ -133,10 +95,27 @@ declare const toFormString: (n?: number | null) => string;
133
95
  */
134
96
  declare const toFormStringInteger: (n?: number | null) => string;
135
97
 
98
+ declare const escapeHtml: (text: string) => string;
99
+ declare const unescapeHtml: (text: string) => string;
100
+
136
101
  declare const isHttpSuccessStatus: (status?: number | null) => boolean;
137
102
  declare const isHttpClientErrorStatus: (status?: number | null) => boolean;
138
103
  declare const isHttpServerErrorStatus: (status?: number | null) => boolean;
139
104
 
105
+ declare const safeJsonParse: <T>(value: string, fallback?: T) => T | undefined;
106
+ declare const safeJsonStringify: (obj: unknown, space?: number) => string;
107
+ declare const sortObjectKeys: (_key: string, value: unknown) => unknown;
108
+ interface FormatJsonArgs {
109
+ value?: string;
110
+ space?: number;
111
+ sortKeys?: boolean;
112
+ }
113
+ declare const formatJson: ({ value, space, sortKeys }: FormatJsonArgs) => string;
114
+ declare const prettifyJson: (value?: string) => string;
115
+ declare const minifyJson: (value?: string) => string;
116
+ declare const isValidJson: (value: string) => boolean;
117
+ declare const isMinifiedJson: (value: string) => boolean;
118
+
140
119
  /**
141
120
  * Returns true if the input string is a valid number (blank and non-numeric strings are invalid).
142
121
  */
@@ -159,6 +138,14 @@ declare const isInputValidNegativeInteger: (value: string) => boolean;
159
138
  declare const formatIntegerDisplay: (value?: number | null) => string;
160
139
  declare const toFixed: (value?: number | null, decimals?: number) => number;
161
140
  declare const roundUpToNearest10: (value?: number | null) => number;
141
+ /**
142
+ * Format a number with K (thousands) or M (millions) suffix.
143
+ */
144
+ declare const formatCount: (count: number) => string;
145
+ /**
146
+ * Format a duration in milliseconds to a human-readable string.
147
+ */
148
+ declare const formatDuration: (ms: number) => string;
162
149
  declare const getOrderOfMagnitudeExponent: (n?: number | null) => number;
163
150
 
164
151
  declare const REGEX_ALPHANUMERIC: RegExp;
@@ -257,6 +244,8 @@ declare const SCHEME_PREFIXES: {
257
244
  readonly sftp: "sftp";
258
245
  readonly smb: "smb";
259
246
  };
247
+ declare const DATA_URI_PATTERN: RegExp;
248
+ declare const isValidDataUri: (uri?: string | null) => boolean;
260
249
  declare const hasScheme: (uri?: string | null) => boolean;
261
250
  /**
262
251
  * Extracts the base64 data from a data URI string.
@@ -267,9 +256,17 @@ declare const hasScheme: (uri?: string | null) => boolean;
267
256
  * @returns The base64 data without the data URI prefix, or the original string if no comma is found
268
257
  */
269
258
  declare const extractBase64FromDataUri: (dataUri: string) => string;
259
+ declare const encodeUrl: (value?: string) => string;
260
+ declare const decodeUrl: (value?: string) => string;
261
+ interface FormatDataUriArgs {
262
+ mimeType: string;
263
+ base64: string;
264
+ }
265
+ declare const formatDataUri: ({ mimeType, base64 }: FormatDataUriArgs) => string;
266
+ declare const getBase64ApproxSize: (base64: string) => number;
270
267
 
271
268
  declare const isWsClosable: (ws?: WebSocket | null) => ws is WebSocket;
272
269
  declare const isWsOpenOrConnecting: (ws?: WebSocket | null) => ws is WebSocket;
273
270
  declare const closeWebSocket: (ws?: WebSocket | null) => void;
274
271
 
275
- export { type ChartPoint, type DateInput, HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, type NormalizedRgb, type NullableChartPoint, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, type RgbColor, type RgbaColor, SCHEME_PREFIXES, type ToleranceArea, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, extractBase64FromDataUri, formatIntegerDisplay, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getColorForPercentage, getContrastTextColor, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getLuminance, getOpacityHexValue, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, hexToNormalizedRgb, hexToRgb, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isLightColor, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isWsClosable, isWsOpenOrConnecting, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, removeDiacriticalMarks, rgbToHex, rgbToString, rgbaToHex, rgbaToHexWithAlpha, rgbaToString, roundToNiceNumber, roundUpToNearest10, sleep, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, yieldToMainThread };
272
+ export { type ChartPoint, DATA_URI_PATTERN, type DateInput, HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, type NullableChartPoint, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, SCHEME_PREFIXES, type ToleranceArea, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, decodeBase64, decodeUrl, encodeBase64, encodeUrl, escapeHtml, extractBase64FromDataUri, formatCount, formatDataUri, formatDuration, formatIntegerDisplay, formatJson, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getBase64ApproxSize, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isMinifiedJson, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isValidDataUri, isValidJson, isWsClosable, isWsOpenOrConnecting, minifyJson, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, prettifyJson, removeDiacriticalMarks, roundToNiceNumber, roundUpToNearest10, safeJsonParse, safeJsonStringify, sleep, sortObjectKeys, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, unescapeHtml, yieldToMainThread };
package/dist/index.js CHANGED
@@ -1,5 +1,115 @@
1
1
  import { format } from 'date-fns';
2
2
 
3
+ // src/utils/base64.utils.ts
4
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
+ var encodeUtf8ToBytes = (text) => {
6
+ const codePoints = [];
7
+ for (let i = 0; i < text.length; i++) {
8
+ const codeUnit = text.charCodeAt(i);
9
+ if (codeUnit >= 55296 && codeUnit <= 56319 && i + 1 < text.length) {
10
+ const next = text.charCodeAt(i + 1);
11
+ if (next >= 56320 && next <= 57343) {
12
+ codePoints.push(65536 + (codeUnit - 55296 << 10) + (next - 56320));
13
+ i++;
14
+ continue;
15
+ }
16
+ }
17
+ codePoints.push(codeUnit);
18
+ }
19
+ const bytes = [];
20
+ for (const codePoint of codePoints) {
21
+ if (codePoint < 128) {
22
+ bytes.push(codePoint);
23
+ } else if (codePoint < 2048) {
24
+ bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
25
+ } else if (codePoint < 65536) {
26
+ bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
27
+ } else {
28
+ bytes.push(
29
+ 240 | codePoint >> 18,
30
+ 128 | codePoint >> 12 & 63,
31
+ 128 | codePoint >> 6 & 63,
32
+ 128 | codePoint & 63
33
+ );
34
+ }
35
+ }
36
+ return bytes;
37
+ };
38
+ var decodeUtf8FromBytes = (bytes) => {
39
+ let result = "";
40
+ let i = 0;
41
+ while (i < bytes.length) {
42
+ const b0 = bytes[i];
43
+ let codePoint;
44
+ if (b0 < 128) {
45
+ codePoint = b0;
46
+ i += 1;
47
+ } else if ((b0 & 224) === 192) {
48
+ codePoint = (b0 & 31) << 6 | bytes[i + 1] & 63;
49
+ i += 2;
50
+ } else if ((b0 & 240) === 224) {
51
+ codePoint = (b0 & 15) << 12 | (bytes[i + 1] & 63) << 6 | bytes[i + 2] & 63;
52
+ i += 3;
53
+ } else {
54
+ codePoint = (b0 & 7) << 18 | (bytes[i + 1] & 63) << 12 | (bytes[i + 2] & 63) << 6 | bytes[i + 3] & 63;
55
+ i += 4;
56
+ }
57
+ if (codePoint <= 65535) {
58
+ result += String.fromCharCode(codePoint);
59
+ } else {
60
+ const adjusted = codePoint - 65536;
61
+ result += String.fromCharCode(55296 + (adjusted >> 10), 56320 + (adjusted & 1023));
62
+ }
63
+ }
64
+ return result;
65
+ };
66
+ var encodeBytesToBase64 = (bytes) => {
67
+ let output = "";
68
+ for (let i = 0; i < bytes.length; i += 3) {
69
+ const b0 = bytes[i];
70
+ const b1 = i + 1 < bytes.length ? bytes[i + 1] : 0;
71
+ const b2 = i + 2 < bytes.length ? bytes[i + 2] : 0;
72
+ const triplet = b0 << 16 | b1 << 8 | b2;
73
+ output += BASE64_CHARS[triplet >> 18 & 63];
74
+ output += BASE64_CHARS[triplet >> 12 & 63];
75
+ output += i + 1 < bytes.length ? BASE64_CHARS[triplet >> 6 & 63] : "=";
76
+ output += i + 2 < bytes.length ? BASE64_CHARS[triplet & 63] : "=";
77
+ }
78
+ return output;
79
+ };
80
+ var decodeBase64ToBytes = (base64) => {
81
+ const sanitized = base64.replace(/[^A-Za-z0-9+/=]/g, "");
82
+ const bytes = [];
83
+ for (let i = 0; i < sanitized.length; i += 4) {
84
+ const c0 = BASE64_CHARS.indexOf(sanitized[i]);
85
+ const c1 = BASE64_CHARS.indexOf(sanitized[i + 1]);
86
+ const c2 = sanitized[i + 2] === "=" ? 0 : BASE64_CHARS.indexOf(sanitized[i + 2]);
87
+ const c3 = sanitized[i + 3] === "=" ? 0 : BASE64_CHARS.indexOf(sanitized[i + 3]);
88
+ if (c0 < 0 || c1 < 0 || sanitized[i + 2] !== "=" && c2 < 0 || sanitized[i + 3] !== "=" && c3 < 0) {
89
+ throw new Error("Invalid base64 character");
90
+ }
91
+ const triplet = c0 << 18 | c1 << 12 | c2 << 6 | c3;
92
+ bytes.push(triplet >> 16 & 255);
93
+ if (sanitized[i + 2] !== "=") bytes.push(triplet >> 8 & 255);
94
+ if (sanitized[i + 3] !== "=") bytes.push(triplet & 255);
95
+ }
96
+ return bytes;
97
+ };
98
+ var encodeBase64 = (text) => {
99
+ try {
100
+ return encodeBytesToBase64(encodeUtf8ToBytes(text));
101
+ } catch {
102
+ return "";
103
+ }
104
+ };
105
+ var decodeBase64 = (base64) => {
106
+ try {
107
+ return decodeUtf8FromBytes(decodeBase64ToBytes(base64));
108
+ } catch {
109
+ return "";
110
+ }
111
+ };
112
+
3
113
  // src/utils/types.utils.ts
4
114
  var NO_OP = () => {
5
115
  };
@@ -282,6 +392,29 @@ var toFormStringInteger = (n) => {
282
392
  return String(Math.round(n));
283
393
  };
284
394
 
395
+ // src/utils/html.utils.ts
396
+ var HTML_ESCAPE_MAP = {
397
+ "&": "&amp;",
398
+ "<": "&lt;",
399
+ ">": "&gt;",
400
+ '"': "&quot;",
401
+ "'": "&#39;"
402
+ };
403
+ var HTML_UNESCAPE_MAP = {
404
+ "&amp;": "&",
405
+ "&lt;": "<",
406
+ "&gt;": ">",
407
+ "&quot;": '"',
408
+ "&#39;": "'",
409
+ "&#x27;": "'"
410
+ };
411
+ var escapeHtml = (text) => {
412
+ return text.replace(/[&<>"']/g, (char) => HTML_ESCAPE_MAP[char] ?? char);
413
+ };
414
+ var unescapeHtml = (text) => {
415
+ return text.replace(/&(?:amp|lt|gt|quot|#39|#x27);/g, (entity) => HTML_UNESCAPE_MAP[entity] ?? entity);
416
+ };
417
+
285
418
  // src/utils/http.utils.ts
286
419
  var isHttpSuccessStatus = (status) => {
287
420
  if (isNullish(status)) {
@@ -302,6 +435,56 @@ var isHttpServerErrorStatus = (status) => {
302
435
  return status >= 500;
303
436
  };
304
437
 
438
+ // src/utils/json.utils.ts
439
+ var safeJsonParse = (value, fallback) => {
440
+ try {
441
+ return JSON.parse(value);
442
+ } catch {
443
+ return fallback;
444
+ }
445
+ };
446
+ var safeJsonStringify = (obj, space = 2) => {
447
+ if (!obj) return "";
448
+ try {
449
+ return JSON.stringify(obj, null, space);
450
+ } catch {
451
+ return "";
452
+ }
453
+ };
454
+ var sortObjectKeys = (_key, value) => value instanceof Object && !(value instanceof Array) ? Object.keys(value).sort().reduce(
455
+ (sorted, key) => {
456
+ sorted[key] = value[key];
457
+ return sorted;
458
+ },
459
+ {}
460
+ ) : value;
461
+ var formatJson = ({ value, space = 2, sortKeys = false }) => {
462
+ if (!value) return "";
463
+ try {
464
+ const obj = JSON.parse(value);
465
+ return JSON.stringify(obj, sortKeys ? sortObjectKeys : void 0, space);
466
+ } catch {
467
+ return value;
468
+ }
469
+ };
470
+ var prettifyJson = (value) => {
471
+ return formatJson({ value, space: 4, sortKeys: true });
472
+ };
473
+ var minifyJson = (value) => {
474
+ return formatJson({ value, space: 0, sortKeys: true });
475
+ };
476
+ var isValidJson = (value) => {
477
+ try {
478
+ JSON.parse(value);
479
+ return true;
480
+ } catch {
481
+ return false;
482
+ }
483
+ };
484
+ var isMinifiedJson = (value) => {
485
+ return value === minifyJson(value);
486
+ };
487
+
305
488
  // src/utils/number.utils.ts
306
489
  var isInputValidNumber = (value) => {
307
490
  if (isBlank(value)) return false;
@@ -335,6 +518,21 @@ var roundUpToNearest10 = (value) => {
335
518
  if (isNullish(value)) return 0;
336
519
  return Math.ceil(value / 10) * 10;
337
520
  };
521
+ var formatCount = (count) => {
522
+ if (count >= 1e6) {
523
+ return `${(count / 1e6).toFixed(1)}M`;
524
+ }
525
+ if (count >= 1e3) {
526
+ return `${(count / 1e3).toFixed(1)}K`;
527
+ }
528
+ return count.toString();
529
+ };
530
+ var formatDuration = (ms) => {
531
+ if (ms < 1e3) {
532
+ return `${ms}ms`;
533
+ }
534
+ return `${(ms / 1e3).toFixed(1)}s`;
535
+ };
338
536
  var getOrderOfMagnitudeExponent = (n) => {
339
537
  if (isNullish(n)) return 0;
340
538
  if (!isNumber(n)) return 0;
@@ -409,6 +607,13 @@ var SCHEME_PREFIXES = {
409
607
  smb: "smb"
410
608
  };
411
609
  var SCHEME_PREFIXES_ARRAY = Object.values(SCHEME_PREFIXES);
610
+ var DATA_URI_PATTERN = /^data:([\w.+-]+\/[\w.+-]+);base64,(.+)$/;
611
+ var isValidDataUri = (uri) => {
612
+ if (isBlank(uri)) {
613
+ return false;
614
+ }
615
+ return DATA_URI_PATTERN.test(uri);
616
+ };
412
617
  var hasScheme = (uri) => {
413
618
  if (!uri) {
414
619
  return false;
@@ -419,6 +624,24 @@ var hasScheme = (uri) => {
419
624
  var extractBase64FromDataUri = (dataUri) => {
420
625
  return dataUri.split(",")[1] ?? dataUri;
421
626
  };
627
+ var encodeUrl = (value) => {
628
+ if (!value) return "";
629
+ return encodeURIComponent(value);
630
+ };
631
+ var decodeUrl = (value) => {
632
+ if (!value) return "";
633
+ try {
634
+ return decodeURIComponent(value);
635
+ } catch {
636
+ return value;
637
+ }
638
+ };
639
+ var formatDataUri = ({ mimeType, base64 }) => {
640
+ return `data:${mimeType};base64,${base64}`;
641
+ };
642
+ var getBase64ApproxSize = (base64) => {
643
+ return Math.round(base64.length * 3 / 4);
644
+ };
422
645
 
423
646
  // src/utils/websocket.utils.ts
424
647
  var WEBSOCKET_CONNECT_STATES = [WebSocket.CONNECTING, WebSocket.OPEN];
@@ -438,6 +661,6 @@ var closeWebSocket = (ws) => {
438
661
  }
439
662
  };
440
663
 
441
- export { HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, SCHEME_PREFIXES, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, extractBase64FromDataUri, formatIntegerDisplay, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getColorForPercentage, getContrastTextColor, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getLuminance, getOpacityHexValue, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, hexToNormalizedRgb, hexToRgb, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isLightColor, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isWsClosable, isWsOpenOrConnecting, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, removeDiacriticalMarks, rgbToHex, rgbToString, rgbaToHex, rgbaToHexWithAlpha, rgbaToString, roundToNiceNumber, roundUpToNearest10, sleep, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, yieldToMainThread };
664
+ export { DATA_URI_PATTERN, HZ_TO_RPM, M3PS_TO_GPM, M_TO_INCHES, NO_OP, PA_TO_FT, PeriodsInMS, REGEX_ALPHANUMERIC, REGEX_IPV4, SCHEME_PREFIXES, W_TO_HP, buildTicksForChart, capitalizeFirst, closeWebSocket, countWords, dateAs_HHMMSS, dateAs_YYYYMMDD, dateAs_YYYYMMDD_HHMMSS, decodeBase64, decodeUrl, encodeBase64, encodeUrl, escapeHtml, extractBase64FromDataUri, formatCount, formatDataUri, formatDuration, formatIntegerDisplay, formatJson, formatUnixTimestamp, fromHzToRpm, fromM3psToGPM, fromMToInches, fromPaToFt, fromWToHp, getBase64ApproxSize, getColorForPercentage, getContrastTextColor, getCurrentUnixTimestamp, getErrorMessage, getFileExtension, getLuminance, getOpacityHexValue, getOrderOfMagnitudeExponent, getTickDomain, hasScheme, hexToNormalizedRgb, hexToRgb, isActiveTimestamp, isAlphanumeric, isBlank, isExpiredTimestamp, isHttpClientErrorStatus, isHttpServerErrorStatus, isHttpSuccessStatus, isInputValidInteger, isInputValidNegativeInteger, isInputValidNumber, isInputValidPositiveInteger, isLightColor, isMinifiedJson, isNotBlank, isNullish, isNumber, isRuntimeEnvNodeJs, isString, isValidDataUri, isValidJson, isWsClosable, isWsOpenOrConnecting, minifyJson, nowAsDate, nowAsDateTime, nowAsDateTimeForFilename, nowAsTime, parseCommaSeparatedList, parseOptionalFormNumber, prettifyJson, removeDiacriticalMarks, rgbToHex, rgbToString, rgbaToHex, rgbaToHexWithAlpha, rgbaToString, roundToNiceNumber, roundUpToNearest10, safeJsonParse, safeJsonStringify, sleep, sortObjectKeys, tickFormatter, toError, toFixed, toFormString, toFormStringInteger, toToleranceLabel, tooltipValueFormatter, truncate, unescapeHtml, yieldToMainThread };
442
665
  //# sourceMappingURL=index.js.map
443
666
  //# sourceMappingURL=index.js.map