@pixpilot/string 2.1.1 → 2.2.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.
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
package/dist/case.cjs ADDED
@@ -0,0 +1 @@
1
+ const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`change-case`);t=e.__toESM(t);function n(e){return(0,t.camelCase)(e)}function r(e){return(0,t.capitalCase)(e)}function i(e){return(0,t.constantCase)(e)}function a(e){return(0,t.dotCase)(e)}function o(e){return(0,t.kebabCase)(e)}function s(e){return(0,t.noCase)(e)}function c(e){return(0,t.pascalCase)(e)}function l(e){return(0,t.pascalSnakeCase)(e)}function u(e){return(0,t.pathCase)(e)}function d(e){return(0,t.sentenceCase)(e)}function f(e){return(0,t.snakeCase)(e)}function p(e){return(0,t.trainCase)(e)}exports.toCamelCase=n,exports.toCapitalCase=r,exports.toConstantCase=i,exports.toDotCase=a,exports.toKebabCase=o,exports.toNoCase=s,exports.toPascalCase=c,exports.toPascalSnakeCase=l,exports.toPathCase=u,exports.toSentenceCase=d,exports.toSnakeCase=f,exports.toTrainCase=p;
@@ -0,0 +1,51 @@
1
+ //#region src/case.d.ts
2
+ /**
3
+ * Convert a string to camel case (`fooBar`).
4
+ */
5
+ declare function toCamelCase(str: string): string;
6
+ /**
7
+ * Convert a string to capital case (`Foo Bar`).
8
+ */
9
+ declare function toCapitalCase(str: string): string;
10
+ /**
11
+ * Convert a string to constant case (`CONSTANT_CASE`).
12
+ */
13
+ declare function toConstantCase(str: string): string;
14
+ /**
15
+ * Convert a string to dot case (`dot.case`).
16
+ */
17
+ declare function toDotCase(str: string): string;
18
+ /**
19
+ * Convert a string to kebab case (`kebab-case`).
20
+ */
21
+ declare function toKebabCase(str: string): string;
22
+ /**
23
+ * Convert a string to no case (`no case`).
24
+ */
25
+ declare function toNoCase(str: string): string;
26
+ /**
27
+ * Convert a string to pascal case (`PascalCase`).
28
+ */
29
+ declare function toPascalCase(str: string): string;
30
+ /**
31
+ * Convert a string to pascal snake case (`Pascal_Snake_Case`).
32
+ */
33
+ declare function toPascalSnakeCase(str: string): string;
34
+ /**
35
+ * Convert a string to path case (`path/case`).
36
+ */
37
+ declare function toPathCase(str: string): string;
38
+ /**
39
+ * Convert a string to sentence case (`Sentence case`).
40
+ */
41
+ declare function toSentenceCase(str: string): string;
42
+ /**
43
+ * Convert a string to snake case (`snake_case`).
44
+ */
45
+ declare function toSnakeCase(str: string): string;
46
+ /**
47
+ * Convert a string to train case (`Train-Case`).
48
+ */
49
+ declare function toTrainCase(str: string): string;
50
+ //#endregion
51
+ export { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase };
package/dist/case.d.ts CHANGED
@@ -1,48 +1,51 @@
1
+ //#region src/case.d.ts
1
2
  /**
2
3
  * Convert a string to camel case (`fooBar`).
3
4
  */
4
- export declare function toCamelCase(str: string): string;
5
+ declare function toCamelCase(str: string): string;
5
6
  /**
6
7
  * Convert a string to capital case (`Foo Bar`).
7
8
  */
8
- export declare function toCapitalCase(str: string): string;
9
+ declare function toCapitalCase(str: string): string;
9
10
  /**
10
11
  * Convert a string to constant case (`CONSTANT_CASE`).
11
12
  */
12
- export declare function toConstantCase(str: string): string;
13
+ declare function toConstantCase(str: string): string;
13
14
  /**
14
15
  * Convert a string to dot case (`dot.case`).
15
16
  */
16
- export declare function toDotCase(str: string): string;
17
+ declare function toDotCase(str: string): string;
17
18
  /**
18
19
  * Convert a string to kebab case (`kebab-case`).
19
20
  */
20
- export declare function toKebabCase(str: string): string;
21
+ declare function toKebabCase(str: string): string;
21
22
  /**
22
23
  * Convert a string to no case (`no case`).
23
24
  */
24
- export declare function toNoCase(str: string): string;
25
+ declare function toNoCase(str: string): string;
25
26
  /**
26
27
  * Convert a string to pascal case (`PascalCase`).
27
28
  */
28
- export declare function toPascalCase(str: string): string;
29
+ declare function toPascalCase(str: string): string;
29
30
  /**
30
31
  * Convert a string to pascal snake case (`Pascal_Snake_Case`).
31
32
  */
