@carbon/utilities
Version:
Utilities and helpers to drive consistency across software products using the Carbon Design System
2 lines (1 loc) • 1.09 kB
JavaScript
;var m=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},w=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of M(t))!y.call(e,a)&&a!==o&&m(e,a,{get:()=>t[a],enumerable:!(n=u(t,a))||n.enumerable});return e};var g=e=>w(m({},"__esModule",{value:!0}),e);var d={};b(d,{format:()=>T});module.exports=g(d);function T(e,t){const o=new Intl.RelativeTimeFormat(t?.locale,{style:t?.style??"long"}),n=typeof e=="number"?new Date(e):e,a=Date.now(),c=Math.floor((a-n.getTime())/1e3),s=Math.floor(c/60),l=Math.floor(s/60),r=Math.floor(l/24),f=Math.floor(r/7),h=Math.floor(f/4),i=Math.floor(r/365);return Math.abs(c)<60?new Intl.RelativeTimeFormat(t?.locale,{numeric:"auto",style:t?.style??"long"}).format(0,"seconds"):Math.abs(s)<60?o.format(s*-1,"minutes"):Math.abs(l)<24?o.format(l*-1,"hours"):Math.abs(r)<7?o.format(r*-1,"days"):Math.abs(f)<4?o.format(f*-1,"weeks"):Math.abs(r)<365?o.format(h*-1,"months"):o.format(i*-1,"years")}