@globalbrain/sefirot 2.7.2 → 2.7.3
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.
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// This file is copied from the source to avoid plugin resolution problem.
|
|
2
|
+
|
|
3
|
+
export const SECONDS_A_MINUTE = 60
|
|
4
|
+
export const SECONDS_A_HOUR = SECONDS_A_MINUTE * 60
|
|
5
|
+
export const SECONDS_A_DAY = SECONDS_A_HOUR * 24
|
|
6
|
+
export const SECONDS_A_WEEK = SECONDS_A_DAY * 7
|
|
7
|
+
|
|
8
|
+
export const MILLISECONDS_A_SECOND = 1e3
|
|
9
|
+
export const MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND
|
|
10
|
+
export const MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND
|
|
11
|
+
export const MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND
|
|
12
|
+
export const MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND
|
|
13
|
+
|
|
14
|
+
// English locales
|
|
15
|
+
export const MS = 'millisecond'
|
|
16
|
+
export const S = 'second'
|
|
17
|
+
export const MIN = 'minute'
|
|
18
|
+
export const H = 'hour'
|
|
19
|
+
export const D = 'day'
|
|
20
|
+
export const W = 'week'
|
|
21
|
+
export const M = 'month'
|
|
22
|
+
export const Q = 'quarter'
|
|
23
|
+
export const Y = 'year'
|
|
24
|
+
export const DATE = 'date'
|
|
25
|
+
|
|
26
|
+
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
|
|
27
|
+
|
|
28
|
+
export const INVALID_DATE_STRING = 'Invalid Date'
|
|
29
|
+
|
|
30
|
+
// Regex
|
|
31
|
+
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
|
|
32
|
+
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import dayjs, { ConfigType, Dayjs } from 'dayjs'
|
|
2
|
+
import { relativeTime } from './plugins/RelativeTime'
|
|
3
|
+
|
|
4
|
+
export type Day = Dayjs
|
|
5
|
+
export type Input = ConfigType
|
|
6
|
+
|
|
7
|
+
dayjs.extend(relativeTime)
|
|
8
|
+
|
|
9
|
+
export function day(input?: Input): Dayjs {
|
|
10
|
+
return dayjs(input)
|
|
11
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// This file is copied from the source to avoid plugin resolution problem.
|
|
2
|
+
|
|
3
|
+
import { PluginFunc } from 'dayjs'
|
|
4
|
+
import * as C from '../Constant'
|
|
5
|
+
|
|
6
|
+
declare module 'dayjs' {
|
|
7
|
+
interface Dayjs {
|
|
8
|
+
fromNow(withoutSuffix?: boolean): string
|
|
9
|
+
from(compared: ConfigType, withoutSuffix?: boolean): string
|
|
10
|
+
toNow(withoutSuffix?: boolean): string
|
|
11
|
+
to(compared: ConfigType, withoutSuffix?: boolean): string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RelativeTimeOptions {
|
|
16
|
+
rounding?: (num: number) => number
|
|
17
|
+
thresholds?: RelativeTimeThreshold[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RelativeTimeThreshold {
|
|
21
|
+
l: string
|
|
22
|
+
r?: number
|
|
23
|
+
d?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const relativeTime: PluginFunc<RelativeTimeOptions> = (o, c, d) => {
|
|
27
|
+
o = o || {}
|
|
28
|
+
|
|
29
|
+
const proto = c.prototype
|
|
30
|
+
|
|
31
|
+
const relObj = {
|
|
32
|
+
future: 'in %s',
|
|
33
|
+
past: '%s ago',
|
|
34
|
+
s: 'a few seconds',
|
|
35
|
+
m: 'a minute',
|
|
36
|
+
mm: '%d minutes',
|
|
37
|
+
h: 'an hour',
|
|
38
|
+
hh: '%d hours',
|
|
39
|
+
d: 'a day',
|
|
40
|
+
dd: '%d days',
|
|
41
|
+
M: 'a month',
|
|
42
|
+
MM: '%d months',
|
|
43
|
+
y: 'a year',
|
|
44
|
+
yy: '%d years'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
;(d as any).en.relativeTime = relObj
|
|
48
|
+
|
|
49
|
+
;(proto as any).fromToBase = (input: any, withoutSuffix: any, instance: any, isFrom: any, postFormat: any) => {
|
|
50
|
+
const loc = instance.$locale().relativeTime || relObj
|
|
51
|
+
|
|
52
|
+
const T = o.thresholds || [
|
|
53
|
+
{ l: 's', r: 44, d: C.S },
|
|
54
|
+
{ l: 'm', r: 89 },
|
|
55
|
+
{ l: 'mm', r: 44, d: C.MIN },
|
|
56
|
+
{ l: 'h', r: 89 },
|
|
57
|
+
{ l: 'hh', r: 21, d: C.H },
|
|
58
|
+
{ l: 'd', r: 35 },
|
|
59
|
+
{ l: 'dd', r: 25, d: C.D },
|
|
60
|
+
{ l: 'M', r: 45 },
|
|
61
|
+
{ l: 'MM', r: 10, d: C.M },
|
|
62
|
+
{ l: 'y', r: 17 },
|
|
63
|
+
{ l: 'yy', d: C.Y }
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
const Tl = T.length
|
|
67
|
+
|
|
68
|
+
let result
|
|
69
|
+
let out
|
|
70
|
+
let isFuture
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < Tl; i += 1) {
|
|
73
|
+
let t = T[i]
|
|
74
|
+
if (t.d) {
|
|
75
|
+
result = isFrom
|
|
76
|
+
? d(input).diff(instance, (t as any).d, true)
|
|
77
|
+
: instance.diff(input, t.d, true)
|
|
78
|
+
}
|
|
79
|
+
let abs = (o.rounding || Math.round)(Math.abs(result))
|
|
80
|
+
isFuture = result > 0
|
|
81
|
+
if (abs <= (t as any).r || !t.r) {
|
|
82
|
+
if (abs <= 1 && i > 0) { t = T[i - 1] } // 1 minutes -> a minute, 0 seconds -> 0 second
|
|
83
|
+
const format = loc[t.l]
|
|
84
|
+
if (postFormat) {
|
|
85
|
+
abs = postFormat(`${abs}`)
|
|
86
|
+
}
|
|
87
|
+
if (typeof format === 'string') {
|
|
88
|
+
out = (format as any).replace('%d', abs)
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
out = format(abs, withoutSuffix, t.l, isFuture)
|
|
92
|
+
}
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (withoutSuffix) { return out }
|
|
97
|
+
const pastOrFuture = isFuture ? loc.future : loc.past
|
|
98
|
+
if (typeof pastOrFuture === 'function') {
|
|
99
|
+
return pastOrFuture(out)
|
|
100
|
+
}
|
|
101
|
+
return pastOrFuture.replace('%s', out)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function fromTo(input: any, withoutSuffix: any, instance: any, isFrom?: any) {
|
|
105
|
+
return (proto as any).fromToBase(input, withoutSuffix, instance, isFrom)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
proto.to = function (input, withoutSuffix) {
|
|
109
|
+
return fromTo(input, withoutSuffix, this, true)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
proto.from = function (input, withoutSuffix) {
|
|
113
|
+
return fromTo(input, withoutSuffix, this)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const makeNow = (thisDay: any) => (thisDay.$u ? (d as any).utc() : d())
|
|
117
|
+
|
|
118
|
+
proto.toNow = function (withoutSuffix?: boolean) {
|
|
119
|
+
return this.to(makeNow(this), withoutSuffix)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
proto.fromNow = function (withoutSuffix) {
|
|
123
|
+
return this.from(makeNow(this), withoutSuffix)
|
|
124
|
+
}
|
|
125
|
+
}
|
package/package.json
CHANGED
package/lib/support/Day.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import dayjs, { ConfigType, Dayjs } from 'dayjs/esm'
|
|
2
|
-
import RelativeTime from 'dayjs/esm/plugin/relativeTime'
|
|
3
|
-
|
|
4
|
-
export type Day = Dayjs
|
|
5
|
-
export type Input = ConfigType
|
|
6
|
-
|
|
7
|
-
dayjs.extend(RelativeTime)
|
|
8
|
-
|
|
9
|
-
export function day(input?: Input): Dayjs {
|
|
10
|
-
return dayjs(input)
|
|
11
|
-
}
|