32
- export declare function toPascalSnakeCase(str: string): string;
33
+ declare function toPascalSnakeCase(str: string): string;
33
34
  /**
34
35
  * Convert a string to path case (`path/case`).
35
36
  */
36
- export declare function toPathCase(str: string): string;
37
+ declare function toPathCase(str: string): string;
37
38
  /**
38
39
  * Convert a string to sentence case (`Sentence case`).
39
40
  */
40
- export declare function toSentenceCase(str: string): string;
41
+ declare function toSentenceCase(str: string): string;
41
42
  /**
42
43
  * Convert a string to snake case (`snake_case`).
43
44
  */
44
- export declare function toSnakeCase(str: string): string;
45
+ declare function toSnakeCase(str: string): string;
45
46
  /**
46
47
  * Convert a string to train case (`Train-Case`).
47
48
  */
48
- export declare function toTrainCase(str: string): string;
49
+ declare function toTrainCase(str: string): string;
50
+ //#endregion
51
+ export { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase };
package/dist/case.js ADDED
@@ -0,0 +1 @@
1
+ import{camelCase as e,capitalCase as t,constantCase as n,dotCase as r,kebabCase as i,noCase as a,pascalCase as o,pascalSnakeCase as s,pathCase as c,sentenceCase as l,snakeCase as u,trainCase as d}from"change-case";function f(t){return e(t)}function p(e){return t(e)}function m(e){return n(e)}function h(e){return r(e)}function g(e){return i(e)}function _(e){return a(e)}function v(e){return o(e)}function y(e){return s(e)}function b(e){return c(e)}function x(e){return l(e)}function S(e){return u(e)}function C(e){return d(e)}export{f as toCamelCase,p as toCapitalCase,m as toConstantCase,h as toDotCase,g as toKebabCase,_ as toNoCase,v as toPascalCase,y as toPascalSnakeCase,b as toPathCase,x as toSentenceCase,S as toSnakeCase,C as toTrainCase};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=/([\p{Ll}\d])(\p{Lu})/gu,e=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,r=/(\d)\p{Ll}|(\p{L})\d/u,n=/[^\p{L}\d]+/giu,o="$1\0$2";function c(r){let c=r.trim();c=c.replace(t,o).replace(e,o),c=c.replace(n,"\0");let i=0,s=c.length;for(;"\0"===c.charAt(i);)i++;if(i===s)return[];for(;"\0"===c.charAt(s-1);)s--;return c.slice(i,s).split(/\0/g)}function i(t){const e=c(t);for(let t=0;t<e.length;t++){const n=e[t],o=r.exec(n);if(o){const r=o.index+(o[1]??o[2]).length;e.splice(t,1,n.slice(0,r),n.slice(r))}}return e}function s(t,e){const[r,n,o]=x(t,e);return r+n.map(a(e?.locale)).join(e?.delimiter??" ")+o}function u(t,e){const[r,n,o]=x(t,e),c=a(e?.locale),i=l(e?.locale);return r+n.map(p(c,i)).join(e?.delimiter??" ")+o}function a(t){return!1===t?t=>t.toLowerCase():e=>e.toLocaleLowerCase(t)}function l(t){return!1===t?t=>t.toUpperCase():e=>e.toLocaleUpperCase(t)}function p(t,e){return r=>`${e(r[0])}${t(r.slice(1))}`}function f(t,e){return(r,n)=>{const o=r[0];return(n>0&&o>="0"&&o<="9"?"_"+o:e(o))+t(r.slice(1))}}function x(t,e={}){const r=e.split??(e.separateNumbers?i:c),n=e.prefixCharacters??"",o=e.suffixCharacters??"";let s=0,u=t.length;for(;s<t.length;){const e=t.charAt(s);if(!n.includes(e))break;s++}for(;u>s;){const e=u-1,r=t.charAt(e);if(!o.includes(r))break;u=e}return[t.slice(0,s),r(t.slice(s,u)),t.slice(u)]}exports.capitalize=function(t){return 0===t.length?t:t.charAt(0).toUpperCase()+t.slice(1)},exports.capitalizeFirst=function(t){return 0===t.length?t:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()},exports.countOccurrences=function(t,e,r=!0){if(0===e.length)return 0;const n=r?t:t.toLowerCase(),o=r?e:e.toLowerCase();let c=0,i=0;for(;;){const t=n.indexOf(o,i);if(-1===t)break;c++,i=t+1}return c},exports.isAlphanumeric=function(t){return/^[\da-z]+$/iu.test(t)},exports.isEmail=function(t){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(t)},exports.isEmpty=function(t,e=!0){return e?0===t.trim().length:0===t.length},exports.isString=function(t){return"string"==typeof t},exports.isUrl=function(t){try{const e=new URL(t);return Boolean(e)}catch{return!1}},exports.normalizeSpaces=function(t){return t.replace(/\s+/gu," ").trim()},exports.padEnd=function(t,e,r=" "){return t.padEnd(e,r)},exports.padStart=function(t,e,r=" "){return t.padStart(e,r)},exports.removeWhitespace=function(t){return t.replace(/\s+/gu,"")},exports.repeat=function(t,e){return t.repeat(e)},exports.reverse=function(t){return t.split("").reverse().join("")},exports.toCamelCase=function(t){return function(t,e){const[r,n,o]=x(t,e),c=a(e?.locale),i=l(e?.locale),s=f(c,i);return r+n.map((t,e)=>0===e?c(t):s(t,e)).join("")+o}(t)},exports.toCapitalCase=function(t){return u(t)},exports.toConstantCase=function(t){return function(t,e){const[r,n,o]=x(t,e);return r+n.map(l(e?.locale)).join("_")+o}(t)},exports.toDotCase=function(t){return s(t,{delimiter:".",...e});var e},exports.toKebabCase=function(t){return s(t,{delimiter:"-",...e});var e},exports.toNoCase=function(t){return s(t)},exports.toPascalCase=function(t){return function(t,e){const[r,n,o]=x(t,e),c=f(a(e?.locale),l(e?.locale));return r+n.map(c).join("")+o}(t)},exports.toPascalSnakeCase=function(t){return u(t,{delimiter:"_",...e});var e},exports.toPathCase=function(t){return s(t,{delimiter:"/",...e});var e},exports.toSentenceCase=function(t){return function(t,e){const[r,n,o]=x(t,e),c=a(e?.locale),i=l(e?.locale),s=p(c,i);return r+n.map((t,e)=>0===e?s(t):c(t)).join(" ")+o}(t)},exports.toSnakeCase=function(t){return s(t,{delimiter:"_",...e});var e},exports.toTrainCase=function(t){return u(t,{delimiter:"-",...e});var e},exports.truncate=function(t,e,r="..."){return t.length<=e?t:t.slice(0,e)+r},exports.words=function(t){return t.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]};
1
+ const e=require(`./case.cjs`),t=require(`./manipulation.cjs`),n=require(`./type-guards.cjs`),r=require(`./validation.cjs`);exports.capitalize=t.capitalize,exports.capitalizeFirst=t.capitalizeFirst,exports.countOccurrences=t.countOccurrences,exports.isAlphanumeric=r.isAlphanumeric,exports.isEmail=r.isEmail,exports.isEmpty=r.isEmpty,exports.isString=n.isString,exports.isUrl=r.isUrl,exports.normalizeSpaces=t.normalizeSpaces,exports.padEnd=t.padEnd,exports.padStart=t.padStart,exports.removeWhitespace=t.removeWhitespace,exports.repeat=t.repeat,exports.reverse=t.reverse,exports.toCamelCase=e.toCamelCase,exports.toCapitalCase=e.toCapitalCase,exports.toConstantCase=e.toConstantCase,exports.toDotCase=e.toDotCase,exports.toKebabCase=e.toKebabCase,exports.toNoCase=e.toNoCase,exports.toPascalCase=e.toPascalCase,exports.toPascalSnakeCase=e.toPascalSnakeCase,exports.toPathCase=e.toPathCase,exports.toSentenceCase=e.toSentenceCase,exports.toSnakeCase=e.toSnakeCase,exports.toTrainCase=e.toTrainCase,exports.truncate=t.truncate,exports.words=t.words;
@@ -0,0 +1,5 @@
1
+ import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.cjs";
2
+ import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.cjs";
3
+ import { isString } from "./type-guards.cjs";
4
+ import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.cjs";
5
+ export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export * from './case';
2
- export * from './manipulation';
3
- export * from './type-guards';
4
- export * from './validation';
1
+ import { toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase } from "./case.js";
2
+ import { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words } from "./manipulation.js";
3
+ import { isString } from "./type-guards.js";
4
+ import { isAlphanumeric, isEmail, isEmpty, isUrl } from "./validation.js";
5
+ export { capitalize, capitalizeFirst, countOccurrences, isAlphanumeric, isEmail, isEmpty, isString, isUrl, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, toCamelCase, toCapitalCase, toConstantCase, toDotCase, toKebabCase, toNoCase, toPascalCase, toPascalSnakeCase, toPathCase, toSentenceCase, toSnakeCase, toTrainCase, truncate, words };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const n=/([\p{Ll}\d])(\p{Lu})/gu,t=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,e=/(\d)\p{Ll}|(\p{L})\d/u,r=/[^\p{L}\d]+/giu,u="$1\0$2";function c(e){let c=e.trim();c=c.replace(n,u).replace(t,u),c=c.replace(r,"\0");let o=0,i=c.length;for(;"\0"===c.charAt(o);)o++;if(o===i)return[];for(;"\0"===c.charAt(i-1);)i--;return c.slice(o,i).split(/\0/g)}function o(n){const t=c(n);for(let n=0;n<t.length;n++){const r=t[n],u=e.exec(r);if(u){const e=u.index+(u[1]??u[2]).length;t.splice(n,1,r.slice(0,e),r.slice(e))}}return t}function i(n,t){const[e,r,u]=d(n,t);return e+r.map(a(t?.locale)).join(t?.delimiter??" ")+u}function l(n,t){const[e,r,u]=d(n,t),c=a(t?.locale),o=f(t?.locale);return e+r.map(s(c,o)).join(t?.delimiter??" ")+u}function a(n){return!1===n?n=>n.toLowerCase():t=>t.toLocaleLowerCase(n)}function f(n){return!1===n?n=>n.toUpperCase():t=>t.toLocaleUpperCase(n)}function s(n,t){return e=>`${t(e[0])}${n(e.slice(1))}`}function p(n,t){return(e,r)=>{const u=e[0];return(r>0&&u>="0"&&u<="9"?"_"+u:t(u))+n(e.slice(1))}}function d(n,t={}){const e=t.split??(t.separateNumbers?o:c),r=t.prefixCharacters??"",u=t.suffixCharacters??"";let i=0,l=n.length;for(;i<n.length;){const t=n.charAt(i);if(!r.includes(t))break;i++}for(;l>i;){const t=l-1,e=n.charAt(t);if(!u.includes(e))break;l=t}return[n.slice(0,i),e(n.slice(i,l)),n.slice(l)]}function h(n){return function(n,t){const[e,r,u]=d(n,t),c=a(t?.locale),o=f(t?.locale),i=p(c,o);return e+r.map((n,t)=>0===t?c(n):i(n,t)).join("")+u}(n)}function g(n){return l(n)}function m(n){return function(n,t){const[e,r,u]=d(n,t);return e+r.map(f(t?.locale)).join("_")+u}(n)}function L(n){return i(n,{delimiter:".",...t});var t}function C(n){return i(n,{delimiter:"-",...t});var t}function A(n){return i(n)}function j(n){return function(n,t){const[e,r,u]=d(n,t),c=p(a(t?.locale),f(t?.locale));return e+r.map(c).join("")+u}(n)}function v(n){return l(n,{delimiter:"_",...t});var t}function w(n){return i(n,{delimiter:"/",...t});var t}function x(n){return function(n,t){const[e,r,u]=d(n,t),c=a(t?.locale),o=f(t?.locale),i=s(c,o);return e+r.map((n,t)=>0===t?i(n):c(n)).join(" ")+u}(n)}function $(n){return i(n,{delimiter:"_",...t});var t}function U(n){return l(n,{delimiter:"-",...t});var t}function b(n,t,e="..."){return n.length<=t?n:n.slice(0,t)+e}function _(n){return 0===n.length?n:n.charAt(0).toUpperCase()+n.slice(1)}function k(n){return 0===n.length?n:n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()}function z(n){return n.split("").reverse().join("")}function y(n){return n.replace(/\s+/gu,"")}function Z(n){return n.replace(/\s+/gu," ").trim()}function B(n,t,e=" "){return n.padStart(t,e)}function E(n,t,e=" "){return n.padEnd(t,e)}function N(n,t){return n.repeat(t)}function O(n,t,e=!0){if(0===t.length)return 0;const r=e?n:n.toLowerCase(),u=e?t:t.toLowerCase();let c=0,o=0;for(;;){const n=r.indexOf(u,o);if(-1===n)break;c++,o=n+1}return c}function R(n){return n.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]}function S(n){return"string"==typeof n}function q(n,t=!0){return t?0===n.trim().length:0===n.length}function D(n){return/^[\da-z]+$/iu.test(n)}function F(n){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(n)}function G(n){try{const t=new URL(n);return Boolean(t)}catch{return!1}}export{_ as capitalize,k as capitalizeFirst,O as countOccurrences,D as isAlphanumeric,F as isEmail,q as isEmpty,S as isString,G as isUrl,Z as normalizeSpaces,E as padEnd,B as padStart,y as removeWhitespace,N as repeat,z as reverse,h as toCamelCase,g as toCapitalCase,m as toConstantCase,L as toDotCase,C as toKebabCase,A as toNoCase,j as toPascalCase,v as toPascalSnakeCase,w as toPathCase,x as toSentenceCase,$ as toSnakeCase,U as toTrainCase,b as truncate,R as words};
1
+ import{toCamelCase as e,toCapitalCase as t,toConstantCase as n,toDotCase as r,toKebabCase as i,toNoCase as a,toPascalCase as o,toPascalSnakeCase as s,toPathCase as c,toSentenceCase as l,toSnakeCase as u,toTrainCase as d}from"./case.js";import{capitalize as f,capitalizeFirst as p,countOccurrences as m,normalizeSpaces as h,padEnd as g,padStart as _,removeWhitespace as v,repeat as y,reverse as b,truncate as x,words as S}from"./manipulation.js";import{isString as C}from"./type-guards.js";import{isAlphanumeric as w,isEmail as T,isEmpty as E,isUrl as D}from"./validation.js";export{f as capitalize,p as capitalizeFirst,m as countOccurrences,w as isAlphanumeric,T as isEmail,E as isEmpty,C as isString,D as isUrl,h as normalizeSpaces,g as padEnd,_ as padStart,v as removeWhitespace,y as repeat,b as reverse,e as toCamelCase,t as toCapitalCase,n as toConstantCase,r as toDotCase,i as toKebabCase,a as toNoCase,o as toPascalCase,s as toPascalSnakeCase,c as toPathCase,l as toSentenceCase,u as toSnakeCase,d as toTrainCase,x as truncate,S as words};
@@ -0,0 +1 @@
1
+ function e(e,t,n=`...`){return e.length<=t?e:e.slice(0,t)+n}function t(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function n(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function r(e){return e.split(``).reverse().join(``)}function i(e){return e.replace(/\s+/gu,``)}function a(e){return e.replace(/\s+/gu,` `).trim()}function o(e,t,n=` `){return e.padStart(t,n)}function s(e,t,n=` `){return e.padEnd(t,n)}function c(e,t){return e.repeat(t)}function l(e,t,n=!0){if(t.length===0)return 0;let r=n?e:e.toLowerCase(),i=n?t:t.toLowerCase(),a=0,o=0;for(;;){let e=r.indexOf(i,o);if(e===-1)break;a++,o=e+1}return a}function u(e){return e.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]}exports.capitalize=t,exports.capitalizeFirst=n,exports.countOccurrences=l,exports.normalizeSpaces=a,exports.padEnd=s,exports.padStart=o,exports.removeWhitespace=i,exports.repeat=c,exports.reverse=r,exports.truncate=e,exports.words=u;
@@ -0,0 +1,158 @@
1
+ //#region src/manipulation.d.ts
2
+ /**
3
+ * Truncate a string to a specified length, adding an ellipsis if truncated.
4
+ *
5
+ * @param str - The string to truncate
6
+ * @param maxLength - The maximum length of the string
7
+ * @param ellipsis - The ellipsis to append (default: '...')
8
+ * @returns The truncated string
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * truncate('Hello World', 5); // 'Hello...'
13
+ * truncate('Hello', 10); // 'Hello'
14
+ * truncate('Hello World', 5, '…'); // 'Hello…'
15
+ * ```
16
+ */
17
+ declare function truncate(str: string, maxLength: number, ellipsis?: string): string;
18
+ /**
19
+ * Capitalize the first letter of a string.
20
+ *
21
+ * @param str - The string to capitalize
22
+ * @returns The capitalized string
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * capitalize('hello'); // 'Hello'
27
+ * capitalize('WORLD'); // 'WORLD'
28
+ * capitalize(''); // ''
29
+ * ```
30
+ */
31
+ declare function capitalize(str: string): string;
32
+ /**
33
+ * Capitalize the first letter of a string and lowercase the rest.
34
+ *
35
+ * @param str - The string to capitalize
36
+ * @returns The capitalized string
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * capitalizeFirst('hello'); // 'Hello'
41
+ * capitalizeFirst('WORLD'); // 'World'
42
+ * capitalizeFirst('hELLO wORLD'); // 'Hello world'
43
+ * ```
44
+ */
45
+ declare function capitalizeFirst(str: string): string;
46
+ /**
47
+ * Reverse a string.
48
+ *
49
+ * @param str - The string to reverse
50
+ * @returns The reversed string
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * reverse('hello'); // 'olleh'
55
+ * reverse('abc123'); // '321cba'
56
+ * ```
57
+ */
58
+ declare function reverse(str: string): string;
59
+ /**
60
+ * Remove all whitespace from a string.
61
+ *
62
+ * @param str - The string to process
63
+ * @returns The string without whitespace
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * removeWhitespace('hello world'); // 'helloworld'
68
+ * removeWhitespace(' a b c '); // 'abc'
69
+ * ```
70
+ */
71
+ declare function removeWhitespace(str: string): string;
72
+ /**
73
+ * Replace multiple consecutive spaces with a single space.
74
+ *
75
+ * @param str - The string to process
76
+ * @returns The string with normalized spaces
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * normalizeSpaces('hello world'); // 'hello world'
81
+ * normalizeSpaces('a b c'); // 'a b c'
82
+ * ```
83
+ */
84
+ declare function normalizeSpaces(str: string): string;
85
+ /**
86
+ * Pad a string to a specified length from the start.
87
+ *
88
+ * @param str - The string to pad
89
+ * @param targetLength - The target length
90
+ * @param padString - The string to pad with (default: ' ')
91
+ * @returns The padded string
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * padStart('5', 3, '0'); // '005'
96
+ * padStart('hello', 10); // ' hello'
97
+ * ```
98
+ */
99
+ declare function padStart(str: string, targetLength: number, padString?: string): string;
100
+ /**
101
+ * Pad a string to a specified length from the end.
102
+ *
103
+ * @param str - The string to pad
104
+ * @param targetLength - The target length
105
+ * @param padString - The string to pad with (default: ' ')
106
+ * @returns The padded string
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * padEnd('5', 3, '0'); // '500'
111
+ * padEnd('hello', 10); // 'hello '
112
+ * ```
113
+ */
114
+ declare function padEnd(str: string, targetLength: number, padString?: string): string;
115
+ /**
116
+ * Repeat a string a specified number of times.
117
+ *
118
+ * @param str - The string to repeat
119
+ * @param count - The number of times to repeat
120
+ * @returns The repeated string
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * repeat('ha', 3); // 'hahaha'
125
+ * repeat('*', 5); // '*****'
126
+ * ```
127
+ */
128
+ declare function repeat(str: string, count: number): string;
129
+ /**
130
+ * Count the occurrences of a substring in a string.
131
+ *
132
+ * @param str - The string to search in
133
+ * @param searchValue - The substring to count
134
+ * @param caseSensitive - Whether the search is case-sensitive (default: true)
135
+ * @returns The number of occurrences
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * countOccurrences('hello world hello', 'hello'); // 2
140
+ * countOccurrences('Hello HELLO hello', 'hello', false); // 3
141
+ * ```
142
+ */
143
+ declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
144
+ /**
145
+ * Extract words from a string.
146
+ *
147
+ * @param str - The string to extract words from
148
+ * @returns An array of words
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * words('hello world'); // ['hello', 'world']
153
+ * words('one-two_three'); // ['one', 'two', 'three']
154
+ * ```
155
+ */
156
+ declare function words(str: string): string[];
157
+ //#endregion
158
+ export { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words };
@@ -1,3 +1,4 @@
1
+ //#region src/manipulation.d.ts
1
2
  /**
2
3
  * Truncate a string to a specified length, adding an ellipsis if truncated.
3
4
  *
@@ -13,7 +14,7 @@
13
14
  * truncate('Hello World', 5, '…'); // 'Hello…'
14
15
  * ```
15
16
  */
16
- export declare function truncate(str: string, maxLength: number, ellipsis?: string): string;
17
+ declare function truncate(str: string, maxLength: number, ellipsis?: string): string;
17
18
  /**
18
19
  * Capitalize the first letter of a string.
19
20
  *
@@ -27,7 +28,7 @@ export declare function truncate(str: string, maxLength: number, ellipsis?: stri
27
28
  * capitalize(''); // ''
28
29
  * ```
29
30
  */
30
- export declare function capitalize(str: string): string;
31
+ declare function capitalize(str: string): string;
31
32
  /**
32
33
  * Capitalize the first letter of a string and lowercase the rest.
33
34
  *
@@ -41,7 +42,7 @@ export declare function capitalize(str: string): string;
41
42
  * capitalizeFirst('hELLO wORLD'); // 'Hello world'
42
43
  * ```
43
44
  */
44
- export declare function capitalizeFirst(str: string): string;
45
+ declare function capitalizeFirst(str: string): string;
45
46
  /**
46
47
  * Reverse a string.
47
48
  *
@@ -54,7 +55,7 @@ export declare function capitalizeFirst(str: string): string;
54
55
  * reverse('abc123'); // '321cba'
55
56
  * ```
56
57
  */
57
- export declare function reverse(str: string): string;
58
+ declare function reverse(str: string): string;
58
59
  /**
59
60
  * Remove all whitespace from a string.
60
61
  *
@@ -67,7 +68,7 @@ export declare function reverse(str: string): string;
67
68
  * removeWhitespace(' a b c '); // 'abc'
68
69
  * ```
69
70
  */
70
- export declare function removeWhitespace(str: string): string;
71
+ declare function removeWhitespace(str: string): string;
71
72
  /**
72
73
  * Replace multiple consecutive spaces with a single space.
73
74
  *
@@ -80,7 +81,7 @@ export declare function removeWhitespace(str: string): string;
80
81
  * normalizeSpaces('a b c'); // 'a b c'
81
82
  * ```
82
83
  */
83
- export declare function normalizeSpaces(str: string): string;
84
+ declare function normalizeSpaces(str: string): string;
84
85
  /**
85
86
  * Pad a string to a specified length from the start.
86
87
  *
@@ -95,7 +96,7 @@ export declare function normalizeSpaces(str: string): string;
95
96
  * padStart('hello', 10); // ' hello'
96
97
  * ```
97
98
  */
98
- export declare function padStart(str: string, targetLength: number, padString?: string): string;
99
+ declare function padStart(str: string, targetLength: number, padString?: string): string;
99
100
  /**
100
101
  * Pad a string to a specified length from the end.
101
102
  *
@@ -110,7 +111,7 @@ export declare function padStart(str: string, targetLength: number, padString?:
110
111
  * padEnd('hello', 10); // 'hello '
111
112
  * ```
112
113
  */
113
- export declare function padEnd(str: string, targetLength: number, padString?: string): string;
114
+ declare function padEnd(str: string, targetLength: number, padString?: string): string;
114
115
  /**
115
116
  * Repeat a string a specified number of times.
116
117
  *
@@ -124,7 +125,7 @@ export declare function padEnd(str: string, targetLength: number, padString?: st
124
125
  * repeat('*', 5); // '*****'
125
126
  * ```
126
127
  */
127
- export declare function repeat(str: string, count: number): string;
128
+ declare function repeat(str: string, count: number): string;
128
129
  /**
129
130
  * Count the occurrences of a substring in a string.
130
131
  *
@@ -139,7 +140,7 @@ export declare function repeat(str: string, count: number): string;
139
140
  * countOccurrences('Hello HELLO hello', 'hello', false); // 3
140
141
  * ```
141
142
  */
142
- export declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
143
+ declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
143
144
  /**
144
145
  * Extract words from a string.
145
146
  *
@@ -152,4 +153,6 @@ export declare function countOccurrences(str: string, searchValue: string, caseS
152
153
  * words('one-two_three'); // ['one', 'two', 'three']
153
154
  * ```
154
155
  */
155
- export declare function words(str: string): string[];
156
+ declare function words(str: string): string[];
157
+ //#endregion
158
+ export { capitalize, capitalizeFirst, countOccurrences, normalizeSpaces, padEnd, padStart, removeWhitespace, repeat, reverse, truncate, words };
@@ -0,0 +1 @@
1
+ function e(e,t,n=`...`){return e.length<=t?e:e.slice(0,t)+n}function t(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1)}function n(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function r(e){return e.split(``).reverse().join(``)}function i(e){return e.replace(/\s+/gu,``)}function a(e){return e.replace(/\s+/gu,` `).trim()}function o(e,t,n=` `){return e.padStart(t,n)}function s(e,t,n=` `){return e.padEnd(t,n)}function c(e,t){return e.repeat(t)}function l(e,t,n=!0){if(t.length===0)return 0;let r=n?e:e.toLowerCase(),i=n?t:t.toLowerCase(),a=0,o=0;for(;;){let e=r.indexOf(i,o);if(e===-1)break;a++,o=e+1}return a}function u(e){return e.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/gu)||[]}export{t as capitalize,n as capitalizeFirst,l as countOccurrences,a as normalizeSpaces,s as padEnd,o as padStart,i as removeWhitespace,c as repeat,r as reverse,e as truncate,u as words};
@@ -0,0 +1 @@
1
+ function e(e){return typeof e==`string`}exports.isString=e;
@@ -0,0 +1,17 @@
1
+ //#region src/type-guards.d.ts
2
+ /**
3
+ * Type guard to check if a value is a string.
4
+ *
5
+ * @param value - The value to check
6
+ * @returns True if the value is a string, false otherwise
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * isString('hello'); // true
11
+ * isString(123); // false
12
+ * isString(null); // false
13
+ * ```
14
+ */
15
+ declare function isString(value: unknown): value is string;
16
+ //#endregion
17
+ export { isString };
@@ -1,3 +1,4 @@
1
+ //#region src/type-guards.d.ts
1
2
  /**
2
3
  * Type guard to check if a value is a string.
3
4
  *
@@ -11,4 +12,6 @@
11
12
  * isString(null); // false
12
13
  * ```
13
14
  */
