Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
Allow to disable options using "false" or "0"
Browse files Browse the repository at this point in the history
`data-add-suffix-value` and `data-include-seconds-value` now can be disabled using the values `false` or `0`.
  • Loading branch information
ocarreterom committed Feb 1, 2024
1 parent 778c1e7 commit 2460897
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ <h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:t
<time
data-controller="timeago"
data-timeago-datetime-value="2018-01-30T09:00"
data-timeago-add-suffix-value=""
data-timeago-include-seconds-value="true"
data-timeago-add-suffix-value="true"
></time
>.
</section>
Expand Down
4 changes: 2 additions & 2 deletions specs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('#load', () => {
<time
data-controller="timeago"
data-timeago-datetime-value="${lastMonth.toISOString()}"
data-timeago-add-suffix-value=""
data-timeago-add-suffix-value="true"
></time>.
`

Expand All @@ -70,7 +70,7 @@ describe('#load', () => {
<time
data-controller="timeago"
data-timeago-datetime-value="${fewSecondsAgo.toISOString()}"
data-timeago-include-seconds-value=""
data-timeago-include-seconds-value="true"
></time>.
`

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class extends Controller {

hasRefreshIntervalValue: boolean
datetimeValue: string
hasAddSuffixValue: boolean
hasIncludeSecondsValue: boolean
addSuffixValue: boolean
includeSecondsValue: boolean
refreshIntervalValue: number

static values = {
Expand Down Expand Up @@ -39,8 +39,8 @@ export default class extends Controller {
const datetime: string = this.datetimeValue
const date: number = Date.parse(datetime)
const options: object = {
includeSeconds: this.hasIncludeSecondsValue,
addSuffix: this.hasAddSuffixValue,
includeSeconds: this.includeSecondsValue,
addSuffix: this.addSuffixValue,
locale: this.locale
}

Expand Down

0 comments on commit 2460897

Please sign in to comment.