@thi.ng/strings
Advanced tools
Comparing version 1.10.0 to 1.11.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.11.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@1.10.0...@thi.ng/strings@1.11.0) (2020-11-24) | ||
### Features | ||
* **strings:** add split() iterator ([6d2ec4f](https://github.com/thi-ng/umbrella/commit/6d2ec4fccc688acf5a541ea51c9705faca1c9835)) | ||
# [1.10.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/strings@1.9.6...@thi.ng/strings@1.10.0) (2020-09-22) | ||
@@ -8,0 +19,0 @@ |
@@ -21,2 +21,3 @@ export * from "./api"; | ||
export * from "./splice"; | ||
export * from "./split"; | ||
export * from "./trim"; | ||
@@ -23,0 +24,0 @@ export * from "./truncate"; |
@@ -21,2 +21,3 @@ export * from "./api"; | ||
export * from "./splice"; | ||
export * from "./split"; | ||
export * from "./trim"; | ||
@@ -23,0 +24,0 @@ export * from "./truncate"; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var memoize = require('@thi.ng/memoize'); | ||
var hex = require('@thi.ng/hex'); | ||
var errors = require('@thi.ng/errors'); | ||
@@ -65,7 +66,7 @@ | ||
const B32 = radix(2, 32); | ||
const U8 = radix(16, 2); | ||
const U16 = radix(16, 4); | ||
const U24 = radix(16, 6); | ||
const U32 = radix(16, 8); | ||
const U64 = (hi, lo) => U32(hi) + U32(lo); | ||
const U8 = hex.U8; | ||
const U16 = hex.U16; | ||
const U24 = hex.U24; | ||
const U32 = hex.U32; | ||
const U64 = hex.U64HL; | ||
@@ -264,2 +265,18 @@ const ESCAPES = { | ||
function* split(src, delim = /(\r\n)|\n|\r/g, includeDelim = false) { | ||
let i = 0; | ||
const n = src.length; | ||
const include = ~~includeDelim; | ||
for (; i < n;) { | ||
const m = delim.exec(src); | ||
if (!m) { | ||
yield src.substring(i); | ||
return; | ||
} | ||
const len = m[0].length; | ||
yield src.substring(i, m.index + include * len); | ||
i = m.index + len; | ||
} | ||
} | ||
const trim = memoize.memoize1((chars = " \t\n\r") => { | ||
@@ -344,24 +361,11 @@ chars = `(${chars | ||
const uuid = (id, i = 0) => [ | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
].join(""); | ||
const uuid = (id, i = 0) => hex.U32BE(id, i) + | ||
"-" + | ||
hex.U16BE(id, i + 4) + | ||
"-" + | ||
hex.U16BE(id, i + 6) + | ||
"-" + | ||
hex.U16BE(id, i + 8) + | ||
"-" + | ||
hex.U48BE(id, i + 10); | ||
@@ -424,2 +428,3 @@ const wrap = memoize.memoizeJ((pad) => (x) => pad + x + pad); | ||
exports.splice = splice; | ||
exports.split = split; | ||
exports.str = str; | ||
@@ -426,0 +431,0 @@ exports.trim = trim; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/memoize"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/memoize","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.strings={}),e.thi.ng.memoize,e.thi.ng.errors)}(this,(function(e,t,r){"use strict";const n=e=>e.toUpperCase(),o=e=>e.toLowerCase(),s=(e,t="-")=>o(e.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,(e,r,n)=>r+t+n)),i=e=>s(e,"_"),a=t.memoizeJ((e,t)=>e.repeat(t)),g=t.memoizeJ((e,t="")=>r=>r.length>e?r.substr(0,e-t.length)+t:r),l=g,c=t.memoizeJ((e,t=" ")=>{const r=a(String(t),e);return t=>{if(null==t)return r;t=t.toString();const n=(e-t.length)/2;return t.length<e?r.substr(0,n)+t+r.substr(0,n+((1&e)==(1&t.length)?0:1)):g(e)(t)}}),u=t.memoizeJ((e,t,r="")=>{const n=a("0",t);return o=>(o=(o>>>0).toString(e),r+(o.length<t?n.substr(o.length)+o:o))}),p=u(2,8),f=u(2,16),m=u(2,32),h=u(16,2),b=u(16,4),d=u(16,6),z=u(16,8),C={0:"\0",b:"\b",t:"\t",r:"\r",v:"\v",f:"\f",n:"\n","'":"'",'"':'"',"\\":"\\"},S={0:"0",8:"b",9:"t",10:"n",11:"v",12:"f",13:"r",33:"'",34:'"',92:"\\"},x=t.memoizeJ((e,t=" ")=>{const r=a(String(t),e);return t=>null!=t?(t=t.toString()).length<e?r.substr(t.length)+t:t:r}),y=x(2,"0"),j=x(3,"0"),A=x(4,"0"),M=t.memoizeJ(e=>t=>P(t)||t.toFixed(e)),w=t.memoizeJ((e,t=3)=>{const r=e-t-1,n=Math.pow(10,r),o=-Math.pow(10,r-1),s=Math.pow(10,-(t-1)),i=x(e);return r=>{const a=Math.abs(r);return i(P(r)||(0===r?"0":a<s||a>=n?O(r,e):r.toFixed(t-(r<o?1:0))))}}),O=(e,t)=>e.toExponential(Math.max(t-4-(Math.log(Math.abs(e))/Math.LN10>=10?2:1)-(e<0?1:0),0)),P=e=>isNaN(e)?"NaN":e===1/0?"+∞":e===-1/0?"-∞":void 0,U=(e,...t)=>{const r=[];for(let n=0,o=0,s=e.length;n<s;n++){const s=e[n],i=typeof s;r.push("function"===i?s(t[o++]):"object"===i?s[t[o++]]:s)}return r.join("")};function*E(e,t){let r="string"==typeof e?e.charCodeAt(0):e;const n="string"==typeof t?t.charCodeAt(0):t;if(r<=n)for(;r<=n;r++)yield String.fromCharCode(r);else for(;r>=n;r--)yield String.fromCharCode(r)}const N=(...e)=>{const t={};for(let r of e)for(let e of r)t[e]=!0;return Object.freeze(t)},F=Object.freeze({"\t":!0,"\n":!0,"\v":!0,"\f":!0,"\r":!0," ":!0}),J=N(E("0","9")),B=N(E("0","9"),E("A","F"),E("a","f")),L=N(E("a","z")),R=N(E("A","Z")),$=Object.freeze(Object.assign(Object.assign({},R),L)),v=Object.freeze(Object.assign(Object.assign(Object.assign({},$),J),{_:!0})),I=N(E("!","/"),E(":","@"),E("[","`"),E("{","~")),_=/\{(\d+)\}/g,k=t.memoize1(e=>t=>t.join(e)),T=t.memoizeJ((e,t=" ")=>{const r=a(String(t),e);return t=>null!=t?(t=t.toString()).length<e?t+r.substr(t.length):t:r}),H="àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;",Z="aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------",G=new RegExp(H.split("").join("|"),"g"),W=t.memoize1((e=" \t\n\r")=>{e=`(${e.split("").map(e=>"\\"+e).join("|")})`;const t=new RegExp(`(^${e}+)|(${e}+$)`,"g");return e=>e.replace(t,"")}),q=t.memoizeJ((e,t="")=>r=>r.length>e?t+r.substr(r.length-e+t.length):r),K=t.memoizeJ((e,t,r=2)=>{const n=e.map(e=>[e[0],null!=e[2]?e[2]:r,e[1]]).sort((e,t)=>e[0]-t[0]);return e=>{if(0===e)return"0"+t;const r=Math.abs(e);for(let t=n.length;--t>=0;){const o=n[t];if(r>=o[0]||0===t)return(e/o[0]).toFixed(o[1])+o[2]}return""}}),D=1024,V=K([[1," bits",0],[D," Kb"],[D**2," Mb"],[D**3," Gb"]]," bits",2),X=K([[1," bytes",0],[D," KB"],[D**2," MB"],[D**3," GB"],[D**4," TB"],[D**5," PB"]]," bytes",2),Q=K([[1e-12," ps"],[1e-9," ns"],[1e-6," µs"],[.001," ms"],[1," secs"],[60," mins"],[3600," hours"],[86400," days"]]," secs",3),Y=K([[1e-12," pm"],[1e-9," nm"],[1e-6," µm"],[.001," mm"],[.01," cm"],[1," m"],[1e3," km"]]," m",2),ee=K([[1e-12," pg"],[1e-9," ng"],[1e-6," µg"],[.001," mg"],[1," g"],[1e3," kg"],[1e6," t"],[1e9," kt"],[1e12," Mt"]]," g",2),te=t.memoizeJ(e=>t=>e+t+e);e.ALPHA=$,e.ALPHA_NUM=v,e.B16=f,e.B32=m,e.B8=p,e.BOM="\ufeff",e.DIGITS=J,e.ESCAPES=C,e.ESCAPES_REV=S,e.HEX=B,e.LOWER=L,e.PUNCTUATION=I,e.U16=b,e.U24=d,e.U32=z,e.U64=(e,t)=>z(e)+z(t),e.U8=h,e.UPPER=R,e.WS=F,e.Z2=y,e.Z3=j,e.Z4=A,e.bits=V,e.bytes=X,e.camel=(e,t="-")=>o(e).replace(new RegExp(`\\${t}+(\\w)`,"g"),(e,t)=>n(t)),e.capitalize=e=>e[0].toUpperCase()+e.substr(1),e.center=c,e.charRange=E,e.computeCursorPos=(e,t,r="\n")=>{if(!e.length)return[1,1];t=Math.min(Math.max(0,t),e.length);const n=e.split(r),o=n.length;for(let e=0;e<o;e++){const r=n[e];if(t<=r.length)return[e+1,t+1];t-=r.length+1}return[o,1]},e.defFormat=e=>(...t)=>U(e,...t),e.escape=e=>e.replace(/[\0\b\t\n\v\f\r'"\\]/g,e=>"\\"+S[e.charCodeAt(0)]).replace(/[\ud800-\udfff]{2}/g,e=>"\\U"+z(e.codePointAt(0))).replace(/[^\u0020-\u007e]/g,e=>"\\u"+b(e.charCodeAt(0))),e.float=M,e.floatFixedWidth=w,e.format=U,e.grams=ee,e.hstr=e=>null!=e?`${(e=e.toString()).length}H${e}`:"",e.ignore=e=>"",e.interpolate=(e,...t)=>t.length>0?e.replace(_,e=>String(t[parseInt(e[1],10)])):e,e.join=k,e.kebab=s,e.lower=o,e.maybeParseFloat=(e,t=0)=>{const r=parseFloat(e);return isNaN(r)?t:r},e.maybeParseInt=(e,t=0,r=10)=>{const n=parseInt(e,r);return isNaN(n)?t:n},e.meters=Y,e.padLeft=x,e.padRight=T,e.percent=(e=0)=>t=>(100*t).toFixed(e)+"%",e.radix=u,e.repeat=a,e.seconds=Q,e.slugify=e=>e.toLowerCase().replace(/\s+/g,"-").replace(G,e=>Z[H.indexOf(e)]).replace(/&+/g,"-and-").replace(/[^\w\-]+/g,"").replace(/\-{2,}/g,"-").replace(/(^-+)|(-+$)/g,""),e.slugifyGH=e=>e.toLowerCase().replace(/\s/g,"-").replace(G,e=>Z[H.indexOf(e)]).replace(/[^\w\-]+/g,"").replace(/(^-+)|(-+$)/g,""),e.snake=i,e.splice=(e,t,n,o=n)=>(n<0&&(n+=e.length),o<0&&(o+=e.length),n>o&&r.illegalArgs("'from' index must be <= 'to'"),o=Math.max(o,0),n<=0?t+e.substr(o):n>=e.length?e+t:e.substr(0,n)+t+e.substr(o)),e.str=e=>String(e),e.trim=W,e.truncate=g,e.truncateLeft=q,e.truncateRight=l,e.unescape=e=>e.replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\\U([0-9a-fA-F]{8})/g,(e,t)=>String.fromCodePoint(parseInt(t,16))).replace(/\\([0btnvfr'"\\])/g,(e,t)=>C[t]),e.units=K,e.upper=n,e.upperSnake=e=>i(e).toUpperCase(),e.uuid=(e,t=0)=>[h(e[t++]),h(e[t++]),h(e[t++]),h(e[t++]),"-",h(e[t++]),h(e[t++]),"-",h(e[t++]),h(e[t++]),"-",h(e[t++]),h(e[t++]),"-",h(e[t++]),h(e[t++]),h(e[t++]),h(e[t++]),h(e[t++]),h(e[t++])].join(""),e.wrap=te,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/memoize"),require("@thi.ng/hex"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/memoize","@thi.ng/hex","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.strings={}),e.thi.ng.memoize,e.thi.ng.hex,e.thi.ng.errors)}(this,(function(e,t,n,r){"use strict";const o=e=>e.toUpperCase(),s=e=>e.toLowerCase(),i=(e,t="-")=>s(e.replace(/([a-z0-9\u00e0-\u00fd])([A-Z\u00c0-\u00dd])/g,((e,n,r)=>n+t+r))),a=e=>i(e,"_"),g=t.memoizeJ(((e,t)=>e.repeat(t))),l=t.memoizeJ(((e,t="")=>n=>n.length>e?n.substr(0,e-t.length)+t:n)),c=l,u=t.memoizeJ(((e,t=" ")=>{const n=g(String(t),e);return t=>{if(null==t)return n;t=t.toString();const r=(e-t.length)/2;return t.length<e?n.substr(0,r)+t+n.substr(0,r+((1&e)==(1&t.length)?0:1)):l(e)(t)}})),p=t.memoizeJ(((e,t,n="")=>{const r=g("0",t);return o=>(o=(o>>>0).toString(e),n+(o.length<t?r.substr(o.length)+o:o))})),h=p(2,8),f=p(2,16),m=p(2,32),d=n.U8,b=n.U16,x=n.U24,z=n.U32,U=n.U64HL,y={0:"\0",b:"\b",t:"\t",r:"\r",v:"\v",f:"\f",n:"\n","'":"'",'"':'"',"\\":"\\"},C={0:"0",8:"b",9:"t",10:"n",11:"v",12:"f",13:"r",33:"'",34:'"',92:"\\"},S=t.memoizeJ(((e,t=" ")=>{const n=g(String(t),e);return t=>null!=t?(t=t.toString()).length<e?n.substr(t.length)+t:t:n})),A=S(2,"0"),M=S(3,"0"),j=S(4,"0"),E=t.memoizeJ((e=>t=>B(t)||t.toFixed(e))),w=t.memoizeJ(((e,t=3)=>{const n=e-t-1,r=Math.pow(10,n),o=-Math.pow(10,n-1),s=Math.pow(10,-(t-1)),i=S(e);return n=>{const a=Math.abs(n);return i(B(n)||(0===n?"0":a<s||a>=r?O(n,e):n.toFixed(t-(n<o?1:0))))}})),O=(e,t)=>e.toExponential(Math.max(t-4-(Math.log(Math.abs(e))/Math.LN10>=10?2:1)-(e<0?1:0),0)),B=e=>isNaN(e)?"NaN":e===1/0?"+∞":e===-1/0?"-∞":void 0,P=(e,...t)=>{const n=[];for(let r=0,o=0,s=e.length;r<s;r++){const s=e[r],i=typeof s;n.push("function"===i?s(t[o++]):"object"===i?s[t[o++]]:s)}return n.join("")};function*$(e,t){let n="string"==typeof e?e.charCodeAt(0):e;const r="string"==typeof t?t.charCodeAt(0):t;if(n<=r)for(;n<=r;n++)yield String.fromCharCode(n);else for(;n>=r;n--)yield String.fromCharCode(n)}const N=(...e)=>{const t={};for(let n of e)for(let e of n)t[e]=!0;return Object.freeze(t)},F=Object.freeze({"\t":!0,"\n":!0,"\v":!0,"\f":!0,"\r":!0," ":!0}),J=N($("0","9")),L=N($("0","9"),$("A","F"),$("a","f")),v=N($("a","z")),R=N($("A","Z")),I=Object.freeze(Object.assign(Object.assign({},R),v)),_=Object.freeze(Object.assign(Object.assign(Object.assign({},I),J),{_:!0})),k=N($("!","/"),$(":","@"),$("[","`"),$("{","~")),H=/\{(\d+)\}/g,T=t.memoize1((e=>t=>t.join(e))),Z=t.memoizeJ(((e,t=" ")=>{const n=g(String(t),e);return t=>null!=t?(t=t.toString()).length<e?t+n.substr(t.length):t:n})),G="àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;",q="aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------",W=new RegExp(G.split("").join("|"),"g");const K=t.memoize1(((e=" \t\n\r")=>{e=`(${e.split("").map((e=>`\\${e}`)).join("|")})`;const t=new RegExp(`(^${e}+)|(${e}+$)`,"g");return e=>e.replace(t,"")})),D=t.memoizeJ(((e,t="")=>n=>n.length>e?t+n.substr(n.length-e+t.length):n)),V=t.memoizeJ(((e,t,n=2)=>{const r=e.map((e=>[e[0],null!=e[2]?e[2]:n,e[1]])).sort(((e,t)=>e[0]-t[0]));return e=>{if(0===e)return`0${t}`;const n=Math.abs(e);for(let t=r.length;--t>=0;){const o=r[t];if(n>=o[0]||0===t)return(e/o[0]).toFixed(o[1])+o[2]}return""}})),X=1024,Q=V([[1," bits",0],[X," Kb"],[X**2," Mb"],[X**3," Gb"]]," bits",2),Y=V([[1," bytes",0],[X," KB"],[X**2," MB"],[X**3," GB"],[X**4," TB"],[X**5," PB"]]," bytes",2),ee=V([[1e-12," ps"],[1e-9," ns"],[1e-6," µs"],[.001," ms"],[1," secs"],[60," mins"],[3600," hours"],[86400," days"]]," secs",3),te=V([[1e-12," pm"],[1e-9," nm"],[1e-6," µm"],[.001," mm"],[.01," cm"],[1," m"],[1e3," km"]]," m",2),ne=V([[1e-12," pg"],[1e-9," ng"],[1e-6," µg"],[.001," mg"],[1," g"],[1e3," kg"],[1e6," t"],[1e9," kt"],[1e12," Mt"]]," g",2),re=t.memoizeJ((e=>t=>e+t+e));e.ALPHA=I,e.ALPHA_NUM=_,e.B16=f,e.B32=m,e.B8=h,e.BOM="\ufeff",e.DIGITS=J,e.ESCAPES=y,e.ESCAPES_REV=C,e.HEX=L,e.LOWER=v,e.PUNCTUATION=k,e.U16=b,e.U24=x,e.U32=z,e.U64=U,e.U8=d,e.UPPER=R,e.WS=F,e.Z2=A,e.Z3=M,e.Z4=j,e.bits=Q,e.bytes=Y,e.camel=(e,t="-")=>s(e).replace(new RegExp(`\\${t}+(\\w)`,"g"),((e,t)=>o(t))),e.capitalize=e=>e[0].toUpperCase()+e.substr(1),e.center=u,e.charRange=$,e.computeCursorPos=(e,t,n="\n")=>{if(!e.length)return[1,1];t=Math.min(Math.max(0,t),e.length);const r=e.split(n),o=r.length;for(let e=0;e<o;e++){const n=r[e];if(t<=n.length)return[e+1,t+1];t-=n.length+1}return[o,1]},e.defFormat=e=>(...t)=>P(e,...t),e.escape=e=>e.replace(/[\0\b\t\n\v\f\r'"\\]/g,(e=>`\\${C[e.charCodeAt(0)]}`)).replace(/[\ud800-\udfff]{2}/g,(e=>`\\U${z(e.codePointAt(0))}`)).replace(/[^\u0020-\u007e]/g,(e=>`\\u${b(e.charCodeAt(0))}`)),e.float=E,e.floatFixedWidth=w,e.format=P,e.grams=ne,e.hstr=e=>null!=e?`${(e=e.toString()).length}H${e}`:"",e.ignore=e=>"",e.interpolate=(e,...t)=>t.length>0?e.replace(H,(e=>String(t[parseInt(e[1],10)]))):e,e.join=T,e.kebab=i,e.lower=s,e.maybeParseFloat=(e,t=0)=>{const n=parseFloat(e);return isNaN(n)?t:n},e.maybeParseInt=(e,t=0,n=10)=>{const r=parseInt(e,n);return isNaN(r)?t:r},e.meters=te,e.padLeft=S,e.padRight=Z,e.percent=(e=0)=>t=>(100*t).toFixed(e)+"%",e.radix=p,e.repeat=g,e.seconds=ee,e.slugify=e=>e.toLowerCase().replace(/\s+/g,"-").replace(W,(e=>q[G.indexOf(e)])).replace(/&+/g,"-and-").replace(/[^\w\-]+/g,"").replace(/\-{2,}/g,"-").replace(/(^-+)|(-+$)/g,""),e.slugifyGH=e=>e.toLowerCase().replace(/\s/g,"-").replace(W,(e=>q[G.indexOf(e)])).replace(/[^\w\-]+/g,"").replace(/(^-+)|(-+$)/g,""),e.snake=a,e.splice=(e,t,n,o=n)=>(n<0&&(n+=e.length),o<0&&(o+=e.length),n>o&&r.illegalArgs("'from' index must be <= 'to'"),o=Math.max(o,0),n<=0?t+e.substr(o):n>=e.length?e+t:e.substr(0,n)+t+e.substr(o)),e.split=function*(e,t=/(\r\n)|\n|\r/g,n=!1){let r=0;const o=e.length,s=~~n;for(;r<o;){const n=t.exec(e);if(!n)return void(yield e.substring(r));const o=n[0].length;yield e.substring(r,n.index+s*o),r=n.index+o}},e.str=e=>String(e),e.trim=K,e.truncate=l,e.truncateLeft=D,e.truncateRight=c,e.unescape=e=>e.replace(/\\u([0-9a-fA-F]{4})/g,((e,t)=>String.fromCharCode(parseInt(t,16)))).replace(/\\U([0-9a-fA-F]{8})/g,((e,t)=>String.fromCodePoint(parseInt(t,16)))).replace(/\\([0btnvfr'"\\])/g,((e,t)=>y[t])),e.units=V,e.upper=o,e.upperSnake=e=>a(e).toUpperCase(),e.uuid=(e,t=0)=>n.U32BE(e,t)+"-"+n.U16BE(e,t+4)+"-"+n.U16BE(e,t+6)+"-"+n.U16BE(e,t+8)+"-"+n.U48BE(e,t+10),e.wrap=re,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@thi.ng/strings", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "Various string formatting & utility functions", | ||
@@ -42,15 +42,16 @@ "module": "./index.js", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@microsoft/api-extractor": "^7.9.11", | ||
"@microsoft/api-extractor": "^7.12.0", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^14.6.1", | ||
"mocha": "^8.1.2", | ||
"mocha": "^8.2.1", | ||
"nyc": "^15.1.0", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.18.0", | ||
"typescript": "^4.0.2" | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.1.2" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/api": "^6.13.1", | ||
"@thi.ng/errors": "^1.2.22", | ||
"@thi.ng/memoize": "^2.1.3" | ||
"@thi.ng/api": "^6.13.2", | ||
"@thi.ng/errors": "^1.2.23", | ||
"@thi.ng/hex": "^0.1.0", | ||
"@thi.ng/memoize": "^2.1.4" | ||
}, | ||
@@ -63,4 +64,2 @@ "files": [ | ||
"keywords": [ | ||
"case", | ||
"center", | ||
"composition", | ||
@@ -91,3 +90,3 @@ "conversion", | ||
}, | ||
"gitHead": "130dff672b56f789205177c2243169d33d479948" | ||
"gitHead": "3a89bdfa4c58983d5e005b3e9fb056b0351198fe" | ||
} |
import type { Stringer } from "./api"; | ||
/** | ||
* Returns a {@link Stringer} which formats given numbers to `radix`, `len` | ||
* and with optional prefix (not included in `len`). | ||
* Returns a {@link Stringer} which formats given numbers to `radix`, `len` and | ||
* with optional prefix (not included in `len`). | ||
* | ||
* @remarks | ||
* Only bases 2 - 36 are supported, due to native `Number.toString()` | ||
* limitations. | ||
* | ||
* @param radix - | ||
@@ -27,3 +31,3 @@ * @param len - | ||
*/ | ||
export declare const U8: Stringer<number>; | ||
export declare const U8: (x: number) => string; | ||
/** | ||
@@ -33,3 +37,3 @@ * 16bit hex conversion preset. | ||
*/ | ||
export declare const U16: Stringer<number>; | ||
export declare const U16: (x: number) => string; | ||
/** | ||
@@ -39,3 +43,3 @@ * 24bit hex conversion preset. | ||
*/ | ||
export declare const U24: Stringer<number>; | ||
export declare const U24: (x: number) => string; | ||
/** | ||
@@ -45,3 +49,3 @@ * 32bit hex conversion preset. | ||
*/ | ||
export declare const U32: Stringer<number>; | ||
export declare const U32: (x: number) => string; | ||
/** | ||
@@ -48,0 +52,0 @@ * 64bit hex conversion preset (2x 32bit ints) |
19
radix.js
@@ -0,7 +1,12 @@ | ||
import { U16 as $16, U24 as $24, U32 as $32, U64HL, U8 as $8, } from "@thi.ng/hex"; | ||
import { memoizeJ } from "@thi.ng/memoize"; | ||
import { repeat } from "./repeat"; | ||
/** | ||
* Returns a {@link Stringer} which formats given numbers to `radix`, `len` | ||
* and with optional prefix (not included in `len`). | ||
* Returns a {@link Stringer} which formats given numbers to `radix`, `len` and | ||
* with optional prefix (not included in `len`). | ||
* | ||
* @remarks | ||
* Only bases 2 - 36 are supported, due to native `Number.toString()` | ||
* limitations. | ||
* | ||
* @param radix - | ||
@@ -34,3 +39,3 @@ * @param len - | ||
*/ | ||
export const U8 = radix(16, 2); | ||
export const U8 = $8; | ||
/** | ||
@@ -40,3 +45,3 @@ * 16bit hex conversion preset. | ||
*/ | ||
export const U16 = radix(16, 4); | ||
export const U16 = $16; | ||
/** | ||
@@ -46,3 +51,3 @@ * 24bit hex conversion preset. | ||
*/ | ||
export const U24 = radix(16, 6); | ||
export const U24 = $24; | ||
/** | ||
@@ -52,3 +57,3 @@ * 32bit hex conversion preset. | ||
*/ | ||
export const U32 = radix(16, 8); | ||
export const U32 = $32; | ||
/** | ||
@@ -58,2 +63,2 @@ * 64bit hex conversion preset (2x 32bit ints) | ||
*/ | ||
export const U64 = (hi, lo) => U32(hi) + U32(lo); | ||
export const U64 = U64HL; |
@@ -55,3 +55,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.72 KB / CJS: 2.97 KB / UMD: 2.84 KB | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.87 KB / CJS: 3.10 KB / UMD: 2.98 KB | ||
@@ -62,2 +62,3 @@ ## Dependencies | ||
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors) | ||
- [@thi.ng/hex](https://github.com/thi-ng/umbrella/tree/develop/packages/hex) | ||
- [@thi.ng/memoize](https://github.com/thi-ng/umbrella/tree/develop/packages/memoize) | ||
@@ -64,0 +65,0 @@ |
@@ -5,6 +5,9 @@ /** | ||
* | ||
* @param id | ||
* @param i | ||
* @remarks | ||
* This is the same function as {@link @thi.ng/random#uuid}. | ||
* | ||
* @param id - | ||
* @param i - | ||
*/ | ||
export declare const uuid: (id: ArrayLike<number>, i?: number) => string; | ||
//# sourceMappingURL=uuid.d.ts.map |
40
uuid.js
@@ -1,2 +0,2 @@ | ||
import { U8 } from "./radix"; | ||
import { U16BE, U32BE, U48BE } from "@thi.ng/hex"; | ||
/** | ||
@@ -6,26 +6,16 @@ * Returns UUID formatted string of given byte array from optional start | ||
* | ||
* @param id | ||
* @param i | ||
* @remarks | ||
* This is the same function as {@link @thi.ng/random#uuid}. | ||
* | ||
* @param id - | ||
* @param i - | ||
*/ | ||
export const uuid = (id, i = 0) => [ | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
"-", | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
U8(id[i++]), | ||
].join(""); | ||
export const uuid = (id, i = 0) => U32BE(id, i) + | ||
"-" + | ||
U16BE(id, i + 4) + | ||
"-" + | ||
U16BE(id, i + 6) + | ||
"-" + | ||
U16BE(id, i + 8) + | ||
"-" + | ||
U48BE(id, i + 10); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116611
64
1676
167
4
+ Added@thi.ng/hex@^0.1.0
+ Added@thi.ng/hex@0.1.3(transitive)
Updated@thi.ng/api@^6.13.2
Updated@thi.ng/errors@^1.2.23
Updated@thi.ng/memoize@^2.1.4