14
- export declare function isString(value: unknown): value is string;
15
+ declare function isString(value: unknown): value is string;
16
+ //#endregion
17
+ export { isString };
@@ -0,0 +1 @@
1
+ function e(e){return typeof e==`string`}export{e as isString};
@@ -0,0 +1 @@
1
+ function e(e,t=!0){return t?e.trim().length===0:e.length===0}function t(e){return/^[\da-z]+$/iu.test(e)}function n(e){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(e)}function r(e){try{return!!new URL(e)}catch{return!1}}exports.isAlphanumeric=t,exports.isEmail=n,exports.isEmpty=e,exports.isUrl=r;
@@ -0,0 +1,59 @@
1
+ //#region src/validation.d.ts
2
+ /**
3
+ * Check if a string is empty (zero length or only whitespace).
4
+ *
5
+ * @param str - The string to check
6
+ * @param trimWhitespace - If true, treats whitespace-only strings as empty (default: true)
7
+ * @returns True if the string is empty, false otherwise
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * isEmpty(''); // true
12
+ * isEmpty(' '); // true
13
+ * isEmpty(' ', false); // false
14
+ * isEmpty('hello'); // false
15
+ * ```
16
+ */
17
+ declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
18
+ /**
19
+ * Check if a string contains only alphanumeric characters.
20
+ *
21
+ * @param str - The string to check
22
+ * @returns True if the string contains only alphanumeric characters, false otherwise
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * isAlphanumeric('abc123'); // true
27
+ * isAlphanumeric('abc-123'); // false
28
+ * isAlphanumeric(''); // false
29
+ * ```
30
+ */
31
+ declare function isAlphanumeric(str: string): boolean;
32
+ /**
33
+ * Check if a string is a valid email address.
34
+ *
35
+ * @param str - The string to check
36
+ * @returns True if the string is a valid email address, false otherwise
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * isEmail('test@example.com'); // true
41
+ * isEmail('invalid-email'); // false
42
+ * ```
43
+ */
44
+ declare function isEmail(str: string): boolean;
45
+ /**
46
+ * Check if a string is a valid URL.
47
+ *
48
+ * @param str - The string to check
49
+ * @returns True if the string is a valid URL, false otherwise
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * isUrl('https://example.com'); // true
54
+ * isUrl('not a url'); // false
55
+ * ```
56
+ */
57
+ declare function isUrl(str: string): boolean;
58
+ //#endregion
59
+ export { isAlphanumeric, isEmail, isEmpty, isUrl };
@@ -1,3 +1,4 @@
1
+ //#region src/validation.d.ts
1
2
  /**
2
3
  * Check if a string is empty (zero length or only whitespace).
3
4
  *
@@ -13,7 +14,7 @@
13
14
  * isEmpty('hello'); // false
14
15
  * ```
15
16
  */
