@savantlink/sdk 2.2.3 → 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/collection.d.ts +1 -1
- package/dist/services/collection.js +1 -1
- package/dist/services/collection.js.map +1 -1
- package/dist/services/format.js +1 -1
- package/dist/services/format.js.map +1 -1
- package/dist/services/query.d.ts +1 -1
- package/dist/services/query.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./format.js");exports.formatArrayToOptions=r=>r.map(r=>({label:e.titleCase(r.name),value:r.slug})),exports.sortData=(e,r)=>{if(!r)return[...e];const t="asc"===r.direction?1:-1;return[...e].sort((e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./format.js");exports.formatArrayToOptions=r=>r.map(r=>({label:e.titleCase(r.name),value:r.slug})),exports.sortData=(e,r)=>{if(!r)return[...e];const t="asc"===r.direction?1:-1;return[...e].sort((e,o)=>{const n=e[String(r.key)],a=o[String(r.key)];return"number"==typeof n&&"number"==typeof a?(n-a)*t:String(null!=n?n:"").localeCompare(String(null!=a?a:""))*t})};
|
|
2
2
|
//# sourceMappingURL=collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","sources":["../../src/services/collection.ts"],"sourcesContent":["import { titleCase } from './format'\n\ntype SortDirection = 'asc' | 'desc'\ninterface SortConfig<T> {\n key: keyof T\n direction: SortDirection\n}\n\nconst sortData = <T>(data: readonly T[], config?: SortConfig<T> | null): T[] => {\n if (!config) return [...data]\n const direction = config.direction === 'asc' ? 1 : -1\n return [...data].sort((left, right) => {\n const leftValue = left[config.key]\n const rightValue = right[config.key]\n if (leftValue
|
|
1
|
+
{"version":3,"file":"collection.js","sources":["../../src/services/collection.ts"],"sourcesContent":["import { titleCase } from './format'\n\ntype SortDirection = 'asc' | 'desc'\ninterface SortConfig<T> {\n key: keyof T | string\n direction: SortDirection\n}\n\nconst sortData = <T>(data: readonly T[], config?: SortConfig<T> | null): T[] => {\n if (!config) return [...data]\n const direction = config.direction === 'asc' ? 1 : -1\n return [...data].sort((left, right) => {\n const leftValue = (left as Record<string, unknown>)[String(config.key)]\n const rightValue = (right as Record<string, unknown>)[String(config.key)]\n if (typeof leftValue === 'number' && typeof rightValue === 'number') {\n return (leftValue - rightValue) * direction\n }\n return String(leftValue ?? '').localeCompare(String(rightValue ?? '')) * direction\n })\n}\n\ninterface NamedOptionSource {\n name: string\n slug: string\n}\n\nconst formatArrayToOptions = <T extends NamedOptionSource>(items: readonly T[]) =>\n items.map((item) => ({ label: titleCase(item.name), value: item.slug }))\n\nexport { formatArrayToOptions, sortData }\nexport type { NamedOptionSource, SortConfig, SortDirection }\n"],"names":["items","map","item","label","titleCase","name","value","slug","data","config","direction","sort","left","right","leftValue","String","key","rightValue","localeCompare"],"mappings":"8HA0B2DA,GACzDA,EAAMC,IAAKC,KAAYC,MAAOC,YAAUF,EAAKG,MAAOC,MAAOJ,EAAKK,yBAnBjD,CAAIC,EAAoBC,KACvC,IAAKA,EAAQ,MAAO,IAAID,GACxB,MAAME,EAAiC,QAArBD,EAAOC,UAAsB,GAAK,EACpD,MAAO,IAAIF,GAAMG,KAAK,CAACC,EAAMC,KAC3B,MAAMC,EAAaF,EAAiCG,OAAON,EAAOO,MAC5DC,EAAcJ,EAAkCE,OAAON,EAAOO,MACpE,MAAyB,iBAAdF,GAAgD,iBAAfG,GAClCH,EAAYG,GAAcP,EAE7BK,OAAOD,QAAAA,EAAa,IAAII,cAAcH,OAAOE,QAAAA,EAAc,KAAOP"}
|
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:
|
|
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:
|
|
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,iBAClBC,OAAOX,GAENY,YAAenB,IACnB,MAAMoB,EAAOpB,aAAiBqB,KAAOrB,EAAQ,IAAIqB,KAAKrB,GACtD,GAAIsB,OAAOC,MAAMH,EAAKI,WAAY,MAAM,IAAIC,WAAW,gBACvD,OAAOL,GAoDHM,EAAoBpB,eAEpBqB,EAAoBrB,gIAnDP,CAACN,EAAkBkB,EAAqB,QAAST,EAAS,UAC3E,IAAIE,KAAKiB,eAAenB,EAAQ,CAC9BoB,IAAK,UACLC,MAAkB,SAAXZ,EAAoB,OAAS,QACpCa,KAAM,YACLb,OAAOC,YAAYnB,2BAeD,CACrBA,EACAS,EAAS,QACTC,EAAsC,KAEtC,IAAIC,KAAKiB,eAAenB,iBACtBoB,IAAK,UACLC,MAAO,QACPC,KAAM,UACNC,KAAM,UACNC,OAAQ,WACLvB,IACFQ,OAAOC,YAAYnB,+BA1DIA,GAA0BD,UAAUC,EAAME,QAAQ,SAAU,yBAiCrE,CACjBF,EACAS,EAAS,QACTC,EAAsC,KAEtC,IAAIC,KAAKiB,eAAenB,iBACtBuB,KAAM,UACNC,OAAQ,UACRC,OAAQ,UACRC,QAAQ,GACLzB,IACFQ,OAAOC,YAAYnB,4BAgBA,CAACA,EAAkBoC,EAAwBf,KAAKgB,MAAO5B,EAAS,QACtF,MAAM6B,EAAiBC,KAAKC,OAAOrB,YAAYnB,GAAOwB,UAAYL,YAAYiB,GAAYZ,WAAa,KACjGiB,EAAY,IAAI9B,KAAK+B,mBAAmBjC,EAAQ,CAAEkC,QAAS,SAS3DC,EARsD,CAC1D,CAAC,OAAQ,SACT,CAAC,QAAS,QACV,CAAC,OAAQ,QACT,CAAC,MAAO,OACR,CAAC,OAAQ,MACT,CAAC,SAAU,KAEMC,KAAK,GAAIC,KAAaP,KAAKQ,IAAIT,IAAmBQ,GACrE,OAAOF,EAAOH,EAAUvB,OAAOqB,KAAKC,MAAMF,EAAiBM,EAAK,IAAKA,EAAK,IAAM,gCArF9D,CAClBI,OAAQ,UACRC,SAAU,qCAae,CAACC,KAAqBC,IAC/CD,EAAShD,QAAQ,WAAY,CAACkD,EAAOC,WAAkB,iBAAAF,EAAa7B,OAAO+B,mBAAWD"}
|
package/dist/services/query.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare type QueryValue = string | number | boolean | null | undefined;
|
|
2
2
|
declare type QueryParams = Record<string, QueryValue | QueryValue[]>;
|
|
3
|
-
declare const createQueryParams: (values:
|
|
3
|
+
declare const createQueryParams: <T extends object>(values: T) => URLSearchParams;
|
|
4
4
|
export { createQueryParams };
|
|
5
5
|
export type { QueryParams, QueryValue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sources":["../../src/services/query.ts"],"sourcesContent":["type QueryValue = string | number | boolean | null | undefined\ntype QueryParams = Record<string, QueryValue | QueryValue[]>\n\nconst createQueryParams = (values:
|
|
1
|
+
{"version":3,"file":"query.js","sources":["../../src/services/query.ts"],"sourcesContent":["type QueryValue = string | number | boolean | null | undefined\ntype QueryParams = Record<string, QueryValue | QueryValue[]>\n\nconst createQueryParams = <T extends object>(values: T): URLSearchParams => {\n const params = new URLSearchParams()\n Object.entries(values).forEach(([key, rawValue]: [string, unknown]) => {\n const entries = Array.isArray(rawValue) ? rawValue : [rawValue]\n entries.forEach((value) => {\n if (value !== undefined && value !== null && value !== '') params.append(key, String(value))\n })\n })\n return params\n}\n\nexport { createQueryParams }\nexport type { QueryParams, QueryValue }\n"],"names":["values","params","URLSearchParams","Object","entries","forEach","key","rawValue","Array","isArray","value","append","String"],"mappings":"8FAG6CA,IAC3C,MAAMC,EAAS,IAAIC,gBAOnB,OANAC,OAAOC,QAAQJ,GAAQK,QAAQ,EAAEC,EAAKC,OACpBC,MAAMC,QAAQF,GAAYA,EAAW,CAACA,IAC9CF,QAASK,IACXA,SAAmD,KAAVA,GAAcT,EAAOU,OAAOL,EAAKM,OAAOF,QAGlFT"}
|
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": {
|