@rtorcato/js-common 1.6.0 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.7.0](https://github.com/rtorcato/js-common/compare/v1.6.0...v1.7.0) (2026-01-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * **strings:** add 12 new string utility functions ([03df6fc](https://github.com/rtorcato/js-common/commit/03df6fc4168c1343be47434a2b4c842be394f61c))
7
+
1
8
  # [1.6.0](https://github.com/rtorcato/js-common/compare/v1.5.0...v1.6.0) (2026-01-16)
2
9
 
3
10
 
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";var o=null;async function a(){if(o)return o;let{default:r}=await import("./currencies.js");return o=r,r}var l=r=>{try{let n=new Intl.NumberFormat("en",{currency:r,style:"currency"}).formatToParts(0).find(e=>e.type==="currency");return n?.value==="\xA4"?void 0:n?.value}catch{return}};function m(r,n="en"){try{return new Intl.DisplayNames([n],{type:"currency"}).of(r.toUpperCase())}catch{return}}function i(r){return{USD:"en-US",EUR:"de-DE",GBP:"en-GB",JPY:"ja-JP",CNY:"zh-CN",CAD:"en-CA",AUD:"en-AU",CHF:"de-CH",NZD:"en-NZ",SGD:"en-SG",HKD:"zh-HK",KRW:"ko-KR",INR:"en-IN",BRL:"pt-BR",MXN:"es-MX",RUB:"ru-RU",ZAR:"en-ZA",SEK:"sv-SE",NOK:"nb-NO",DKK:"da-DK",PLN:"pl-PL",TRY:"tr-TR",THB:"th-TH",MYR:"ms-MY",PHP:"en-PH",IDR:"id-ID",CZK:"cs-CZ",HUF:"hu-HU",ILS:"he-IL",TWD:"zh-TW"}[r.toUpperCase()]??"en"}function p(r,n="USD",e){let t=e??i(n);return new Intl.NumberFormat(t,{style:"currency",currency:n}).format(Number(r))}function d(r,n="USD",e){let t=e??i(n);return new Intl.NumberFormat(t,{style:"currency",currency:n,notation:"compact",compactDisplay:"short"}).format(Number(r))}function s(r){let n=/\d+\.\d{3},\d{2}$/.test(r),e=r;n&&(e=r.replace(/\./g,"").replace(",","."));let t=e.replace(/[^0-9.-]+/g,""),c=Number.parseFloat(t);return Number.isNaN(c)?null:c}function f(r){let n={$:"USD","\u20AC":"EUR","\xA3":"GBP","\xA5":"JPY","\u20B9":"INR","\u20BD":"RUB",R$:"BRL","\u20A9":"KRW","\u0E3F":"THB","\u20AA":"ILS","\u20B1":"PHP","\u20AB":"VND",kr:"SEK",CHF:"CHF",C$:"CAD",A$:"AUD",NZ$:"NZD",HK$:"HKD",S$:"SGD"},e=r.match(/\b([A-Z]{3})\b/);if(e&&e[1]){let t=s(r);if(t!==null)return{amount:t,currency:e[1]}}for(let[t,c]of Object.entries(n))if(r.includes(t)){let u=s(r);if(u!==null)return{amount:u,currency:c}}return null}function y(r,n,e=2){return Number.parseFloat((r*n).toFixed(e))}async function g(r){return(await a()).includes(r.toUpperCase())}function b(r){try{return new Intl.NumberFormat("en",{style:"currency",currency:r}),!0}catch{return!1}}function C(r,n=2){let e=10**n;return Math.round(r*e)/e}export{y as convertCurrency,p as formatPrice,d as formatPriceCompact,i as getCurrencyLocale,m as getCurrencyName,l as getCurrencySymbol,b as isValidCurrency,g as isValidCurrencyCode,f as parseCurrencyString,s as parsePrice,C as roundTo};
1
+ import"../chunks/chunk-ANN5UYCF.js";var o=null;async function a(){if(o)return o;let{default:r}=await import("./currencies.js");return o=r,r}var l=r=>{try{let n=new Intl.NumberFormat("en",{currency:r,style:"currency"}).formatToParts(0).find(e=>e.type==="currency");return n?.value==="\xA4"?void 0:n?.value}catch{return}};function m(r,n="en"){try{return new Intl.DisplayNames([n],{type:"currency"}).of(r.toUpperCase())}catch{return}}function i(r){return{USD:"en-US",EUR:"de-DE",GBP:"en-GB",JPY:"ja-JP",CNY:"zh-CN",CAD:"en-CA",AUD:"en-AU",CHF:"de-CH",NZD:"en-NZ",SGD:"en-SG",HKD:"zh-HK",KRW:"ko-KR",INR:"en-IN",BRL:"pt-BR",MXN:"es-MX",RUB:"ru-RU",ZAR:"en-ZA",SEK:"sv-SE",NOK:"nb-NO",DKK:"da-DK",PLN:"pl-PL",TRY:"tr-TR",THB:"th-TH",MYR:"ms-MY",PHP:"en-PH",IDR:"id-ID",CZK:"cs-CZ",HUF:"hu-HU",ILS:"he-IL",TWD:"zh-TW"}[r.toUpperCase()]??"en"}function p(r,n="USD",e){let t=e??i(n);return new Intl.NumberFormat(t,{style:"currency",currency:n}).format(Number(r))}function d(r,n="USD",e){let t=e??i(n);return new Intl.NumberFormat(t,{style:"currency",currency:n,notation:"compact",compactDisplay:"short"}).format(Number(r))}function s(r){let n=/\d+\.\d{3},\d{2}$/.test(r),e=r;n&&(e=r.replace(/\./g,"").replace(",","."));let t=e.replace(/[^0-9.-]+/g,""),c=Number.parseFloat(t);return Number.isNaN(c)?null:c}function f(r){let n={$:"USD","\u20AC":"EUR","\xA3":"GBP","\xA5":"JPY","\u20B9":"INR","\u20BD":"RUB",R$:"BRL","\u20A9":"KRW","\u0E3F":"THB","\u20AA":"ILS","\u20B1":"PHP","\u20AB":"VND",kr:"SEK",CHF:"CHF",C$:"CAD",A$:"AUD",NZ$:"NZD",HK$:"HKD",S$:"SGD"},e=r.match(/\b([A-Z]{3})\b/);if(e?.[1]){let t=s(r);if(t!==null)return{amount:t,currency:e[1]}}for(let[t,c]of Object.entries(n))if(r.includes(t)){let u=s(r);if(u!==null)return{amount:u,currency:c}}return null}function y(r,n,e=2){return Number.parseFloat((r*n).toFixed(e))}async function g(r){return(await a()).includes(r.toUpperCase())}function b(r){try{return new Intl.NumberFormat("en",{style:"currency",currency:r}),!0}catch{return!1}}function C(r,n=2){let e=10**n;return Math.round(r*e)/e}export{y as convertCurrency,p as formatPrice,d as formatPriceCompact,i as getCurrencyLocale,m as getCurrencyName,l as getCurrencySymbol,b as isValidCurrency,g as isValidCurrencyCode,f as parseCurrencyString,s as parsePrice,C as roundTo};
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";function i(r){return r.replace(/\w\S*/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())}function s(r){return r.length===0?"":(r[0]?.toUpperCase()??"")+r.slice(1)}function a(r){return r.replace(/[-_\s]+(.)?/g,(e,t)=>t?t.toUpperCase():"").replace(/^(.)/,e=>e.toLowerCase())}function g(r){return r.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}function o(r){return r.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function p(r,e){return r.length>e?`${r.slice(0,e-1)}\u2026`:r}function c(r,e,t=" "){return r.padStart(e,t)}function u(r,e,t=" "){return r.padEnd(e,t)}var l=(r,e)=>{let t="";for(let n=r;n>0;--n)t+=e[Math.floor(Math.random()*e.length)];return t},f=(r,e,t)=>r.replace(new RegExp(e,"g"),t);function C(r){return r.replace(/<script.*?>.*?<\/script>/gi,"").replace(/on\w+\s*=\s*(['"]).*?\1/gi,"")}export{a as camelCase,s as capitalize,g as kebabCase,u as padEnd,c as padStart,l as randomString,f as replaceString,C as sanitizeString,o as snakeCase,i as titleCase,p as truncate};
1
+ import"../chunks/chunk-ANN5UYCF.js";function s(r){return r.replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase())}function o(r){return r.length===0?"":(r[0]?.toUpperCase()??"")+r.slice(1)}function g(r){return r.replace(/[-_\s]+(.)?/g,(t,e)=>e?e.toUpperCase():"").replace(/^(.)/,t=>t.toLowerCase())}function a(r){return r.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}function p(r){return r.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function c(r,t){return r.length>t?`${r.slice(0,t-1)}\u2026`:r}function u(r,t,e=" "){return r.padStart(t,e)}function l(r,t,e=" "){return r.padEnd(t,e)}var f=(r,t)=>{let e="";for(let n=r;n>0;--n)e+=t[Math.floor(Math.random()*t.length)];return e},x=(r,t,e)=>r.replace(new RegExp(t,"g"),e);function m(r){return r.replace(/<script.*?>.*?<\/script>/gi,"").replace(/on\w+\s*=\s*(['"]).*?\1/gi,"")}function b(r){return[...r].reverse().join("")}function $(r){return r.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim().replace(/[^a-z0-9\s-]/g,"").replace(/[\s_]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function h(r){return r.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[-_]+/g," ").trim().split(/\s+/).filter(Boolean)}function w(r){let t=r.trim();return t===""?0:t.split(/\s+/).length}function d(r){let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return r.replace(/[&<>"']/g,e=>t[e]??e)}function C(r){let t={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&#x27;":"'","&#x2F;":"/","&nbsp;":" "};return r.replace(/&(?:amp|lt|gt|quot|#39|#x27|#x2F|nbsp);/g,e=>t[e]??e)}function z(r){return r.replace(/<[^>]*>/g,"")}function S(r,t,e){return t===1?r:e??`${r}s`}function _(r){let t=Math.abs(r),e=t%100,n=t%10;if(e>=11&&e<=13)return`${r}th`;switch(n){case 1:return`${r}st`;case 2:return`${r}nd`;case 3:return`${r}rd`;default:return`${r}th`}}function k(r){return r.trim().length===0}function A(r,t,e,n="*"){if(t<0&&(t=0),e>r.length&&(e=r.length),t>=e)return r;let i=n.repeat(e-t);return r.slice(0,t)+i+r.slice(e)}function E(r,t){return r.replace(/\$\{(\w+)\}/g,(e,n)=>Object.hasOwn(t,n)?String(t[n]):e)}export{g as camelCase,o as capitalize,d as escapeHtml,k as isBlank,a as kebabCase,A as mask,_ as ordinalize,l as padEnd,u as padStart,S as pluralize,f as randomString,x as replaceString,b as reverse,m as sanitizeString,$ as slugify,p as snakeCase,z as stripHtml,E as template,s as titleCase,c as truncate,C as unescapeHtml,w as wordCount,h as words};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtorcato/js-common",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "JavaScript and TypeScript common code",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",