@naturalcycles/time-lib
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -0,1 +1,8 @@ | ||
## [3.0.2](https://github.com/NaturalCycles/time-lib/compare/v3.0.1...v3.0.2) (2020-05-11) | ||
### Bug Fixes | ||
* release ([09fa7ce](https://github.com/NaturalCycles/time-lib/commit/09fa7ce26d82d11cb8d3264373e0a6bf3e62b973)) | ||
## [3.0.1](https://github.com/NaturalCycles/time-lib/compare/v3.0.0...v3.0.1) (2020-05-11) | ||
@@ -2,0 +9,0 @@ |
@@ -1,3 +0,3 @@ | ||
declare const dayjs: IDayjs; | ||
import type { IDayjs } from './types'; | ||
declare const dayjs: IDayjsFactory; | ||
import type { IDayjsFactory } from './types'; | ||
export { dayjs }; |
import { dayjs } from './dayjs.full'; | ||
import { DAYJS_TIME_HM, DAYJS_TIME_HMS } from './plugin/default'; | ||
import { IDayjs, IDayjsInstance, ILocale } from './types'; | ||
import { IDayjs, IDayjsFactory, IDayjsLocale } from './types'; | ||
export { dayjs, // should be imported from dayjs.full, cause it's an extended version | ||
IDayjs, IDayjsInstance, ILocale, DAYJS_TIME_HM, DAYJS_TIME_HMS, }; | ||
IDayjsFactory, IDayjs, IDayjsLocale, DAYJS_TIME_HM, DAYJS_TIME_HMS, }; |
@@ -1,2 +0,2 @@ | ||
export declare type ConfigType = string | number | Date | IDayjsInstance; | ||
export declare type ConfigType = string | number | Date | IDayjs; | ||
export declare type OptionType = { | ||
@@ -11,44 +11,44 @@ locale?: string; | ||
export declare type QUnitType = UnitType | 'quarter' | 'Q'; | ||
export declare type PluginFunc<T = unknown> = (option: T, c: IDayjs, d: IDayjs) => void; | ||
export interface IDayjs { | ||
(cfg?: ConfigType): IDayjsInstance; | ||
unix(t: number): IDayjsInstance; | ||
extend<T = unknown>(plugin: PluginFunc<T>, option?: T): IDayjs; | ||
locale(preset?: string | ILocale, object?: Partial<ILocale> | null, isLocal?: boolean): string; | ||
isDayjs(d: any): d is IDayjsInstance; | ||
utc(config?: ConfigType, format?: string): IDayjsInstance; | ||
max(dayjs: IDayjsInstance[]): IDayjsInstance; | ||
max(...dayjs: IDayjsInstance[]): IDayjsInstance; | ||
min(dayjs: IDayjsInstance[]): IDayjsInstance; | ||
min(...dayjs: IDayjsInstance[]): IDayjsInstance; | ||
export declare type PluginFunc<T = unknown> = (option: T, c: IDayjsFactory, d: IDayjsFactory) => void; | ||
export interface IDayjsFactory { | ||
(cfg?: ConfigType): IDayjs; | ||
unix(t: number): IDayjs; | ||
extend<T = unknown>(plugin: PluginFunc<T>, option?: T): IDayjsFactory; | ||
locale(preset?: string | IDayjsLocale, object?: Partial<IDayjsLocale> | null, isLocal?: boolean): string; | ||
isDayjs(d: any): d is IDayjs; | ||
utc(config?: ConfigType, format?: string): IDayjs; | ||
max(dayjs: IDayjs[]): IDayjs; | ||
max(...dayjs: IDayjs[]): IDayjs; | ||
min(dayjs: IDayjs[]): IDayjs; | ||
min(...dayjs: IDayjs[]): IDayjs; | ||
updateLocale(localeName: string, customConfig: object): any; | ||
Ls: { | ||
[localeName: string]: ILocale; | ||
[localeName: string]: IDayjsLocale; | ||
}; | ||
} | ||
export interface IDayjsInstance { | ||
clone(): IDayjsInstance; | ||
export interface IDayjs { | ||
clone(): IDayjs; | ||
isValid(): boolean; | ||
year(): number; | ||
year(value: number): IDayjsInstance; | ||
year(value: number): IDayjs; | ||
month(): number; | ||
month(value: number): IDayjsInstance; | ||
month(value: number): IDayjs; | ||
date(): number; | ||
date(value: number): IDayjsInstance; | ||
date(value: number): IDayjs; | ||
day(): number; | ||
day(value: number): IDayjsInstance; | ||
day(value: number): IDayjs; | ||
hour(): number; | ||
hour(value: number): IDayjsInstance; | ||
hour(value: number): IDayjs; | ||
minute(): number; | ||
minute(value: number): IDayjsInstance; | ||
minute(value: number): IDayjs; | ||
second(): number; | ||
second(value: number): IDayjsInstance; | ||
second(value: number): IDayjs; | ||
millisecond(): number; | ||
millisecond(value: number): IDayjsInstance; | ||
set(unit: UnitType, value: number): IDayjsInstance; | ||
millisecond(value: number): IDayjs; | ||
set(unit: UnitType, value: number): IDayjs; | ||
get(unit: UnitType): number; | ||
add(value: number, unit: OpUnitType): IDayjsInstance; | ||
subtract(value: number, unit: OpUnitType): IDayjsInstance; | ||
startOf(unit: OpUnitType): IDayjsInstance; | ||
endOf(unit: OpUnitType): IDayjsInstance; | ||
add(value: number, unit: OpUnitType): IDayjs; | ||
subtract(value: number, unit: OpUnitType): IDayjs; | ||
startOf(unit: OpUnitType): IDayjs; | ||
endOf(unit: OpUnitType): IDayjs; | ||
format(template?: string): string; | ||
@@ -62,3 +62,3 @@ diff(date: ConfigType, unit?: QUnitType | OpUnitType, float?: boolean): number; | ||
utcOffset(): number; | ||
utcOffset(offset: number): IDayjsInstance; | ||
utcOffset(offset: number): IDayjs; | ||
isBefore(date: ConfigType, unit?: OpUnitType): boolean; | ||
@@ -68,4 +68,4 @@ isSame(date: ConfigType, unit?: OpUnitType): boolean; | ||
locale(): string; | ||
locale(preset: string | ILocale, object?: Partial<ILocale>): IDayjsInstance; | ||
locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string; | ||
locale(preset: string | IDayjsLocale, object?: Partial<IDayjsLocale>): IDayjs; | ||
locale(preset?: string | IDayjsLocale, object?: Partial<IDayjsLocale>, isLocal?: boolean): string; | ||
/** | ||
@@ -97,3 +97,3 @@ * Returns ISO date, e.g `2018-06-21` | ||
*/ | ||
today(): IDayjsInstance; | ||
today(): IDayjs; | ||
/** | ||
@@ -118,4 +118,4 @@ * 1: Monday | ||
isBetween(a: ConfigType, b: ConfigType, c?: OpUnitType | null, d?: string): boolean; | ||
utc(): IDayjsInstance; | ||
local(): IDayjsInstance; | ||
utc(): IDayjs; | ||
local(): IDayjs; | ||
isUTC(): boolean; | ||
@@ -131,6 +131,6 @@ isSameOrAfter(date: ConfigType, unit?: OpUnitType): boolean; | ||
*/ | ||
$locale(): ILocale; | ||
localeData(): ILocale; | ||
$locale(): IDayjsLocale; | ||
localeData(): IDayjsLocale; | ||
} | ||
export interface ILocale { | ||
export interface IDayjsLocale { | ||
name: string; | ||
@@ -137,0 +137,0 @@ weekdays: string[]; |
@@ -41,3 +41,3 @@ { | ||
}, | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Date/time related API, based on Day.js", | ||
@@ -44,0 +44,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
const dayjs = require('dayjs') as IDayjs | ||
const dayjs = require('dayjs') as IDayjsFactory | ||
@@ -6,3 +6,3 @@ import { defaultPlugins } from './plugin/default' | ||
import { weekOfYearPlugin } from './plugin/weekOfYear' | ||
import type { IDayjs } from './types' | ||
import type { IDayjsFactory } from './types' | ||
@@ -9,0 +9,0 @@ dayjs.extend(require('dayjs/plugin/utc')) |
import { dayjs } from './dayjs.full' | ||
import { DAYJS_TIME_HM, DAYJS_TIME_HMS } from './plugin/default' | ||
import { IDayjs, IDayjsInstance, ILocale } from './types' | ||
import { IDayjs, IDayjsFactory, IDayjsLocale } from './types' | ||
export { | ||
dayjs, // should be imported from dayjs.full, cause it's an extended version | ||
IDayjsFactory, | ||
IDayjs, | ||
IDayjsInstance, | ||
ILocale, | ||
IDayjsLocale, | ||
DAYJS_TIME_HM, | ||
@@ -11,0 +11,0 @@ DAYJS_TIME_HMS, |
@@ -1,2 +0,2 @@ | ||
import type { IDayjsInstance, PluginFunc } from '../types' | ||
import type { IDayjs, PluginFunc } from '../types' | ||
@@ -15,15 +15,15 @@ // todo: fix the interface extension | ||
export const defaultPlugins: PluginFunc = (_opt, dayjsClass, _dayjsFactory) => { | ||
dayjsClass.prototype.toISODate = function (this: IDayjsInstance): string { | ||
dayjsClass.prototype.toISODate = function (this: IDayjs): string { | ||
return this.format(DAYJS_ISO_DATE) | ||
} | ||
dayjsClass.prototype.toPretty = function (this: IDayjsInstance, seconds = true): string { | ||
dayjsClass.prototype.toPretty = function (this: IDayjs, seconds = true): string { | ||
return this.format(seconds ? DAYJS_PRETTY_TIME : DAYJS_PRETTY_TIME_NO_SECONDS) | ||
} | ||
dayjsClass.prototype.toCompactTime = function (this: IDayjsInstance, seconds = false): string { | ||
dayjsClass.prototype.toCompactTime = function (this: IDayjs, seconds = false): string { | ||
return this.format(seconds ? DAYJS_COMPACT_TIME_SECONDS : DAYJS_COMPACT_TIME) | ||
} | ||
dayjsClass.prototype.toCompactDate = function (this: IDayjsInstance): string { | ||
dayjsClass.prototype.toCompactDate = function (this: IDayjs): string { | ||
return this.format(DAYJS_COMPACT_DATE) | ||
@@ -36,5 +36,5 @@ } | ||
dayjsClass.prototype.today = function (this: IDayjsInstance): IDayjsInstance { | ||
dayjsClass.prototype.today = function (this: IDayjs): IDayjs { | ||
return this.startOf('day') | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
import type { IDayjsInstance, PluginFunc } from '../types' | ||
import type { IDayjs, PluginFunc } from '../types' | ||
export const isoWeekdayPlugin: PluginFunc = (_opt, dayjsClass) => { | ||
dayjsClass.prototype.isoWeekday = function (this: IDayjsInstance, setWeekday?: number) { | ||
dayjsClass.prototype.isoWeekday = function (this: IDayjs, setWeekday?: number) { | ||
const { $W } = this as any | ||
@@ -6,0 +6,0 @@ const weekday = $W <= 0 ? $W + 7 : $W |
@@ -1,5 +0,5 @@ | ||
import type { IDayjsInstance, PluginFunc } from '../types' | ||
import type { IDayjs, PluginFunc } from '../types' | ||
export const weekOfYearPlugin: PluginFunc = (_opt, dayjsClass, dayjs) => { | ||
dayjsClass.prototype.week = function (this: IDayjsInstance) { | ||
dayjsClass.prototype.week = function (this: IDayjs) { | ||
const weekStart = this.$locale().weekStart || 0 | ||
@@ -6,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
export type ConfigType = string | number | Date | IDayjsInstance | ||
export type ConfigType = string | number | Date | IDayjs | ||
@@ -20,29 +20,33 @@ export type OptionType = { locale?: string; format?: string; utc?: boolean } | string | ||
export type PluginFunc<T = unknown> = (option: T, c: IDayjs, d: IDayjs) => void | ||
export type PluginFunc<T = unknown> = (option: T, c: IDayjsFactory, d: IDayjsFactory) => void | ||
export interface IDayjs { | ||
(cfg?: ConfigType): IDayjsInstance | ||
export interface IDayjsFactory { | ||
(cfg?: ConfigType): IDayjs | ||
unix(t: number): IDayjsInstance | ||
unix(t: number): IDayjs | ||
extend<T = unknown>(plugin: PluginFunc<T>, option?: T): IDayjs | ||
extend<T = unknown>(plugin: PluginFunc<T>, option?: T): IDayjsFactory | ||
locale(preset?: string | ILocale, object?: Partial<ILocale> | null, isLocal?: boolean): string | ||
locale( | ||
preset?: string | IDayjsLocale, | ||
object?: Partial<IDayjsLocale> | null, | ||
isLocal?: boolean, | ||
): string | ||
isDayjs(d: any): d is IDayjsInstance | ||
isDayjs(d: any): d is IDayjs | ||
// Plugins are copy-pasted there now: | ||
utc(config?: ConfigType, format?: string): IDayjsInstance | ||
utc(config?: ConfigType, format?: string): IDayjs | ||
max(dayjs: IDayjsInstance[]): IDayjsInstance | ||
max(...dayjs: IDayjsInstance[]): IDayjsInstance | ||
min(dayjs: IDayjsInstance[]): IDayjsInstance | ||
min(...dayjs: IDayjsInstance[]): IDayjsInstance | ||
max(dayjs: IDayjs[]): IDayjs | ||
max(...dayjs: IDayjs[]): IDayjs | ||
min(dayjs: IDayjs[]): IDayjs | ||
min(...dayjs: IDayjs[]): IDayjs | ||
updateLocale(localeName: string, customConfig: object): any | ||
Ls: { [localeName: string]: ILocale } | ||
Ls: { [localeName: string]: IDayjsLocale } | ||
} | ||
export interface IDayjsInstance { | ||
clone(): IDayjsInstance | ||
export interface IDayjs { | ||
clone(): IDayjs | ||
@@ -53,43 +57,43 @@ isValid(): boolean | ||
year(value: number): IDayjsInstance | ||
year(value: number): IDayjs | ||
month(): number | ||
month(value: number): IDayjsInstance | ||
month(value: number): IDayjs | ||
date(): number | ||
date(value: number): IDayjsInstance | ||
date(value: number): IDayjs | ||
day(): number | ||
day(value: number): IDayjsInstance | ||
day(value: number): IDayjs | ||
hour(): number | ||
hour(value: number): IDayjsInstance | ||
hour(value: number): IDayjs | ||
minute(): number | ||
minute(value: number): IDayjsInstance | ||
minute(value: number): IDayjs | ||
second(): number | ||
second(value: number): IDayjsInstance | ||
second(value: number): IDayjs | ||
millisecond(): number | ||
millisecond(value: number): IDayjsInstance | ||
millisecond(value: number): IDayjs | ||
set(unit: UnitType, value: number): IDayjsInstance | ||
set(unit: UnitType, value: number): IDayjs | ||
get(unit: UnitType): number | ||
add(value: number, unit: OpUnitType): IDayjsInstance | ||
add(value: number, unit: OpUnitType): IDayjs | ||
subtract(value: number, unit: OpUnitType): IDayjsInstance | ||
subtract(value: number, unit: OpUnitType): IDayjs | ||
startOf(unit: OpUnitType): IDayjsInstance | ||
startOf(unit: OpUnitType): IDayjs | ||
endOf(unit: OpUnitType): IDayjsInstance | ||
endOf(unit: OpUnitType): IDayjs | ||
@@ -117,3 +121,3 @@ format(template?: string): string | ||
utcOffset(): number | ||
utcOffset(offset: number): IDayjsInstance | ||
utcOffset(offset: number): IDayjs | ||
@@ -128,5 +132,5 @@ isBefore(date: ConfigType, unit?: OpUnitType): boolean | ||
locale(preset: string | ILocale, object?: Partial<ILocale>): IDayjsInstance | ||
locale(preset: string | IDayjsLocale, object?: Partial<IDayjsLocale>): IDayjs | ||
locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string | ||
locale(preset?: string | IDayjsLocale, object?: Partial<IDayjsLocale>, isLocal?: boolean): string | ||
@@ -165,3 +169,3 @@ // default plugin here | ||
*/ | ||
today(): IDayjsInstance | ||
today(): IDayjs | ||
@@ -197,4 +201,4 @@ // isoWeekDay plugin here | ||
utc(): IDayjsInstance | ||
local(): IDayjsInstance | ||
utc(): IDayjs | ||
local(): IDayjs | ||
isUTC(): boolean | ||
@@ -212,7 +216,7 @@ | ||
*/ | ||
$locale(): ILocale | ||
localeData(): ILocale | ||
$locale(): IDayjsLocale | ||
localeData(): IDayjsLocale | ||
} | ||
export interface ILocale { | ||
export interface IDayjsLocale { | ||
name: string | ||
@@ -219,0 +223,0 @@ weekdays: string[] |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
647
37806