@salespark/toolkit 2.1.8 → 2.1.9
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/README.md +27 -3
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -233,6 +233,20 @@ declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): O
|
|
|
233
233
|
declare function objectToString(obj: unknown): string;
|
|
234
234
|
declare function cleanObject<T = unknown>(obj: T, removeEmptyString?: boolean): any;
|
|
235
235
|
|
|
236
|
+
type Locale = string | string[] | undefined;
|
|
237
|
+
type CapitalizeFirstOptions = {
|
|
238
|
+
lowerRest?: boolean;
|
|
239
|
+
locale?: Locale;
|
|
240
|
+
};
|
|
241
|
+
type CapitalizeWordsOptions = {
|
|
242
|
+
lowerRest?: boolean;
|
|
243
|
+
locale?: Locale;
|
|
244
|
+
treatHyphenAsSeparator?: boolean;
|
|
245
|
+
};
|
|
246
|
+
type SentenceCaseOptions = {
|
|
247
|
+
lowerRest?: boolean;
|
|
248
|
+
locale?: Locale;
|
|
249
|
+
};
|
|
236
250
|
/******************************************************
|
|
237
251
|
* ##: Slugify String
|
|
238
252
|
* Converts a string to a URL-friendly slug (basic ASCII, keeps numbers and dashes)
|
|
@@ -261,6 +275,33 @@ declare function fill(template: string, values: Record<string, string | number>)
|
|
|
261
275
|
* 21-08-2025: Created
|
|
262
276
|
****************************************************/
|
|
263
277
|
declare function deburr(str: string): string;
|
|
278
|
+
/******************************************************
|
|
279
|
+
* ##: Capitalize First Letter
|
|
280
|
+
* Capitalizes only the first character of a string; optionally lowercases the rest
|
|
281
|
+
* @param {String} input - Input string
|
|
282
|
+
* @param {Object} options - { lowerRest = true, locale }
|
|
283
|
+
* History:
|
|
284
|
+
* 19-12-2025: Created
|
|
285
|
+
****************************************************/
|
|
286
|
+
declare function capitalizeFirst(input: unknown, options?: CapitalizeFirstOptions): string;
|
|
287
|
+
/******************************************************
|
|
288
|
+
* ##: Capitalize Words
|
|
289
|
+
* Capitalizes each word in a string with options for hyphens and locale
|
|
290
|
+
* @param {String} input - Input string
|
|
291
|
+
* @param {Object} options - { lowerRest = true, locale, treatHyphenAsSeparator = false }
|
|
292
|
+
* History:
|
|
293
|
+
* 19-12-2025: Created
|
|
294
|
+
****************************************************/
|
|
295
|
+
declare function capitalizeWords(input: unknown, options?: CapitalizeWordsOptions): string;
|
|
296
|
+
/******************************************************
|
|
297
|
+
* ##: Sentence Case
|
|
298
|
+
* Capitalizes the first letter of each sentence (. ! ?) with optional lowercasing of the rest
|
|
299
|
+
* @param {String} input - Input string
|
|
300
|
+
* @param {Object} options - { lowerRest = true, locale }
|
|
301
|
+
* History:
|
|
302
|
+
* 19-12-2025: Created
|
|
303
|
+
****************************************************/
|
|
304
|
+
declare function sentenceCase(input: unknown, options?: SentenceCaseOptions): string;
|
|
264
305
|
/**
|
|
265
306
|
* @deprecated Use `deburr` instead.
|
|
266
307
|
*/
|
|
@@ -781,4 +822,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
781
822
|
declare const isBrowser: boolean;
|
|
782
823
|
declare const isNode: boolean;
|
|
783
824
|
|
|
784
|
-
export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
825
|
+
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.d.ts
CHANGED
|
@@ -233,6 +233,20 @@ declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): O
|
|
|
233
233
|
declare function objectToString(obj: unknown): string;
|
|
234
234
|
declare function cleanObject<T = unknown>(obj: T, removeEmptyString?: boolean): any;
|
|
235
235
|
|
|
236
|
+
type Locale = string | string[] | undefined;
|
|
237
|
+
type CapitalizeFirstOptions = {
|
|
238
|
+
lowerRest?: boolean;
|
|
239
|
+
locale?: Locale;
|
|
240
|
+
};
|
|
241
|
+
type CapitalizeWordsOptions = {
|
|
242
|
+
lowerRest?: boolean;
|
|
243
|
+
locale?: Locale;
|
|
244
|
+
treatHyphenAsSeparator?: boolean;
|
|
245
|
+
};
|
|
246
|
+
type SentenceCaseOptions = {
|
|
247
|
+
lowerRest?: boolean;
|
|
248
|
+
locale?: Locale;
|
|
249
|
+
};
|
|
236
250
|
/******************************************************
|
|
237
251
|
* ##: Slugify String
|
|
238
252
|
* Converts a string to a URL-friendly slug (basic ASCII, keeps numbers and dashes)
|
|
@@ -261,6 +275,33 @@ declare function fill(template: string, values: Record<string, string | number>)
|
|
|
261
275
|
* 21-08-2025: Created
|
|
262
276
|
****************************************************/
|
|
263
277
|
declare function deburr(str: string): string;
|
|
278
|
+
/******************************************************
|
|
279
|
+
* ##: Capitalize First Letter
|
|
280
|
+
* Capitalizes only the first character of a string; optionally lowercases the rest
|
|
281
|
+
* @param {String} input - Input string
|
|
282
|
+
* @param {Object} options - { lowerRest = true, locale }
|
|
283
|
+
* History:
|
|
284
|
+
* 19-12-2025: Created
|
|
285
|
+
****************************************************/
|
|
286
|
+
declare function capitalizeFirst(input: unknown, options?: CapitalizeFirstOptions): string;
|
|
287
|
+
/******************************************************
|
|
288
|
+
* ##: Capitalize Words
|
|
289
|
+
* Capitalizes each word in a string with options for hyphens and locale
|
|
290
|
+
* @param {String} input - Input string
|
|
291
|
+
* @param {Object} options - { lowerRest = true, locale, treatHyphenAsSeparator = false }
|
|
292
|
+
* History:
|
|
293
|
+
* 19-12-2025: Created
|
|
294
|
+
****************************************************/
|
|
295
|
+
declare function capitalizeWords(input: unknown, options?: CapitalizeWordsOptions): string;
|
|
296
|
+
/******************************************************
|
|
297
|
+
* ##: Sentence Case
|
|
298
|
+
* Capitalizes the first letter of each sentence (. ! ?) with optional lowercasing of the rest
|
|
299
|
+
* @param {String} input - Input string
|
|
300
|
+
* @param {Object} options - { lowerRest = true, locale }
|
|
301
|
+
* History:
|
|
302
|
+
* 19-12-2025: Created
|
|
303
|
+
****************************************************/
|
|
304
|
+
declare function sentenceCase(input: unknown, options?: SentenceCaseOptions): string;
|
|
264
305
|
/**
|
|
265
306
|
* @deprecated Use `deburr` instead.
|
|
266
307
|
*/
|
|
@@ -781,4 +822,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
781
822
|
declare const isBrowser: boolean;
|
|
782
823
|
declare const isNode: boolean;
|
|
783
824
|
|
|
784
|
-
export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
825
|
+
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.js
CHANGED
|
@@ -209,6 +209,12 @@ function cleanObject(obj, removeEmptyString = false) {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
// src/utils/string.ts
|
|
212
|
+
function upper(value, locale) {
|
|
213
|
+
return locale ? value.toLocaleUpperCase(locale) : value.toUpperCase();
|
|
214
|
+
}
|
|
215
|
+
function lower(value, locale) {
|
|
216
|
+
return locale ? value.toLocaleLowerCase(locale) : value.toLowerCase();
|
|
217
|
+
}
|
|
212
218
|
function slugify(input) {
|
|
213
219
|
return input.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
214
220
|
}
|
|
@@ -222,6 +228,38 @@ function deburr(str) {
|
|
|
222
228
|
return str;
|
|
223
229
|
}
|
|
224
230
|
}
|
|
231
|
+
function capitalizeFirst(input, options) {
|
|
232
|
+
if (typeof input !== "string" || input.length === 0) return "";
|
|
233
|
+
const { lowerRest = true, locale } = options ?? {};
|
|
234
|
+
const first = upper(input[0], locale);
|
|
235
|
+
const rest = lowerRest ? lower(input.slice(1), locale) : input.slice(1);
|
|
236
|
+
return first + rest;
|
|
237
|
+
}
|
|
238
|
+
function capitalizeWords(input, options) {
|
|
239
|
+
if (typeof input !== "string" || input.length === 0) return "";
|
|
240
|
+
const {
|
|
241
|
+
lowerRest = true,
|
|
242
|
+
locale,
|
|
243
|
+
treatHyphenAsSeparator = false
|
|
244
|
+
} = options ?? {};
|
|
245
|
+
const wordPattern = treatHyphenAsSeparator ? /[\p{L}\p{N}]+(?:['’][\p{L}\p{N}]+)*/gu : /[\p{L}\p{N}]+(?:['’\-][\p{L}\p{N}]+)*/gu;
|
|
246
|
+
return input.replace(wordPattern, (word) => {
|
|
247
|
+
const first = upper(word[0], locale);
|
|
248
|
+
const rest = lowerRest ? lower(word.slice(1), locale) : word.slice(1);
|
|
249
|
+
return first + rest;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function sentenceCase(input, options) {
|
|
253
|
+
if (typeof input !== "string" || input.length === 0) return "";
|
|
254
|
+
const { lowerRest = true, locale } = options ?? {};
|
|
255
|
+
const base = lowerRest ? lower(input, locale) : input;
|
|
256
|
+
const sentencePattern = /(^\s*[\p{L}])|([.!?]\s*[\p{L}])/gu;
|
|
257
|
+
return base.replace(sentencePattern, (match) => {
|
|
258
|
+
const lastChar = match[match.length - 1];
|
|
259
|
+
const upperChar = upper(lastChar, locale);
|
|
260
|
+
return match.slice(0, -1) + upperChar;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
225
263
|
var removeDiacritics = deburr;
|
|
226
264
|
function sanitize(input, maxLength) {
|
|
227
265
|
if (typeof input !== "string") return "";
|
|
@@ -1694,6 +1732,6 @@ var assessSecurityRisks = (risks) => {
|
|
|
1694
1732
|
var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
1695
1733
|
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
1696
1734
|
|
|
1697
|
-
export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
1735
|
+
export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
1698
1736
|
//# sourceMappingURL=index.js.map
|
|
1699
1737
|
//# sourceMappingURL=index.js.map
|