Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.fdate=t()}(this,function(){"use strict";const n=(n,t=2)=>`${n}`.padStart(t,"0"),t={month(n){return n.getMonth()+1},M(){return this.month},MM(){return n(this.month)},quarter(n){return Math.floor(n.getMonth()/3)},Q(){return this.quarter},day(n){return n.getDate()},D(){return this.day},DD(){return n(this.day)},dayOfWeek(n){return n.getDay()},d(){return this.dayOfWeek},year(n){return n.getFullYear()},YY(){return this.year%100},YYYY(){return this.year},AM_PM(){return this.hour<12?"AM":"PM"},A(){return this.AM_PM},hour(n){return n.getHours()},H(){return this.hour},HH(){return n(this.hour)},h(){return this.hour%12+1},hh(){return n(this.h)},k(){return this.hour+1},kk(){return n(this.k)},minute(n){return n.getMinutes()},m(){return this.minute},mm(){return n(this.minute)},second(n){return n.getSeconds()},s(){return this.second},ss(){return n(this.second)},milliSecond(n){return n.getMilliseconds()},SSS(){return n(this.milliSecond,3)},Z(t){const e=t.getTimezoneOffset();return 0===e?"Z":[e>0?"-":"+",n(Math.floor(Math.abs(e)/60)),":",n(e%60)].join("")},ZZ(){const n=this.Z;return 1===n.length?n:n.replace(":","")}},e=new Set(Object.keys(t));var r=Object.create(t);const u=(n,...t)=>{const e=n.raw;const r=[];const u=r.length=e.length-1;for(let n=0;n<u;n++)r.push(e[n]),r.push(t[n]);r.push(e[u]);return r.join("")},o="undefined"!=typeof navigator&&/Chrom(?:e|ium)/.test(navigator.userAgent)||void 0===String.raw?u:String.raw,i=n=>{const t=new Proxy({},{get(u,o){return e.has(o)?r[o].call(t,n):void 0},has(n,t){return e.has(t)},ownKeys:()=>Object.getOwnPropertyNames(r)});return t};return(n,...t)=>e=>{const r=i(e);return o(n,...t.map(n=>"string"==typeof n?r[n]:n(r)))}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.fdate=n()}(this,function(){"use strict";const t=(t,n=2)=>`${t}`.padStart(n,"0");class n{constructor(t){this.date=t}get month(){return this.date.getMonth()+1}get M(){return this.month}get MM(){return t(this.month)}get quarter(){return Math.floor(this.date.getMonth()/3)}get Q(){return this.quarter}get day(){return this.date.getDate()}get D(){return this.day}get DD(){return t(this.day)}get dayOfWeek(){return this.date.getDay()}get d(){return this.dayOfWeek}get year(){return this.date.getFullYear()}get YY(){return this.year%100}get YYYY(){return this.year}get AM_PM(){return this.hour<12?"AM":"PM"}get A(){return this.AM_PM}get hour(){return this.date.getHours()}get H(){return this.hour}get HH(){return t(this.hour)}get h(){return this.hour%12+1}get hh(){return t(this.h)}get k(){return this.hour+1}get kk(){return t(this.k)}get minute(){return this.date.getMinutes()}get m(){return this.minute}get mm(){return t(this.minute)}get second(){return this.date.getSeconds()}get s(){return this.second}get ss(){return t(this.second)}get milliSecond(){return this.date.getMilliseconds()}get SSS(){return t(this.milliSecond,3)}get Z(){const n=this.date.getTimezoneOffset();return 0===n?"Z":[n>0?"-":"+",t(Math.floor(Math.abs(n)/60)),":",t(n%60)].join("")}get ZZ(){const t=this.Z;return 1===t.length?t:t.replace(":","")}}const e=(t,...n)=>{const e=t.raw;const r=[];const i=r.length=e.length-1;for(let t=0;t<i;t++)r.push(e[t]),r.push(n[t]);r.push(e[i]);return r.join("")},r="undefined"!=typeof navigator&&/Chrom(?:e|ium)/.test(navigator.userAgent)||void 0===String.raw?e:String.raw;return(t,...e)=>i=>{const u=new n(i);return r(t,...e.map(t=>"string"==typeof t?u[t]:t(u)))}}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -1,4 +0,7 @@ | ||
import { DateKeys, DateProxy, DateProxyFunction } from './types'; | ||
declare const fdate: (strArr: TemplateStringsArray, ...args: ("day" | "hour" | "minute" | "month" | "second" | "year" | "M" | "MM" | "quarter" | "Q" | "D" | "DD" | "dayOfWeek" | "d" | "YY" | "YYYY" | "AM_PM" | "A" | "H" | "HH" | "h" | "hh" | "k" | "kk" | "m" | "mm" | "s" | "ss" | "milliSecond" | "SSS" | "Z" | "ZZ" | DateProxyFunction)[]) => (date: Date) => string; | ||
import DateProxy from './DateProxy'; | ||
declare type DateProxyType = DateProxy; | ||
declare type DateKeys = keyof DateProxy; | ||
declare type DateProxyFunction = (date: DateProxy) => any; | ||
declare const fdate: (strArr: TemplateStringsArray, ...args: ("day" | "hour" | "minute" | "month" | "second" | "year" | "Z" | "M" | "MM" | "quarter" | "Q" | "D" | "DD" | "dayOfWeek" | "d" | "YY" | "YYYY" | "AM_PM" | "A" | "H" | "HH" | "h" | "hh" | "k" | "kk" | "m" | "mm" | "s" | "ss" | "milliSecond" | "SSS" | "ZZ" | DateProxyFunction)[]) => (date: Date) => string; | ||
export default fdate; | ||
export { DateKeys, DateProxy, DateProxyFunction }; | ||
export { DateKeys, DateProxyType as DateProxy, DateProxyFunction }; |
203
lib/index.js
'use strict'; | ||
const pad = (num, count = 2) => `${num}`.padStart(count, '0'); | ||
const proxyFunctions = { | ||
month(date) { | ||
return date.getMonth() + 1; | ||
}, | ||
M() { | ||
class DateProxy { | ||
constructor(date) { | ||
this.date = date; | ||
} | ||
/** Month. */ | ||
get month() { | ||
return this.date.getMonth() + 1; | ||
} | ||
/** Month. */ | ||
get M() { | ||
return this.month; | ||
}, | ||
MM() { | ||
} | ||
/*+ Padded month */ | ||
get MM() { | ||
return pad(this.month); | ||
}, | ||
quarter(date) { | ||
return Math.floor(date.getMonth() / 3); | ||
}, | ||
Q() { | ||
} | ||
/** Quarter */ | ||
get quarter() { | ||
return Math.floor(this.date.getMonth() / 3); | ||
} | ||
/** Quarter */ | ||
get Q() { | ||
return this.quarter; | ||
}, | ||
day(date) { | ||
return date.getDate(); | ||
}, | ||
D() { | ||
} | ||
/** Day of month */ | ||
get day() { | ||
return this.date.getDate(); | ||
} | ||
/** Day of month */ | ||
get D() { | ||
return this.day; | ||
}, | ||
DD() { | ||
} | ||
/** Padded day of month */ | ||
get DD() { | ||
return pad(this.day); | ||
}, | ||
dayOfWeek(date) { | ||
return date.getDay(); | ||
}, | ||
d() { | ||
} | ||
/** Day of week */ | ||
get dayOfWeek() { | ||
return this.date.getDay(); | ||
} | ||
/** Day of week */ | ||
get d() { | ||
return this.dayOfWeek; | ||
}, | ||
year(date) { | ||
return date.getFullYear(); | ||
}, | ||
YY() { | ||
} | ||
/** Year */ | ||
get year() { | ||
return this.date.getFullYear(); | ||
} | ||
/** Year (2 degits) */ | ||
get YY() { | ||
return this.year % 100; | ||
}, | ||
YYYY() { | ||
} | ||
/** Year (4 degits) */ | ||
get YYYY() { | ||
return this.year; | ||
}, | ||
AM_PM() { | ||
} | ||
/** AM / PM */ | ||
get AM_PM() { | ||
return this.hour < 12 ? 'AM' : 'PM'; | ||
}, | ||
A() { | ||
} | ||
/** AM / PM */ | ||
get A() { | ||
return this.AM_PM; | ||
}, | ||
hour(date) { | ||
return date.getHours(); | ||
}, | ||
H() { | ||
} | ||
/** Hour (0-23) */ | ||
get hour() { | ||
return this.date.getHours(); | ||
} | ||
/** Hour (0-23) */ | ||
get H() { | ||
return this.hour; | ||
}, | ||
HH() { | ||
} | ||
/** Padded Hour (0-23) */ | ||
get HH() { | ||
return pad(this.hour); | ||
}, | ||
h() { | ||
} | ||
/** Hour (1-12) */ | ||
get h() { | ||
return this.hour % 12 + 1; | ||
}, | ||
hh() { | ||
} | ||
/** Padded Hour (1-12) */ | ||
get hh() { | ||
return pad(this.h); | ||
}, | ||
k() { | ||
} | ||
/** Hour (1-24) */ | ||
get k() { | ||
return this.hour + 1; | ||
}, | ||
kk() { | ||
} | ||
/** Padded Hour (1-24) */ | ||
get kk() { | ||
return pad(this.k); | ||
}, | ||
minute(date) { | ||
return date.getMinutes(); | ||
}, | ||
m() { | ||
} | ||
/** Minute */ | ||
get minute() { | ||
return this.date.getMinutes(); | ||
} | ||
/** Minute */ | ||
get m() { | ||
return this.minute; | ||
}, | ||
mm() { | ||
} | ||
/** Padded Minute */ | ||
get mm() { | ||
return pad(this.minute); | ||
}, | ||
second(date) { | ||
return date.getSeconds(); | ||
}, | ||
s() { | ||
} | ||
/** Second */ | ||
get second() { | ||
return this.date.getSeconds(); | ||
} | ||
/** Second */ | ||
get s() { | ||
return this.second; | ||
}, | ||
ss() { | ||
} | ||
/** Padded Second */ | ||
get ss() { | ||
return pad(this.second); | ||
}, | ||
milliSecond(date) { | ||
return date.getMilliseconds(); | ||
}, | ||
SSS() { | ||
} | ||
/** Millisecond */ | ||
get milliSecond() { | ||
return this.date.getMilliseconds(); | ||
} | ||
/** Padded Millisecond (3 degits) */ | ||
get SSS() { | ||
return pad(this.milliSecond, 3); | ||
}, | ||
Z(date) { | ||
const timezone = date.getTimezoneOffset(); | ||
} | ||
/** Time Zone */ | ||
get Z() { | ||
const timezone = this.date.getTimezoneOffset(); | ||
if (timezone === 0) { | ||
@@ -101,10 +135,9 @@ return 'Z'; | ||
return [timezone > 0 ? '-' : '+', pad(Math.floor(Math.abs(timezone) / 60)), ':', pad(timezone % 60)].join(''); | ||
}, | ||
ZZ() { | ||
} | ||
/** Time Zone (no colon) */ | ||
get ZZ() { | ||
const Z = this.Z; | ||
return Z.length === 1 ? Z : Z.replace(':', ''); | ||
}, | ||
}; | ||
const proxyFunctionKeys = new Set(Object.keys(proxyFunctions)); | ||
var proxyFunctions$1 = Object.create(proxyFunctions); | ||
} | ||
} | ||
@@ -128,16 +161,4 @@ const isChrome = | ||
const wrap = (date) => { | ||
const proxy = new Proxy({}, { | ||
get(_target, key) { | ||
return proxyFunctionKeys.has(key) ? proxyFunctions$1[key].call(proxy, date) : undefined; | ||
}, | ||
has(_target, key) { | ||
return proxyFunctionKeys.has(key); | ||
}, | ||
ownKeys: () => Object.getOwnPropertyNames(proxyFunctions$1), | ||
}); | ||
return proxy; | ||
}; | ||
const fdate = (strArr, ...args) => (date) => { | ||
const proxy = wrap(date); | ||
const proxy = new DateProxy(date); | ||
return stringRaw(strArr, ...args.map((argv) => (typeof argv === 'string' ? proxy[argv] : argv(proxy)))); | ||
@@ -144,0 +165,0 @@ }; |
@@ -7,3 +7,3 @@ { | ||
"repository": "git@github.com:3846masa/fdate.git", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "lib/index", | ||
@@ -10,0 +10,0 @@ "files": [ |
124
README.md
@@ -10,5 +10,5 @@ # ⏰ fdate | ||
- ⏰ **f**ormatter of **Date** | ||
- 👼 light-weight (**~1kB** gzipped!) | ||
- 🦄 fast like other datetime libraries (under V8 engine) | ||
- 🆕 powered by `Proxy` and `Template literals` | ||
- 👼 light-weight as a **f**eather (**~1kB** gzipped!) | ||
- 🦄 very **f**aster than other datetime libraries (e.g. `moment`) | ||
- 🆕 powered by `Template literals` | ||
@@ -52,7 +52,7 @@ ## Table of Contents | ||
See [examples](./examples). | ||
See [examples](https://github.com/3846masa/fdate/tree/master/examples). | ||
## Benchmark | ||
See [benchmarks](./benchmarks) for more details. | ||
See [benchmarks](https://github.com/3846masa/fdate/tree/master/benchmarks) for more details. | ||
@@ -67,36 +67,36 @@ ### Basic usage | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| **fdate** | **555,012 ops/sec** | ±1.46% | (91 runs sampled) | | ||
| time-stamp | 387,908 ops/sec | ±1.45% | (85 runs sampled) | | ||
| moment | 371,611 ops/sec | ±1.73% | (84 runs sampled) | | ||
| date-fns | 363,545 ops/sec | ±2.03% | (85 runs sampled) | | ||
| dayjs | 267,914 ops/sec | ±1.49% | (82 runs sampled) | | ||
| fecha | 188,312 ops/sec | ±1.39% | (89 runs sampled) | | ||
| dateformat | 102,990 ops/sec | ±3.18% | (83 runs sampled) | | ||
| luxon | 2,300 ops/sec | ±1.58% | (85 runs sampled) | | ||
| **fdate** | **993,227 ops/sec** | ±0.97% | (87 runs sampled) | | ||
| time-stamp | 409,736 ops/sec | ±2.20% | (88 runs sampled) | | ||
| date-fns | 400,837 ops/sec | ±1.21% | (88 runs sampled) | | ||
| moment | 391,224 ops/sec | ±1.61% | (87 runs sampled) | | ||
| dayjs | 266,590 ops/sec | ±1.84% | (83 runs sampled) | | ||
| fecha | 193,034 ops/sec | ±2.46% | (81 runs sampled) | | ||
| dateformat | 114,571 ops/sec | ±1.58% | (86 runs sampled) | | ||
| luxon | 2,506 ops/sec | ±1.91% | (82 runs sampled) | | ||
#### Chrome 66.0.3359 (Windows 10 0.0.0) | ||
#### Chrome 66.0.3359 | ||
| | ops/sec | | | | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| time-stamp | 599,766 ops/sec | ±0.76% | (64 runs sampled) | | ||
| **fdate** | **518,779 ops/sec** | ±1.19% | (61 runs sampled) | | ||
| moment | 494,608 ops/sec | ±0.71% | (63 runs sampled) | | ||
| fecha | 487,890 ops/sec | ±1.19% | (64 runs sampled) | | ||
| date-fns | 474,755 ops/sec | ±1.12% | (62 runs sampled) | | ||
| dayjs | 271,477 ops/sec | ±1.35% | (60 runs sampled) | | ||
| dateformat | 141,005 ops/sec | ±1.15% | (61 runs sampled) | | ||
| luxon | 2,433 ops/sec | ±2.46% | (59 runs sampled) | | ||
| **fdate** | **948,727 ops/sec** | ±1.21% | (65 runs sampled) | | ||
| time-stamp | 683,091 ops/sec | ±1.04% | (65 runs sampled) | | ||
| fecha | 548,628 ops/sec | ±0.90% | (64 runs sampled) | | ||
| moment | 505,969 ops/sec | ±1.13% | (64 runs sampled) | | ||
| date-fns | 488,131 ops/sec | ±0.97% | (63 runs sampled) | | ||
| dayjs | 307,569 ops/sec | ±0.59% | (63 runs sampled) | | ||
| dateformat | 133,583 ops/sec | ±0.92% | (63 runs sampled) | | ||
| luxon | 2,808 ops/sec | ±3.24% | (19 runs sampled) | | ||
#### Firefox 59.0.0 (Windows 10 0.0.0) | ||
#### Firefox 59.0.0 | ||
| | ops/sec | | | | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| fecha | 838,066 ops/sec | ±3.73% | (45 runs sampled) | | ||
| time-stamp | 508,171 ops/sec | ±2.72% | (46 runs sampled) | | ||
| date-fns | 452,750 ops/sec | ±2.90% | (47 runs sampled) | | ||
| moment | 436,953 ops/sec | ±1.96% | (48 runs sampled) | | ||
| dayjs | 253,912 ops/sec | ±2.91% | (47 runs sampled) | | ||
| **fdate** | **190,718 ops/sec** | ±4.33% | (42 runs sampled) | | ||
| dateformat | 55,879 ops/sec | ±2.32% | (49 runs sampled) | | ||
| luxon | 2,609 ops/sec | ±1.34% | (48 runs sampled) | | ||
| | ops/sec | | | | ||
| :--------- | --------------------: | -----: | ----------------: | | ||
| **fdate** | **1,373,935 ops/sec** | ±2.58% | (48 runs sampled) | | ||
| fecha | 988,180 ops/sec | ±2.68% | (47 runs sampled) | | ||
| time-stamp | 601,037 ops/sec | ±2.84% | (45 runs sampled) | | ||
| moment | 479,960 ops/sec | ±2.57% | (47 runs sampled) | | ||
| date-fns | 478,713 ops/sec | ±3.20% | (47 runs sampled) | | ||
| dayjs | 269,816 ops/sec | ±3.10% | (47 runs sampled) | | ||
| dateformat | 62,120 ops/sec | ±2.12% | (50 runs sampled) | | ||
| luxon | 2,945 ops/sec | ±2.72% | (20 runs sampled) | | ||
@@ -111,43 +111,41 @@ ### Advanced usage | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| **fdate** | **487,123 ops/sec** | ±2.39% | (84 runs sampled) | | ||
| moment | 429,814 ops/sec | ±7.70% | (84 runs sampled) | | ||
| fecha | 180,108 ops/sec | ±1.90% | (86 runs sampled) | | ||
| date-fns | 120,219 ops/sec | ±1.34% | (86 runs sampled) | | ||
| dateformat | 104,204 ops/sec | ±1.29% | (85 runs sampled) | | ||
| luxon | 472 ops/sec | ±2.01% | (81 runs sampled) | | ||
| **fdate** | **842,085 ops/sec** | ±1.83% | (83 runs sampled) | | ||
| moment | 479,692 ops/sec | ±7.26% | (87 runs sampled) | | ||
| fecha | 204,389 ops/sec | ±2.47% | (84 runs sampled) | | ||
| date-fns | 129,711 ops/sec | ±1.67% | (86 runs sampled) | | ||
| dateformat | 111,659 ops/sec | ±1.92% | (82 runs sampled) | | ||
| luxon | 549 ops/sec | ±1.23% | (87 runs sampled) | | ||
#### Chrome 66.0.3359 (Windows 10 0.0.0) | ||
#### Chrome 66.0.3359 | ||
| | ops/sec | | | | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| **fdate** | **601,323 ops/sec** | ±0.93% | (62 runs sampled) | | ||
| moment | 565,947 ops/sec | ±1.14% | (60 runs sampled) | | ||
| fecha | 508,299 ops/sec | ±0.83% | (63 runs sampled) | | ||
| date-fns | 337,258 ops/sec | ±0.96% | (63 runs sampled) | | ||
| dateformat | 137,248 ops/sec | ±1.42% | (62 runs sampled) | | ||
| luxon | 489 ops/sec | ±1.24% | (60 runs sampled) | | ||
| | ops/sec | | | | ||
| :--------- | --------------------: | -----: | ----------------: | | ||
| **fdate** | **1,159,099 ops/sec** | ±0.73% | (65 runs sampled) | | ||
| moment | 619,972 ops/sec | ±0.74% | (62 runs sampled) | | ||
| fecha | 573,963 ops/sec | ±1.10% | (62 runs sampled) | | ||
| date-fns | 368,440 ops/sec | ±0.55% | (64 runs sampled) | | ||
| dateformat | 142,079 ops/sec | ±0.49% | (64 runs sampled) | | ||
| luxon | 562 ops/sec | ±1.11% | (60 runs sampled) | | ||
#### Firefox 59.0.0 (Windows 10 0.0.0) | ||
#### Firefox 59.0.0 | ||
| | ops/sec | | | | ||
| :--------- | ------------------: | -----: | ----------------: | | ||
| fecha | 754,953 ops/sec | ±3.44% | (44 runs sampled) | | ||
| dateformat | 56,548 ops/sec | ±2.56% | (45 runs sampled) | | ||
| moment | 397,211 ops/sec | ±3.44% | (46 runs sampled) | | ||
| date-fns | 268,545 ops/sec | ±5.27% | (43 runs sampled) | | ||
| **fdate** | **168,387 ops/sec** | ±5.00% | (42 runs sampled) | | ||
| luxon | 462 ops/sec | ±3.17% | (42 runs sampled) | | ||
| | ops/sec | | | | ||
| :--------- | --------------------: | -----: | ----------------: | | ||
| **fdate** | **1,358,185 ops/sec** | ±2.62% | (47 runs sampled) | | ||
| fecha | 965,889 ops/sec | ±3.61% | (46 runs sampled) | | ||
| date-fns | 342,457 ops/sec | ±2.67% | (48 runs sampled) | | ||
| moment | 449,780 ops/sec | ±2.26% | (48 runs sampled) | | ||
| dateformat | 60,055 ops/sec | ±1.60% | (49 runs sampled) | | ||
| luxon | 554 ops/sec | ±2.17% | (45 runs sampled) | | ||
### Bundle size | ||
### Bundle size (Webpack) | ||
See [benchmarks/scripts](./benchmarks/scripts). | ||
| | size | gzipped | | ||
| :--------- | ----------: | ------------: | | ||
| time-stamp | 1.12 KB | 658 bytes | | ||
| **fdate** | **2.05 KB** | **986 bytes** | | ||
| **fdate** | **2.14 KB** | **915 bytes** | | ||
| dateformat | 3.36 KB | 1.66 KB | | ||
| fecha | 5.13 KB | 2.06 KB | | ||
| dayjs | 6.30 KB | 2.26 KB | | ||
| date-fns | 8.93 KB | 3.02 KB | | ||
| dayjs | 6.30 KB | 2.26 KB | | ||
| luxon | 50.86 KB | 15.16 KB | | ||
@@ -162,2 +160,2 @@ | moment | 51.29 KB | 16.63 KB | | ||
[MIT (c) 3846masa](./LICENSE) | ||
[MIT (c) 3846masa](https://github.com/3846masa/fdate/blob/master/LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40692
412
16
157
1