@savantlink/sdk 2.2.4 → 2.2.5
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/services/format.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const titleCase=e=>e.trim().replace(/[_-]+/g," ").replace(/\s+/g," ").toLocaleLowerCase().replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),formatCurrency=(e,t="NGN",r="en-US",a={})=>new Intl.NumberFormat(r,Object.assign(Object.assign({minimumFractionDigits:2,maximumFractionDigits:2},a),{style:"currency",currency:t.toUpperCase()})).format(e),toValidDate=e=>{const t=e instanceof Date?e:new Date(e);if(Number.isNaN(t.getTime()))throw new RangeError("Invalid date");return t},e=formatCurrency,t=formatCurrency;exports.currencyFormatter=e,exports.currencyFormmater=t,exports.formatCurrency=formatCurrency,exports.formatDate=(e,t="short",r="en-GB")=>new Intl.DateTimeFormat(r,{day:"2-digit",month:"long"===t?"long":"short",year:"numeric"}).format(toValidDate(e)),exports.formatDateTime=(e,t="en-GB",r={})=>new Intl.DateTimeFormat(t,Object.assign({day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"},r)).format(toValidDate(e)),exports.formatSlugToString=e=>titleCase(e.replace(/[-_]+/g," ")),exports.formatTime=(e,t="en-US",r={})=>new Intl.DateTimeFormat(t,Object.assign({hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1},r)).format(toValidDate(e)),exports.getRelativeTime=(e,t=Date.now(),r="en")=>{const a=Math.round((toValidDate(e).getTime()-toValidDate(t).getTime())/1e3),o=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[["year",31536e3],["month",2592e3],["week",604800],["day",86400],["hour",3600],["minute",60]].find(([,e])=>Math.abs(a)>=e);return n?o.format(Math.round(a/n[1]),n[0]):"just now"},exports.getTagColor={active:"success",inactive:"danger"},exports.replacePlaceholder=(e,...t)=>e.replace(/{(\d+)}/g,(e,r)=>{var a;return null!==(a=t[Number(r)])&&void 0!==a?a:e}),exports.titleCase=titleCase;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const titleCase=e=>e.trim().replace(/[_-]+/g," ").replace(/\s+/g," ").toLocaleLowerCase().replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),formatCurrency=(e,t="NGN",r="en-US",a={})=>new Intl.NumberFormat(r,Object.assign(Object.assign({minimumFractionDigits:2,maximumFractionDigits:2,currencyDisplay:"narrowSymbol"},a),{style:"currency",currency:t.toUpperCase()})).format(e),toValidDate=e=>{const t=e instanceof Date?e:new Date(e);if(Number.isNaN(t.getTime()))throw new RangeError("Invalid date");return t},e=formatCurrency,t=formatCurrency;exports.currencyFormatter=e,exports.currencyFormmater=t,exports.formatCurrency=formatCurrency,exports.formatDate=(e,t="short",r="en-GB")=>new Intl.DateTimeFormat(r,{day:"2-digit",month:"long"===t?"long":"short",year:"numeric"}).format(toValidDate(e)),exports.formatDateTime=(e,t="en-GB",r={})=>new Intl.DateTimeFormat(t,Object.assign({day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"},r)).format(toValidDate(e)),exports.formatSlugToString=e=>titleCase(e.replace(/[-_]+/g," ")),exports.formatTime=(e,t="en-US",r={})=>new Intl.DateTimeFormat(t,Object.assign({hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1},r)).format(toValidDate(e)),exports.getRelativeTime=(e,t=Date.now(),r="en")=>{const a=Math.round((toValidDate(e).getTime()-toValidDate(t).getTime())/1e3),o=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=[["year",31536e3],["month",2592e3],["week",604800],["day",86400],["hour",3600],["minute",60]].find(([,e])=>Math.abs(a)>=e);return n?o.format(Math.round(a/n[1]),n[0]):"just now"},exports.getTagColor={active:"success",inactive:"danger"},exports.replacePlaceholder=(e,...t)=>e.replace(/{(\d+)}/g,(e,r)=>{var a;return null!==(a=t[Number(r)])&&void 0!==a?a:e}),exports.titleCase=titleCase;
|
|
2
2
|
//# sourceMappingURL=format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sources":["../../src/services/format.ts"],"sourcesContent":["export type DateFormat = 'short' | 'long'\nexport type DateInput = Date | string | number\n\nconst getTagColor = {\n active: 'success',\n inactive: 'danger',\n} as const\n\nconst titleCase = (value: string): string =>\n value\n .trim()\n .replace(/[_-]+/g, ' ')\n .replace(/\\s+/g, ' ')\n .toLocaleLowerCase()\n .replace(/(^|\\s)\\S/g, (letter) => letter.toLocaleUpperCase())\n\nconst formatSlugToString = (value: string): string => titleCase(value.replace(/[-_]+/g, ' '))\n\nconst replacePlaceholder = (template: string, ...replacements: string[]): string =>\n template.replace(/{(\\d+)}/g, (match, index: string) => replacements[Number(index)] ?? match)\n\nconst formatCurrency = (\n amount: number,\n currency = 'NGN',\n locale = 'en-US',\n options: Omit<Intl.NumberFormatOptions, 'style' | 'currency'> = {}\n): string =>\n new Intl.NumberFormat(locale, {\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n ...options,\n style: 'currency',\n currency: currency.toUpperCase(),\n }).format(amount)\n\nconst toValidDate = (value: DateInput): Date => {\n const date = value instanceof Date ? value : new Date(value)\n if (Number.isNaN(date.getTime())) throw new RangeError('Invalid date')\n return date\n}\n\nconst formatDate = (value: DateInput, format: DateFormat = 'short', locale = 'en-GB'): string =>\n new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: format === 'long' ? 'long' : 'short',\n year: 'numeric',\n }).format(toValidDate(value))\n\nconst formatTime = (\n value: DateInput,\n locale = 'en-US',\n options: Intl.DateTimeFormatOptions = {}\n): string =>\n new Intl.DateTimeFormat(locale, {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n ...options,\n }).format(toValidDate(value))\n\nconst formatDateTime = (\n value: DateInput,\n locale = 'en-GB',\n options: Intl.DateTimeFormatOptions = {}\n): string =>\n new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'short',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n ...options,\n }).format(toValidDate(value))\n\nconst getRelativeTime = (value: DateInput, relativeTo: DateInput = Date.now(), locale = 'en'): string => {\n const elapsedSeconds = Math.round((toValidDate(value).getTime() - toValidDate(relativeTo).getTime()) / 1000)\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n const units: Array<[Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 31_536_000],\n ['month', 2_592_000],\n ['week', 604_800],\n ['day', 86_400],\n ['hour', 3_600],\n ['minute', 60],\n ]\n const unit = units.find(([, seconds]) => Math.abs(elapsedSeconds) >= seconds)\n return unit ? formatter.format(Math.round(elapsedSeconds / unit[1]), unit[0]) : 'just now'\n}\n\nconst currencyFormatter = formatCurrency\n// Kept for consumers already using the common misspelling.\nconst currencyFormmater = formatCurrency\n\nexport {\n currencyFormmater,\n currencyFormatter,\n formatCurrency,\n formatDate,\n formatDateTime,\n formatSlugToString,\n formatTime,\n getRelativeTime,\n getTagColor,\n replacePlaceholder,\n titleCase,\n}\n"],"names":["titleCase","value","trim","replace","toLocaleLowerCase","letter","toLocaleUpperCase","formatCurrency","amount","currency","locale","options","Intl","NumberFormat","minimumFractionDigits","maximumFractionDigits","style","toUpperCase","format","toValidDate","date","Date","Number","isNaN","getTime","RangeError","currencyFormatter","currencyFormmater","DateTimeFormat","day","month","year","hour","minute","second","hour12","relativeTo","now","elapsedSeconds","Math","round","formatter","RelativeTimeFormat","numeric","unit","find","seconds","abs","active","inactive","template","replacements","match","index"],"mappings":"0EAQMA,UAAaC,GACjBA,EACGC,OACAC,QAAQ,SAAU,KAClBA,QAAQ,OAAQ,KAChBC,oBACAD,QAAQ,YAAcE,GAAWA,EAAOC,qBAOvCC,eAAiB,CACrBC,EACAC,EAAW,MACXC,EAAS,QACTC,EAAgE,KAEhE,IAAIC,KAAKC,aAAaH,+BACpBI,sBAAuB,EACvBC,sBAAuB,
|
|
1
|
+
{"version":3,"file":"format.js","sources":["../../src/services/format.ts"],"sourcesContent":["export type DateFormat = 'short' | 'long'\nexport type DateInput = Date | string | number\n\nconst getTagColor = {\n active: 'success',\n inactive: 'danger',\n} as const\n\nconst titleCase = (value: string): string =>\n value\n .trim()\n .replace(/[_-]+/g, ' ')\n .replace(/\\s+/g, ' ')\n .toLocaleLowerCase()\n .replace(/(^|\\s)\\S/g, (letter) => letter.toLocaleUpperCase())\n\nconst formatSlugToString = (value: string): string => titleCase(value.replace(/[-_]+/g, ' '))\n\nconst replacePlaceholder = (template: string, ...replacements: string[]): string =>\n template.replace(/{(\\d+)}/g, (match, index: string) => replacements[Number(index)] ?? match)\n\nconst formatCurrency = (\n amount: number,\n currency = 'NGN',\n locale = 'en-US',\n options: Omit<Intl.NumberFormatOptions, 'style' | 'currency'> = {}\n): string =>\n new Intl.NumberFormat(locale, {\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n currencyDisplay: 'narrowSymbol',\n ...options,\n style: 'currency',\n currency: currency.toUpperCase(),\n }).format(amount)\n\nconst toValidDate = (value: DateInput): Date => {\n const date = value instanceof Date ? value : new Date(value)\n if (Number.isNaN(date.getTime())) throw new RangeError('Invalid date')\n return date\n}\n\nconst formatDate = (value: DateInput, format: DateFormat = 'short', locale = 'en-GB'): string =>\n new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: format === 'long' ? 'long' : 'short',\n year: 'numeric',\n }).format(toValidDate(value))\n\nconst formatTime = (\n value: DateInput,\n locale = 'en-US',\n options: Intl.DateTimeFormatOptions = {}\n): string =>\n new Intl.DateTimeFormat(locale, {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n ...options,\n }).format(toValidDate(value))\n\nconst formatDateTime = (\n value: DateInput,\n locale = 'en-GB',\n options: Intl.DateTimeFormatOptions = {}\n): string =>\n new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'short',\n year: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n ...options,\n }).format(toValidDate(value))\n\nconst getRelativeTime = (value: DateInput, relativeTo: DateInput = Date.now(), locale = 'en'): string => {\n const elapsedSeconds = Math.round((toValidDate(value).getTime() - toValidDate(relativeTo).getTime()) / 1000)\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n const units: Array<[Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 31_536_000],\n ['month', 2_592_000],\n ['week', 604_800],\n ['day', 86_400],\n ['hour', 3_600],\n ['minute', 60],\n ]\n const unit = units.find(([, seconds]) => Math.abs(elapsedSeconds) >= seconds)\n return unit ? formatter.format(Math.round(elapsedSeconds / unit[1]), unit[0]) : 'just now'\n}\n\nconst currencyFormatter = formatCurrency\n// Kept for consumers already using the common misspelling.\nconst currencyFormmater = formatCurrency\n\nexport {\n currencyFormmater,\n currencyFormatter,\n formatCurrency,\n formatDate,\n formatDateTime,\n formatSlugToString,\n formatTime,\n getRelativeTime,\n getTagColor,\n replacePlaceholder,\n titleCase,\n}\n"],"names":["titleCase","value","trim","replace","toLocaleLowerCase","letter","toLocaleUpperCase","formatCurrency","amount","currency","locale","options","Intl","NumberFormat","minimumFractionDigits","maximumFractionDigits","currencyDisplay","style","toUpperCase","format","toValidDate","date","Date","Number","isNaN","getTime","RangeError","currencyFormatter","currencyFormmater","DateTimeFormat","day","month","year","hour","minute","second","hour12","relativeTo","now","elapsedSeconds","Math","round","formatter","RelativeTimeFormat","numeric","unit","find","seconds","abs","active","inactive","template","replacements","match","index"],"mappings":"0EAQMA,UAAaC,GACjBA,EACGC,OACAC,QAAQ,SAAU,KAClBA,QAAQ,OAAQ,KAChBC,oBACAD,QAAQ,YAAcE,GAAWA,EAAOC,qBAOvCC,eAAiB,CACrBC,EACAC,EAAW,MACXC,EAAS,QACTC,EAAgE,KAEhE,IAAIC,KAAKC,aAAaH,+BACpBI,sBAAuB,EACvBC,sBAAuB,EACvBC,gBAAiB,gBACdL,IACHM,MAAO,WACPR,SAAUA,EAASS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C,SAAU,qCAae,CAACC,KAAqBC,IAC/CD,EAAShD,QAAQ,WAAY,CAACkD,EAAOC,WAAkB,iBAAAF,EAAa7B,OAAO+B,mBAAWD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savantlink/sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "A package that contains reusable components and services for the SavantLink design system and architecture.",
|
|
5
5
|
"homepage": "https://github.com/savantlink/savantlink-sdk",
|
|
6
6
|
"repository": {
|