16
- export declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
17
+ declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
17
18
  /**
18
19
  * Check if a string contains only alphanumeric characters.
19
20
  *
@@ -27,7 +28,7 @@ export declare function isEmpty(str: string, trimWhitespace?: boolean): boolean;
27
28
  * isAlphanumeric(''); // false
28
29
  * ```
29
30
  */
30
- export declare function isAlphanumeric(str: string): boolean;
31
+ declare function isAlphanumeric(str: string): boolean;
31
32
  /**
32
33
  * Check if a string is a valid email address.
33
34
  *
@@ -40,7 +41,7 @@ export declare function isAlphanumeric(str: string): boolean;
40
41
  * isEmail('invalid-email'); // false
41
42
  * ```
42
43
  */
43
- export declare function isEmail(str: string): boolean;
44
+ declare function isEmail(str: string): boolean;
44
45
  /**
45
46
  * Check if a string is a valid URL.
46
47
  *
@@ -53,4 +54,6 @@ export declare function isEmail(str: string): boolean;
53
54
  * isUrl('not a url'); // false
54
55
  * ```
55
56
  */
56
- export declare function isUrl(str: string): boolean;
57
+ declare function isUrl(str: string): boolean;
58
+ //#endregion
59
+ export { isAlphanumeric, isEmail, isEmpty, isUrl };
@@ -0,0 +1 @@
1
+ function e(e,t=!0){return t?e.trim().length===0:e.length===0}function t(e){return/^[\da-z]+$/iu.test(e)}function n(e){return/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/u.test(e)}function r(e){try{return!!new URL(e)}catch{return!1}}export{t as isAlphanumeric,n as isEmail,e as isEmpty,r as isUrl};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixpilot/string",
3
3
  "type": "module",
