@tempots/std 0.13.0 → 0.14.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/regexp.d.ts CHANGED
@@ -8,4 +8,4 @@
8
8
  * @param subject - The string to search.
9
9
  * @public
10
10
  */
11
- export declare function mapRegExp(subject: string, pattern: RegExp, f: (...s: string[]) => string): string;
11
+ export declare const mapRegExp: (subject: string, pattern: RegExp, f: (...s: string[]) => string) => string;
package/regexp.js CHANGED
@@ -1,14 +1,14 @@
1
- function h(s, i, u) {
1
+ const h = (n, i, u) => {
2
2
  const e = [];
3
- let n = 0, l;
3
+ let s = 0, l;
4
4
  if (i.global)
5
- for (i.lastIndex = 0; (l = i.exec(s)) !== null; )
6
- e.push(s.substring(n, l.index)), e.push(u(...l)), n = l.index + l[0].length;
5
+ for (i.lastIndex = 0; (l = i.exec(n)) !== null; )
6
+ e.push(n.substring(s, l.index)), e.push(u(...l)), s = l.index + l[0].length;
7
7
  else
8
- for (; (l = i.exec(s.substring(n))) !== null; )
9
- e.push(s.substring(n, n + l.index)), e.push(u(...l)), n += l.index + l[0].length;
10
- return e.push(s.substring(n)), e.join("");
11
- }
8
+ for (; (l = i.exec(n.substring(s))) !== null; )
9
+ e.push(n.substring(s, s + l.index)), e.push(u(...l)), s += l.index + l[0].length;
10
+ return e.push(n.substring(s)), e.join("");
11
+ };
12
12
  export {
13
13
  h as mapRegExp
14
14
  };
package/result.d.ts CHANGED
@@ -7,19 +7,19 @@ import { Validation } from './validation';
7
7
  * @typeParam V - The type of the value.
8
8
  * @public
9
9
  */
10
- export interface Success<V> {
11
- type: 'Success';
12
- value: V;
13
- }
10
+ export type Success<V> = {
11
+ readonly type: 'Success';
12
+ readonly value: V;
13
+ };
14
14
  /**
15
15
  * Represents a failure result.
16
16
  * @typeParam E - The type of the error.
17
17
  * @public
18
18
  */
