Skip to content

Commit

Permalink
fix: Move toObject, toArray API to separate plugin from core
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Mar 7, 2019
1 parent 8d63d88 commit 40a3431
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 38 deletions.
24 changes: 0 additions & 24 deletions src/index.js
Expand Up @@ -360,18 +360,6 @@ class Dayjs {
return new Date(this.$d)
}

toArray() {
return [
this.$y,
this.$M,
this.$D,
this.$H,
this.$m,
this.$s,
this.$ms
]
}

toJSON() {
return this.toISOString()
}
Expand All @@ -383,18 +371,6 @@ class Dayjs {
return this.$d.toISOString()
}

toObject() {
return {
years: this.$y,
months: this.$M,
date: this.$D,
hours: this.$H,
minutes: this.$m,
seconds: this.$s,
milliseconds: this.$ms
}
}

toString() {
return this.$d.toUTCString()
}
Expand Down
15 changes: 15 additions & 0 deletions src/plugin/toArray/index.js
@@ -0,0 +1,15 @@
export default (o, c) => {
const proto = c.prototype
proto.toArray = function () {
return [
this.$y,
this.$M,
this.$D,
this.$H,
this.$m,
this.$s,
this.$ms
]
}
}

15 changes: 15 additions & 0 deletions src/plugin/toObject/index.js
@@ -0,0 +1,15 @@
export default (o, c) => {
const proto = c.prototype
proto.toObject = function () {
return {
years: this.$y,
months: this.$M,
date: this.$D,
hours: this.$H,
minutes: this.$m,
seconds: this.$s,
milliseconds: this.$ms
}
}
}

14 changes: 0 additions & 14 deletions types/index.d.ts
Expand Up @@ -12,16 +12,6 @@ declare namespace dayjs {
type OpUnitTypeShort = 'w'
export type OpUnitType = UnitType | "week" | OpUnitTypeShort;

interface DayjsObject {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

class Dayjs {
constructor (config?: ConfigType)

Expand Down Expand Up @@ -67,14 +57,10 @@ declare namespace dayjs {

toDate(): Date

toArray(): number[]

toJSON(): string

toISOString(): string

toObject(): DayjsObject

toString(): string

utcOffset(): number
Expand Down
10 changes: 10 additions & 0 deletions types/plugin/toArray.d.ts
@@ -0,0 +1,10 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
interface Dayjs {
toArray(): number[]
}
}
20 changes: 20 additions & 0 deletions types/plugin/toObject.d.ts
@@ -0,0 +1,20 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

interface DayjsObject {
years: number
months: number
date: number
hours: number
minutes: number
seconds: number
milliseconds: number
}

declare module 'dayjs' {
interface Dayjs {
toObject(): DayjsObject
}
}

2 comments on commit 40a3431

@JosuaKrause
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you guys not heard of semantic versioning? why does a breaking change like this come up in a minor (aka bugfix) version change? npm/yarn happily upgrade those versions automatically

@iamkun
Copy link
Owner Author

@iamkun iamkun commented on 40a3431 Mar 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JosuaKrause Sorry. That's my fault.

This package is released by an auto semantic-release based on git commit message.

After v1.8.10 released, I found this should be a minor update instead of a patch. However, it's too late to unpublish this on npm due to their restriction.

Please sign in to comment.