UNPKG

tempe

Version:

Featherlight (< 2kB) helper for simple javascript date formatting without all of those superpowers

3 lines (2 loc) 1.89 kB
"use strict";function e(t,r){return(e=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(t,r)}function t(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function r(n,u,o){return(r=t()?Reflect.construct:function(t,r,n){var u=[null];u.push.apply(u,r);var o=new(Function.bind.apply(t,u));return n&&e(o,n.prototype),o}).apply(null,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var n=["hh","DD","mm","ss","HH"],u={YYYY:{year:"numeric"},YYY:{year:"numeric"},YY:{year:"2-digit"},MMMM:{month:"long"},MMM:{month:"short"},MM:{month:"2-digit"},M:{month:"numeric"},DD:{day:"2-digit"},D:{day:"numeric"},dd:{weekday:"long"},d:{weekday:"short"},hh:{hour:"numeric",hour12:!1},h:{hour:"numeric",hour12:!1},HH:{hour:"numeric",hour12:!0},H:{hour:"numeric",hour12:!0},mm:{minute:"numeric"},m:{minute:"numeric"},ss:{second:"numeric"},s:{second:"numeric"}},o=function(){function e(e){return this.date=e,this}var t=e.prototype;return t.format=function(e,t,r){var n=t||"en",u=r?n+"-u-ca-"+r:n,o=function(e){return e.match(/\bY{2,4}\b|\bM{1,4}\b|\bD{1,2}\b|\bd{1,2}\b|\bh{1,2}\b|\bH{1,2}\b|\bm{1,2}\b|\bs{1,2}\b/g)||[]}(e),c=this.mapAvailableStringFormatToValue(o,u);return Object.keys(c).reduce((function(e,t){var r=new RegExp("\\b"+t+"\\b","g");return e.replace(r,c[t])}),e)},t.mapAvailableStringFormatToValue=function(e,t){var r=this;return e.reduce((function(e,o){return e[o]=function(e,t,r){var o=e.toLocaleString(r,u[t]);return n.includes(t)?o.padStart(2,"0"):o}(r.date,o,t),e}),{})},e}();exports.default=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var u=t?r(Date,t):new Date;return new o(u)}; //# sourceMappingURL=tempe.cjs.production.min.js.map