4
- "version": "2.1.1",
4
+ "version": "2.2.0",
5
5
  "description": "A collection of utility functions for string manipulation and validation.",
6
6
  "author": "Pixpilot <m.doaie@hotmail.com>",
7
7
  "license": "MIT",
@@ -30,19 +30,22 @@
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.18.10",
32
32
  "eslint": "^9.37.0",
33
- "rollup": "^4.52.4",
33
+ "tsdown": "^0.15.8",
34
34
  "typescript": "^5.9.3",
35
35
  "@internal/eslint-config": "0.3.0",
36
36
  "@internal/prettier-config": "0.0.1",
37
- "@internal/rollup-config": "0.1.0",
38
37
  "@internal/tsconfig": "0.1.0",
38
+ "@internal/tsdown-config": "0.1.0",
39
39
  "@internal/vitest-config": "0.1.0"
40
40
  },
41
41
  "prettier": "@internal/prettier-config",
42
42
  "scripts": {
43
+ "@internal/tsdown-config": "workspace:*",
44
+ "tsdown": "catalog:dev",
43
45
  "clean": "git clean -xdf .cache .turbo dist",
44
46
  "clean:all": "git clean -xdf .cache .turbo dist node_modules",
45
- "build": "pnpm run clean && rollup -c",
47
+ "build": "tsdown",
48
+ "buld:watch": "tsdown --watch",
46
49
  "test": "vitest --run --passWithNoTests",
47
50
  "test:watch": "vitest --watch",
48
51
  "test:ui": "vitest --ui",