@sqlrooms/utils 0.24.8 → 0.24.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/dist/str.d.ts +10 -0
- package/dist/str.d.ts.map +1 -1
- package/dist/str.js +15 -0
- package/dist/str.js.map +1 -1
- package/package.json +2 -2
package/dist/str.d.ts
CHANGED
|
@@ -24,4 +24,14 @@ export declare function camelCaseToTitle(camelCase: string): string;
|
|
|
24
24
|
* capitalize("hello world") // returns "Hello world"
|
|
25
25
|
*/
|
|
26
26
|
export declare function capitalize(str: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Truncates text to a specified word limit
|
|
29
|
+
* @param text - The text to truncate
|
|
30
|
+
* @param maxWords - The maximum number of words to keep (default: 10)
|
|
31
|
+
* @returns The truncated text with "..." appended if truncated
|
|
32
|
+
* @example
|
|
33
|
+
* truncate("This is a very long sentence that should be truncated", 5) // returns "This is a very long..."
|
|
34
|
+
* truncate("Short text", 10) // returns "Short text"
|
|
35
|
+
*/
|
|
36
|
+
export declare function truncate(text: string, maxWords?: number): string;
|
|
27
37
|
//# sourceMappingURL=str.d.ts.map
|
package/dist/str.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"str.d.ts","sourceRoot":"","sources":["../src/str.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBjD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAqB1D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
|
1
|
+
{"version":3,"file":"str.d.ts","sourceRoot":"","sources":["../src/str.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBjD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAqB1D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM,CAIpE"}
|
package/dist/str.js
CHANGED
|
@@ -57,4 +57,19 @@ export function camelCaseToTitle(camelCase) {
|
|
|
57
57
|
export function capitalize(str) {
|
|
58
58
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Truncates text to a specified word limit
|
|
62
|
+
* @param text - The text to truncate
|
|
63
|
+
* @param maxWords - The maximum number of words to keep (default: 10)
|
|
64
|
+
* @returns The truncated text with "..." appended if truncated
|
|
65
|
+
* @example
|
|
66
|
+
* truncate("This is a very long sentence that should be truncated", 5) // returns "This is a very long..."
|
|
67
|
+
* truncate("Short text", 10) // returns "Short text"
|
|
68
|
+
*/
|
|
69
|
+
export function truncate(text, maxWords = 10) {
|
|
70
|
+
const words = text.split(' ');
|
|
71
|
+
if (words.length <= maxWords)
|
|
72
|
+
return text;
|
|
73
|
+
return words.slice(0, maxWords).join(' ') + '...';
|
|
74
|
+
}
|
|
60
75
|
//# sourceMappingURL=str.js.map
|
package/dist/str.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"str.js","sourceRoot":"","sources":["../src/str.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAElC,MAAM,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI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AC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Formats a number of bytes into a human-readable string with appropriate size units.\n * @param bytes - The number of bytes to format\n * @returns A string representation of the bytes with appropriate unit (Bytes, KB, MB, etc.)\n * @example\n * formatBytes(1024) // returns \"1 KB\"\n * formatBytes(1234567) // returns \"1.18 MB\"\n */\nexport function formatBytes(bytes: number): string {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n let sizeValue = bytes / Math.pow(k, i);\n // Use floor to check if there's a non-zero fractional part, format accordingly\n sizeValue =\n sizeValue != Math.floor(sizeValue)\n ? parseFloat(sizeValue.toFixed(2))\n : Math.floor(sizeValue);\n\n return sizeValue + ' ' + sizes[i];\n}\n\n/**\n * Converts a camelCase string into a Title Case string.\n * @param camelCase - The camelCase string to convert\n * @returns A Title Case string with spaces between words\n * @example\n * camelCaseToTitle(\"myVariableName\") // returns \"My Variable Name\"\n * camelCaseToTitle(\"URL\") // returns \"URL\"\n */\nexport function camelCaseToTitle(camelCase: string): string {\n // Split the string into words on the camelCase boundaries\n const words = camelCase.match(/[A-Z]+(?![a-z])|[A-Z]?[a-z]+/g);\n\n // If words are found, transform them and join into a title string\n if (words) {\n return words\n .map((word) => {\n // Preserve fully uppercase words like \"URL\"\n if (word === word.toUpperCase()) {\n return word;\n }\n\n // Capitalize the first letter of each word\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n })\n .join(' '); // Join the words with space\n }\n\n // If no words were found, just capitalize the whole string\n return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);\n}\n\n/**\n * Capitalizes the first letter of string\n * @param str - The string to capitalize\n * @returns A new string with the first letter capitalized\n * @example\n * capitalize(\"hello world\") // returns \"Hello world\"\n */\nexport function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"str.js","sourceRoot":"","sources":["../src/str.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAElC,MAAM,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAExE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,IAAI,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,+EAA+E;IAC/E,SAAS;QACP,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAChC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAClC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE5B,OAAO,SAAS,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,0DAA0D;IAC1D,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAE/D,kEAAkE;IAClE,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,KAAK;aACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,4CAA4C;YAC5C,IAAI,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,2CAA2C;YAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpE,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,4BAA4B;IAC5C,CAAC;IAED,2DAA2D;IAC3D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,WAAmB,EAAE;IAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Formats a number of bytes into a human-readable string with appropriate size units.\n * @param bytes - The number of bytes to format\n * @returns A string representation of the bytes with appropriate unit (Bytes, KB, MB, etc.)\n * @example\n * formatBytes(1024) // returns \"1 KB\"\n * formatBytes(1234567) // returns \"1.18 MB\"\n */\nexport function formatBytes(bytes: number): string {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n let sizeValue = bytes / Math.pow(k, i);\n // Use floor to check if there's a non-zero fractional part, format accordingly\n sizeValue =\n sizeValue != Math.floor(sizeValue)\n ? parseFloat(sizeValue.toFixed(2))\n : Math.floor(sizeValue);\n\n return sizeValue + ' ' + sizes[i];\n}\n\n/**\n * Converts a camelCase string into a Title Case string.\n * @param camelCase - The camelCase string to convert\n * @returns A Title Case string with spaces between words\n * @example\n * camelCaseToTitle(\"myVariableName\") // returns \"My Variable Name\"\n * camelCaseToTitle(\"URL\") // returns \"URL\"\n */\nexport function camelCaseToTitle(camelCase: string): string {\n // Split the string into words on the camelCase boundaries\n const words = camelCase.match(/[A-Z]+(?![a-z])|[A-Z]?[a-z]+/g);\n\n // If words are found, transform them and join into a title string\n if (words) {\n return words\n .map((word) => {\n // Preserve fully uppercase words like \"URL\"\n if (word === word.toUpperCase()) {\n return word;\n }\n\n // Capitalize the first letter of each word\n return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();\n })\n .join(' '); // Join the words with space\n }\n\n // If no words were found, just capitalize the whole string\n return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);\n}\n\n/**\n * Capitalizes the first letter of string\n * @param str - The string to capitalize\n * @returns A new string with the first letter capitalized\n * @example\n * capitalize(\"hello world\") // returns \"Hello world\"\n */\nexport function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Truncates text to a specified word limit\n * @param text - The text to truncate\n * @param maxWords - The maximum number of words to keep (default: 10)\n * @returns The truncated text with \"...\" appended if truncated\n * @example\n * truncate(\"This is a very long sentence that should be truncated\", 5) // returns \"This is a very long...\"\n * truncate(\"Short text\", 10) // returns \"Short text\"\n */\nexport function truncate(text: string, maxWords: number = 10): string {\n const words = text.split(' ');\n if (words.length <= maxWords) return text;\n return words.slice(0, maxWords).join(' ') + '...';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/utils",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"react": ">=18",
|
|
45
45
|
"react-dom": ">=18"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2cbf51a0c14270bd02b73ea20d9684b7453cbdfe"
|
|
48
48
|
}
|