19
- export interface Failure<E> {
20
- type: 'Failure';
21
- error: E;
22
- }
19
+ export type Failure<E> = {
20
+ readonly type: 'Failure';
21
+ readonly error: E;
22
+ };
23
23
  /**
24
24
  * Represents a result that can either be a success or a failure.
25
25
  * @typeParam V - The type of the value in case of success.
package/string.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./array.cjs"),m=require("./regexp.cjs");function f(t,n,e){return t.split(n).join(e)}function U(t,n){const e=t.indexOf(n);return e<0?"":t.substring(e+n.length)}function _(t,n){const e=t.lastIndexOf(n);return e<0?"":t.substring(e+n.length)}function k(t,n){const e=t.indexOf(n);return e<0?"":t.substring(0,e)}function H(t,n){const e=t.lastIndexOf(n);return e<0?"":t.substring(0,e)}function p(t){return t.substring(0,1).toUpperCase()+t.substring(1)}const x=t=>t.toUpperCase();function $(t,n=!1){return n?m.mapRegExp(p(t),Rt,x):m.mapRegExp(p(t),Ht,x)}function D(t){return t.replace(qt,`
2
- `)}function R(t,n){return t==null&&n==null?0:t==null?-1:n==null?1:b(t.toLowerCase(),n.toLowerCase())}function d(t,n){return t.substring(0,t.length-n.length)===n}function P(t,n){return t.substring(0,t.length-n.length).toLowerCase()===n.toLowerCase()}function A(t,n){return t.substring(0,n.length)===n}function Z(t,n){return t.substring(0,n.length).toLowerCase()===n.toLowerCase()}function q(t,n){return L(t.toLowerCase(),n.map(e=>e.toLowerCase()))}function Q(t,n){return W(t.toLowerCase(),n.map(e=>e.toLowerCase()))}function G(t){return t.trim().replace(M," ")}function b(t,n){return t<n?-1:t>n?1:0}function C(t,n){return t.toLowerCase().includes(n.toLowerCase())}function l(t,n){return t.includes(n)}function K(t,n){return t.split(n).length-1}function v(t,n){return u.anyElement(n,e=>C(t,e))}function J(t,n){return u.anyElement(n,e=>l(t,e))}function V(t,n){return u.allElements(n,e=>C(t,e))}function X(t,n){return u.allElements(n,e=>l(t,e))}function Y(t){return t.replace("_","-")}function tt(t,n){if(t===n)return-1;const e=Math.min(t.length,n.length);for(let r=0;r<e;r++)if(t.substring(r,r+1)!==n.substring(r,r+1))return r;return e}function T(t,n=20,e="…"){const r=t.length,i=e.length;return r>n?n<i?e.substr(i-n,n):t.substr(0,n-i)+e:t}function nt(t,n=20,e="…"){const r=t.length,i=e.length;if(r>n){if(n<=i)return T(t,n,e);const c=Math.ceil((n-i)/2),a=Math.floor((n-i)/2);return t.substr(0,c)+e+t.substr(r-a,a)}else return t}function L(t,n){return u.anyElement(n,e=>d(t,e))}function et(t,n){return g(t).filter(n).join("")}function rt(t,n){return O(t).filter(n).map(r=>String.fromCharCode(r)).join("")}function it(t,n=2166136261){let e=n;for(let r=0,i=t.length;r<i;r++)e^=t.charCodeAt(r),e+=(e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24);return e>>>0}function st(t){return t!=null&&t.length>0}function ot(t){return f(F(t),"_"," ")}function ut(t){return t.length>0&&!Dt.test(t)}function ct(t){return Pt.test(t)}function ft(t){return!$t.test(t)}function at(t){return t.toLowerCase()===t}function lt(t){return t.toUpperCase()===t}function gt(t,n){return t!=null&&t!==""?t:n}function pt(t){return Zt.test(t)}function ht(t){return t==null||t===""}function dt(t){return t.substring(0,1).toLowerCase()+t.substring(1)}function w(t,n=1){return t.substring(Math.floor((t.length-n+1)*Math.random()),n)}function I(t,n){return u.generateArray(n,()=>w(t)).join("")}function Ct(t){return I(kt,t)}function St(t,n){return g(n).map(t)}function mt(t,n){return f(t,n,"")}function xt(t,n){return d(t,n)?t.substring(0,t.length-n.length):t}function At(t,n,e){return t.substring(0,n)+t.substring(n+e)}function bt(t,n){return A(t,n)?t.substring(n.length):t}function Tt(t,n){const e=t.indexOf(n);return e<0?t:t.substring(0,e)+t.substring(e+n.length)}function S(t,n){return u.createFilledArray(n,t).join("")}function Lt(t){const n=g(t);return n.reverse(),n.join("")}function y(t,n="'"){return n==="'"?t.includes("'")?t.includes('"')?"'"+f(t,"'","\\'")+"'":'"'+t+'"':"'"+t+"'":t.includes('"')?t.includes("'")?'"'+f(t,'"','\\"')+'"':"'"+t+"'":'"'+t+'"'}function E(t,n="'"){return n+f(t,n,"\\"+n)+n}function wt(t,n="'"){return t.indexOf(`
3
- `)>=0?E(t,"`"):y(t,n)}function It(t,n){const e=t.indexOf(n);return e<0?[t]:[t.substring(0,e),t.substring(e+n.length)]}function W(t,n){return u.anyElement(n,e=>t.startsWith(e))}function yt(t,n,e=n){return`${n}${t}${e}`}function g(t){return t.split("")}function O(t){return u.generateArray(t.length,n=>t.charCodeAt(n))}function Et(t,n){const e=[];for(;t.length>0;)e.push(t.substring(0,n)),t=t.substr(n,t.length-n);return e}function Wt(t){return t.split(N)}function Ot(t,n){return B(z(t,n),n)}function z(t,n){let e=0;for(let r=0;r<t.length&&l(n,t.charAt(r));r++)e++;return t.substring(e)}function B(t,n){const e=t.length;let r=e,i;for(let c=0;c<e&&(i=e-c-1,l(n,t.charAt(i)));c++)r=i;return t.substring(0,r)}function F(t){return t=t.replace(/::/g,"/"),t=t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2"),t=t.replace(/([a-z\d])([A-Z])/g,"$1_$2"),t=t.replace(/-/g,"_"),t.toLowerCase()}function zt(t){return t.substring(0,1).toUpperCase()+t.substring(1)}function Bt(t,n=78,e="",r=`
4
- `){return t.split(N).map(i=>j(i.replace(M," ").trim(),n,e,r)).join(r)}function h(t,n){if(n<0||n>=t.length)return!1;const e=t.charCodeAt(n);return e===9||e===10||e===11||e===12||e===13||e===32}function Ft(t){if(typeof Buffer<"u")return Buffer.from(t).toString("base64");if(typeof btoa<"u")return btoa(t);throw new Error("no implementation found for base64 encoding")}function jt(t){if(typeof Buffer<"u")return Buffer.from(t,"base64").toString("utf8");if(typeof atob<"u")return atob(t);throw new Error("no implementation found for base64 decoding")}function j(t,n,e,r){const i=[],c=t.length,a=e.length;let o=0;for(n-=a;;){if(o+n>=c-a){i.push(t.substring(o));break}let s=0;for(;!h(t,o+n-s)&&s<n;)s++;if(s===n){for(s=0;!h(t,o+n+s)&&o+n+s<c;)s++;i.push(t.substring(o,o+n+s)),o+=n+s+1}else i.push(t.substring(o,o+n-s)),o+=n-s+1}return e+i.join(r+e)}function Mt(t,n,e){const r=e-t.length;return r>0?S(n,r)+t:t}function Nt(t,n,e){const r=e-t.length;return r>0?t+S(n,r):t}function Ut(t,n){const e=t.lastIndexOf(n);return e>=0?[t.substring(0,e),t.substring(e+n.length)]:[t]}function _t(t,n){const e=t.indexOf(n);return e>=0?[t.substring(0,e),t.substring(e+n.length)]:[t]}const kt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ht=/[^a-zA-Z]([a-z])/g,$t=/[^\t\n\r ]/,Dt=/[^a-zA-Z]/,Rt=/[ \t\r\n][a-z]/g,Pt=/^[a-z0-9]+$/i,Zt=/^[0-9]+$/,M=/[ \t\r\n]+/g,N=/\r\n|\n\r|\n|\r/g,qt=/\r\n|\n\r|\r/g;exports.afterLastText=_;exports.afterText=U;exports.beforeLastText=H;exports.beforeText=k;exports.canonicalizeNewlines=D;exports.capitalize=p;exports.capitalizeWords=$;exports.chunkText=Et;exports.compareCaseInsensitive=R;exports.compareStrings=b;exports.containsAllText=X;exports.containsAllTextCaseInsensitive=V;exports.containsAnyText=J;exports.containsAnyTextCaseInsensitive=v;exports.countTextOccurrences=K;exports.dasherize=Y;exports.decodeBase64=jt;exports.ellipsis=T;exports.ellipsisMiddle=nt;exports.encodeBase64=Ft;exports.endsWithAnyText=L;exports.filterCharcode=rt;exports.filterText=et;exports.humanize=ot;exports.ifEmptyString=gt;exports.isAlpha=ut;exports.isAlphaNum=ct;exports.isBreakingWhitespace=ft;exports.isDigitsOnly=pt;exports.isEmptyString=ht;exports.isLowerCase=at;exports.isSpaceAt=h;exports.isUpperCase=lt;exports.jsQuote=wt;exports.lowerCaseFirst=dt;exports.lpad=Mt;exports.mapChars=St;exports.quote=E;exports.randomString=w;exports.randomStringSequence=I;exports.randomStringSequenceBase64=Ct;exports.removeFirstFromString=Tt;exports.removeFromString=mt;exports.removeFromStringAfter=xt;exports.removeFromStringBefore=bt;exports.removeSliceFromString=At;exports.repeatString=S;exports.replaceAll=f;exports.reverseString=Lt;exports.rpad=Nt;exports.smartQuote=y;exports.splitOnFirst=_t;exports.splitOnLast=Ut;exports.splitStringOnce=It;exports.stringHasContent=st;exports.stringHashCode=it;exports.stringToCharcodes=O;exports.stringToChars=g;exports.stringToLines=Wt;exports.stringsDifferAtIndex=tt;exports.surroundText=yt;exports.textCollapse=G;exports.textContains=l;exports.textContainsCaseInsensitive=C;exports.textEndsWith=d;exports.textEndsWithAnyCaseInsensitive=q;exports.textEndsWithCaseInsensitive=P;exports.textStartsWith=A;exports.textStartsWithAny=W;exports.textStartsWithAnyCaseInsensitive=Q;exports.textStartsWithCaseInsensitive=Z;exports.trimChars=Ot;exports.trimCharsLeft=z;exports.trimCharsRight=B;exports.underscore=F;exports.upperCaseFirst=zt;exports.wrapColumns=Bt;exports.wrapLine=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./array.cjs"),m=require("./error.cjs"),A=require("./regexp.cjs"),u=(t,e,n)=>t.split(e).join(n),_=(t,e)=>{const n=t.indexOf(e);return n<0?"":t.substring(n+e.length)},k=(t,e)=>{const n=t.lastIndexOf(e);return n<0?"":t.substring(n+e.length)},H=(t,e)=>{const n=t.indexOf(e);return n<0?"":t.substring(0,n)},$=(t,e)=>{const n=t.lastIndexOf(e);return n<0?"":t.substring(0,n)},h=t=>t.substring(0,1).toUpperCase()+t.substring(1),b=t=>t.toUpperCase(),D=(t,e=!1)=>e?A.mapRegExp(h(t),qt,b):A.mapRegExp(h(t),$t,b),R=t=>t.replace(Qt,`
2
+ `),q=(t,e)=>t==null&&e==null?0:t==null?-1:e==null?1:I(t.toLowerCase(),e.toLowerCase()),d=(t,e)=>t.substring(0,t.length-e.length)===e,P=(t,e)=>t.substring(0,t.length-e.length).toLowerCase()===e.toLowerCase(),L=(t,e)=>t.substring(0,e.length)===e,Z=(t,e)=>t.substring(0,e.length).toLowerCase()===e.toLowerCase(),Q=(t,e)=>y(t.toLowerCase(),e.map(n=>n.toLowerCase())),G=(t,e)=>B(t.toLowerCase(),e.map(n=>n.toLowerCase())),K=t=>t.trim().replace(F," "),I=(t,e)=>t<e?-1:t>e?1:0,C=(t,e)=>t.toLowerCase().includes(e.toLowerCase()),l=(t,e)=>t.includes(e),J=(t,e)=>t.split(e).length-1,V=(t,e)=>c.anyElement(e,n=>C(t,n)),X=(t,e)=>c.anyElement(e,n=>l(t,n)),Y=(t,e)=>c.allElements(e,n=>C(t,n)),v=(t,e)=>c.allElements(e,n=>l(t,n)),tt=t=>t.replace("_","-"),et=(t,e)=>{if(t===e)return-1;const n=Math.min(t.length,e.length);for(let r=0;r<n;r++)if(t.substring(r,r+1)!==e.substring(r,r+1))return r;return n},w=(t,e=20,n="…")=>{const r=t.length,s=n.length;return r>e?e<s?n.slice(s-e,e):t.slice(0,e-s)+n:t},nt=(t,e=20,n="…")=>{const r=t.length,s=n.length;if(r>e){if(e<=s)return w(t,e,n);const a=Math.ceil((e-s)/2),g=Math.floor((e-s)/2);return t.slice(0,a)+n+t.slice(r-g)}else return t},y=(t,e)=>c.anyElement(e,n=>d(t,n)),rt=(t,e)=>p(t).filter(e).join(""),st=(t,e)=>T(t).filter(e).map(r=>String.fromCharCode(r)).join(""),it=(t,e=2166136261)=>{let n=e;for(let r=0,s=t.length;r<s;r++)n^=t.charCodeAt(r),n+=(n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24);return n>>>0},ot=t=>t!=null&&t.length>0,ct=t=>u(M(t),"_"," "),at=t=>t.length>0&&!Rt.test(t),ut=t=>Pt.test(t),lt=t=>!Dt.test(t),gt=t=>t.toLowerCase()===t,pt=t=>t.toUpperCase()===t,ht=(t,e)=>t!=null&&t!==""?t:e,ft=t=>Zt.test(t),dt=t=>t==null||t==="",Ct=t=>t.substring(0,1).toLowerCase()+t.substring(1),E=(t,e=1)=>t.substring(Math.floor((t.length-e+1)*Math.random()),e),x=(t,e)=>c.generateArray(e,()=>E(t)).join(""),St=t=>x(Ht,t),At=(t,e)=>p(e).map(t),bt=(t,e)=>u(t,e,""),mt=(t,e)=>d(t,e)?t.substring(0,t.length-e.length):t,Lt=(t,e,n)=>t.substring(0,e)+t.substring(e+n),It=(t,e)=>L(t,e)?t.substring(e.length):t,wt=(t,e)=>{const n=t.indexOf(e);return n<0?t:t.substring(0,n)+t.substring(n+e.length)},S=(t,e)=>c.createFilledArray(e,t).join(""),yt=t=>{const e=p(t);return e.reverse(),e.join("")},W=(t,e="'")=>e==="'"?t.includes("'")?t.includes('"')?"'"+u(t,"'","\\'")+"'":'"'+t+'"':"'"+t+"'":t.includes('"')?t.includes("'")?'"'+u(t,'"','\\"')+'"':"'"+t+"'":'"'+t+'"',O=(t,e="'")=>e+u(t,e,"\\"+e)+e,Et=(t,e="'")=>t.indexOf(`
3
+ `)>=0?O(t,"`"):W(t,e),xt=(t,e)=>{const n=t.indexOf(e);return n<0?[t]:[t.substring(0,n),t.substring(n+e.length)]},B=(t,e)=>c.anyElement(e,n=>t.startsWith(n)),Wt=(t,e,n=e)=>`${e}${t}${n}`,p=t=>t.split(""),T=t=>c.generateArray(t.length,e=>t.charCodeAt(e)),Ot=(t,e)=>{const n=[];for(;t.length>0;)n.push(t.substring(0,e)),t=t.substring(e,t.length-e);return n},Bt=t=>t.split(U),Tt=(t,e)=>j(z(t,e),e),z=(t,e)=>{let n=0;for(let r=0;r<t.length&&l(e,t.charAt(r));r++)n++;return t.substring(n)},j=(t,e)=>{const n=t.length;let r=n,s;for(let a=0;a<n&&(s=n-a-1,l(e,t.charAt(s)));a++)r=s;return t.substring(0,r)},M=t=>(t=t.replace(/::/g,"/"),t=t.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2"),t=t.replace(/([a-z\d])([A-Z])/g,"$1_$2"),t=t.replace(/-/g,"_"),t.toLowerCase()),zt=t=>t.substring(0,1).toUpperCase()+t.substring(1),jt=(t,e=78,n="",r=`
4
+ `)=>t.split(U).map(s=>N(s.replace(F," ").trim(),e,n,r)).join(r),f=(t,e)=>{if(e<0||e>=t.length)return!1;const n=t.charCodeAt(e);return n===9||n===10||n===11||n===12||n===13||n===32},Mt=t=>{if(typeof Buffer<"u")return Buffer.from(t).toString("base64");if(typeof btoa<"u")return btoa(t);throw new m.MissingImplementationError("No implementation found for base64 encoding")},Nt=t=>{if(typeof Buffer<"u")return Buffer.from(t,"base64").toString("utf8");if(typeof atob<"u")return atob(t);throw new m.MissingImplementationError("No implementation found for base64 decoding")},N=(t,e,n,r)=>{const s=[],a=t.length,g=n.length;let o=0;for(e-=g;;){if(o+e>=a-g){s.push(t.substring(o));break}let i=0;for(;!f(t,o+e-i)&&i<e;)i++;if(i===e){for(i=0;!f(t,o+e+i)&&o+e+i<a;)i++;s.push(t.substring(o,o+e+i)),o+=e+i+1}else s.push(t.substring(o,o+e-i)),o+=e-i+1}return n+s.join(r+n)},Ft=(t,e,n)=>{const r=n-t.length;return r>0?S(e,r)+t:t},Ut=(t,e,n)=>{const r=n-t.length;return r>0?t+S(e,r):t},_t=(t,e)=>{const n=t.lastIndexOf(e);return n>=0?[t.substring(0,n),t.substring(n+e.length)]:[t]},kt=(t,e)=>{const n=t.indexOf(e);return n>=0?[t.substring(0,n),t.substring(n+e.length)]:[t]},Ht="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",$t=/[^a-zA-Z]([a-z])/g,Dt=/[^\t\n\r ]/,Rt=/[^a-zA-Z]/,qt=/[ \t\r\n][a-z]/g,Pt=/^[a-z0-9]+$/i,Zt=/^[0-9]+$/,F=/[ \t\r\n]+/g,U=/\r\n|\n\r|\n|\r/g,Qt=/\r\n|\n\r|\r/g;exports.canonicalizeNewlines=R;exports.capitalize=h;exports.capitalizeWords=D;exports.chunkString=Ot;exports.collapseText=K;exports.compareCaseInsensitive=q;exports.compareStrings=I;exports.containsAllText=v;exports.containsAllTextCaseInsensitive=Y;exports.containsAnyText=X;exports.containsAnyTextCaseInsensitive=V;exports.countStringOccurrences=J;exports.dasherize=tt;exports.decodeBase64=Nt;exports.deleteFirstFromString=wt;exports.deleteStringAfter=mt;exports.deleteStringBefore=It;exports.deleteSubstring=bt;exports.ellipsis=w;exports.ellipsisMiddle=nt;exports.encodeBase64=Mt;exports.filterCharcodes=st;exports.filterChars=rt;exports.humanize=ct;exports.ifEmptyString=ht;exports.isAlpha=at;exports.isAlphaNum=ut;exports.isBreakingWhitespace=lt;exports.isDigitsOnly=ft;exports.isEmptyString=dt;exports.isLowerCase=gt;exports.isSpaceAt=f;exports.isUpperCase=pt;exports.jsQuote=Et;exports.lowerCaseFirst=Ct;exports.lpad=Ft;exports.mapChars=At;exports.quote=O;exports.randomString=E;exports.randomStringSequence=x;exports.randomStringSequenceBase64=St;exports.repeatString=S;exports.replaceAll=u;exports.reverseString=yt;exports.rpad=Ut;exports.smartQuote=W;exports.splitStringOnFirst=kt;exports.splitStringOnLast=_t;exports.splitStringOnce=xt;exports.stringContains=l;exports.stringEndsWith=d;exports.stringEndsWithAny=y;exports.stringHasContent=ot;exports.stringHashCode=it;exports.stringStartsWith=L;exports.stringStartsWithAny=B;exports.stringToCharcodes=T;exports.stringToChars=p;exports.stringsDifferAtIndex=et;exports.substringAfter=_;exports.substringAfterLast=k;exports.substringBefore=H;exports.substringBeforeLast=$;exports.surroundString=Wt;exports.textContainsCaseInsensitive=C;exports.textEndsWithAnyCaseInsensitive=Q;exports.textEndsWithCaseInsensitive=P;exports.textStartsWithAnyCaseInsensitive=G;exports.textStartsWithCaseInsensitive=Z;exports.textToLines=Bt;exports.trimChars=Tt;exports.trimCharsLeft=z;exports.trimCharsRight=j;exports.trimStringSlice=Lt;exports.underscore=M;exports.upperCaseFirst=zt;exports.wrapColumns=jt;exports.wrapLine=N;