Skip to content

Commit ac09f14

Browse files
4limirzaeiAli Mirzaei
andauthored
doc: ECMAScript 2015 (ES6) description added to plugins pages (#126)
* ECMAScript 2015 (ES6) description added to plugins pages for importing plugins. * lock file removed --------- Co-authored-by: Ali Mirzaei <[email protected]>
1 parent 23d526b commit ac09f14

35 files changed

+293
-201
lines changed

docs/durations/locale.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ You can get or set the locale of a duration using `locale`. The locale will affe
88
@>RelativeTime
99

1010
```javascript
11-
require('dayjs/locale/es')
11+
require("dayjs/locale/es");
12+
// import es from 'dayjs/plugin/es' // ES 2015
1213

1314
dayjs.duration(1, "minutes").locale("en").humanize(); // a minute
15+
1416
dayjs.duration(1, "minutes").locale("es").humanize(); // un minuto
17+
// dayjs.duration(1, "minutes").locale(es).humanize(); // ES 2015
1518
```

docs/plugin/advanced-format.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,36 @@
22
id: advanced-format
33
title: AdvancedFormat
44
---
5+
56
AdvancedFormat extends `dayjs().format` API to supply more format options.
67

78
```javascript
8-
var advancedFormat = require('dayjs/plugin/advancedFormat')
9-
dayjs.extend(advancedFormat)
9+
var advancedFormat = require("dayjs/plugin/advancedFormat");
10+
// import advancedFormat from 'dayjs/plugin/advancedFormat' // ES 2015
11+
12+
dayjs.extend(advancedFormat);
1013

11-
dayjs().format('Q Do k kk X x')
14+
dayjs().format("Q Do k kk X x");
1215
```
1316

1417
Note: some of the format options like `z` and `zzz` in the table below require additional plugins.
1518

1619
List of added formats:
1720

18-
| Format | Output | Description |
19-
| ------ | --------------------- | ----------------------------------------------------- |
20-
| `Q` | 1-4 | Quarter |
21-
| `Do` | 1st 2nd ... 31st | Day of Month with ordinal |
22-
| `k` | 1-24 | The hour, beginning at 1 |
23-
| `kk` | 01-24 | The hour, 2-digits, beginning at 1 |
24-
| `X` | 1360013296 | Unix Timestamp in second |
25-
| `x` | 1360013296123 | Unix Timestamp in millisecond |
26-
| `w` | 1 2 ... 52 53 | Week of year @>>WeekOfYear |
27-
| `ww` | 01 02 ... 52 53 | Week of year, 2-digits @>>WeekOfYear |
28-
| `W` | 1 2 ... 52 53 | ISO Week of year @>>IsoWeek |
29-
| `WW` | 01 02 ... 52 53 | ISO Week of year, 2-digits @>>IsoWeek |
30-
| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal @>>WeekOfYear |
31-
| `gggg` | 2017 | Week Year @>>WeekYear |
32-
| `GGGG` | 2017 | ISO Week Year @>>IsoWeek |
33-
| `z` | EST | Abbreviated named offset @>>Timezone |
34-
| `zzz` | Eastern Standard Time | Unabbreviated named offset @>>Timezone |
21+
| Format | Output | Description |
22+
| ------ | --------------------- | --------------------------------------- |
23+
| `Q` | 1-4 | Quarter |
24+
| `Do` | 1st 2nd ... 31st | Day of Month with ordinal |
25+
| `k` | 1-24 | The hour, beginning at 1 |
26+
| `kk` | 01-24 | The hour, 2-digits, beginning at 1 |
27+
| `X` | 1360013296 | Unix Timestamp in second |
28+
| `x` | 1360013296123 | Unix Timestamp in millisecond |
29+
| `w` | 1 2 ... 52 53 | Week of year @>>WeekOfYear |
30+
| `ww` | 01 02 ... 52 53 | Week of year, 2-digits @>>WeekOfYear |
31+
| `W` | 1 2 ... 52 53 | ISO Week of year @>>IsoWeek |
32+
| `WW` | 01 02 ... 52 53 | ISO Week of year, 2-digits @>>IsoWeek |
33+
| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal @>>WeekOfYear |
34+
| `gggg` | 2017 | Week Year @>>WeekYear |
35+
| `GGGG` | 2017 | ISO Week Year @>>IsoWeek |
36+
| `z` | EST | Abbreviated named offset @>>Timezone |
37+
| `zzz` | Eastern Standard Time | Unabbreviated named offset @>>Timezone |

docs/plugin/array-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ArraySupport extends `dayjs()`, `dayjs.utc` APIs to support array argument.
77

88
```javascript
99
var arraySupport = require("dayjs/plugin/arraySupport");
10+
// import arraySupport from 'dayjs/plugin/arraySupport' // ES 2015
11+
1012
dayjs.extend(arraySupport);
1113

1214
dayjs([2010, 1, 14, 15, 25, 50, 125]);

docs/plugin/bad-mutable.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ title: BadMutable
55

66
Day.js is designed to be immutable, however, in order to make it fully compatible with moment.js in some legacy projects we introduced a plugin 🚨 BadMutable 🚨 to make Day.js mutable.
77

8-
> This is __NOT__ good and __NOT__ recommended for most projects.
8+
> This is **NOT** good and **NOT** recommended for most projects.
99
1010
With this plugin enabled, all setters will update the instance itself.
1111

1212
```javascript
13-
var badMutable = require('dayjs/plugin/badMutable')
14-
dayjs.extend(badMutable)
13+
var badMutable = require("dayjs/plugin/badMutable");
14+
// import badMutable from 'dayjs/plugin/badMutable' // ES 2015
15+
16+
dayjs.extend(badMutable);
1517
// with 🚨 BadMutable 🚨 plugin
16-
const today = dayjs()
17-
today.add(1, 'day')
18-
console.log(today) // update itself, value will be tomorrow
18+
const today = dayjs();
19+
today.add(1, "day");
20+
console.log(today); // update itself, value will be tomorrow
1921
```

docs/plugin/bigint-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ BigIntSupport extends `dayjs()`, `dayjs.unix` APIs to support [BigInt](https://d
77

88
```javascript
99
var bigIntSupport = require("dayjs/plugin/bigIntSupport");
10+
// import bigIntSupport from 'dayjs/plugin/bigIntSupport' // ES 2015
11+
1012
dayjs.extend(bigIntSupport);
1113

1214
dayjs(BigInt(1666310421101));

docs/plugin/buddhist-era.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ Buddhist Era is a year numbering system that primarily used in mainland Southeas
1010
To calculate BE year manually, just add 543 to year. For example 26 May 1977 AD/CE should display as 26 May 2520 BE (1977 + 543).
1111

1212
```javascript
13-
var buddhistEra = require('dayjs/plugin/buddhistEra')
14-
dayjs.extend(buddhistEra)
13+
var buddhistEra = require("dayjs/plugin/buddhistEra");
14+
// import buddhistEra from 'dayjs/plugin/buddhistEra' // ES 2015
1515

16-
dayjs().format('BBBB BB')
16+
dayjs.extend(buddhistEra);
17+
18+
dayjs().format("BBBB BB");
1719
```
1820

1921
List of added formats:

docs/plugin/calendar.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
id: calendar
33
title: Calendar
44
---
5+
56
Calendar adds `.calendar` API to return a `string` to display calendar time
67

78
```javascript
8-
var calendar = require('dayjs/plugin/calendar')
9-
dayjs.extend(calendar)
9+
var calendar = require("dayjs/plugin/calendar");
10+
// import calendar from 'dayjs/plugin/calendar' // ES 2015
11+
12+
dayjs.extend(calendar);
1013

11-
dayjs().calendar(dayjs('2008-01-01'))
14+
dayjs().calendar(dayjs("2008-01-01"));
1215
dayjs().calendar(null, {
13-
sameDay: '[Today at] h:mm A', // The same day ( Today at 2:30 AM )
14-
nextDay: '[Tomorrow at] h:mm A', // The next day ( Tomorrow at 2:30 AM )
15-
nextWeek: 'dddd [at] h:mm A', // The next week ( Sunday at 2:30 AM )
16-
lastDay: '[Yesterday at] h:mm A', // The day before ( Yesterday at 2:30 AM )
17-
lastWeek: '[Last] dddd [at] h:mm A', // Last week ( Last Monday at 2:30 AM )
18-
sameElse: 'DD/MM/YYYY' // Everything else ( 17/10/2011 )
19-
})
16+
sameDay: "[Today at] h:mm A", // The same day ( Today at 2:30 AM )
17+
nextDay: "[Tomorrow at] h:mm A", // The next day ( Tomorrow at 2:30 AM )
18+
nextWeek: "dddd [at] h:mm A", // The next week ( Sunday at 2:30 AM )
19+
lastDay: "[Yesterday at] h:mm A", // The day before ( Yesterday at 2:30 AM )
20+
lastWeek: "[Last] dddd [at] h:mm A", // Last week ( Last Monday at 2:30 AM )
21+
sameElse: "DD/MM/YYYY", // Everything else ( 17/10/2011 )
22+
});
2023
```

docs/plugin/custom-parse-format.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
id: custom-parse-format
33
title: CustomParseFormat
44
---
5+
56
CustomParseFormat extends `dayjs()` constructor to support custom formats of input strings.
67

78
```javascript
8-
var customParseFormat = require('dayjs/plugin/customParseFormat')
9-
dayjs.extend(customParseFormat)
9+
var customParseFormat = require("dayjs/plugin/customParseFormat");
10+
// import customParseFormat from 'dayjs/plugin/customParseFormat' // ES 2015
11+
12+
dayjs.extend(customParseFormat);
1013

11-
dayjs('05/02/69 1:02:03 PM -05:00', 'MM/DD/YY H:mm:ss A Z')
14+
dayjs("05/02/69 1:02:03 PM -05:00", "MM/DD/YY H:mm:ss A Z");
1215
// Returns an instance containing '1969-05-02T18:02:03.000Z'
1316

14-
dayjs('2018 Enero 15', 'YYYY MMMM DD', 'es')
17+
dayjs("2018 Enero 15", "YYYY MMMM DD", "es");
1518
// Returns an instance containing '2018-01-15T00:00:00.000Z'
1619

17-
dayjs('1970-00-00', 'YYYY-MM-DD', true) // strict parsing
20+
dayjs("1970-00-00", "YYYY-MM-DD", true); // strict parsing
1821
```
1922

2023
[List of all available parsing tokens](../parse/string-format#list-of-all-available-parsing-tokens)

docs/plugin/day-of-year.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
id: day-of-year
33
title: DayOfYear
44
---
5+
56
DayOfYear adds `.dayOfYear()` API to returns a `number` indicating the `Dayjs`'s day of the year, or to set the day of the year.
67

78
```javascript
8-
var dayOfYear = require('dayjs/plugin/dayOfYear')
9-
dayjs.extend(dayOfYear)
9+
var dayOfYear = require("dayjs/plugin/dayOfYear");
10+
// import dayOfYear from 'dayjs/plugin/dayOfYear' // ES 2015
11+
12+
dayjs.extend(dayOfYear);
1013

11-
dayjs('2010-01-01').dayOfYear() // 1
12-
dayjs('2010-01-01').dayOfYear(365) // 2010-12-31
14+
dayjs("2010-01-01").dayOfYear(); // 1
15+
dayjs("2010-01-01").dayOfYear(365); // 2010-12-31
1316
```

docs/plugin/dev-helper.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ DevHelper adds some helper function to give you more hints and warnings while us
88
Note, you can set `process.env.NODE_ENV` to `production` to disable the DevHelper in your production environment. And if you have enabled a JavaScript minifier like UglifyJS, it can remove the plugin from your production bundle automatically to save some bytes.
99

1010
```js
11-
var devHelper = require('dayjs/plugin/devHelper')
11+
var devHelper = require("dayjs/plugin/devHelper");
12+
// import devHelper from 'dayjs/plugin/devHelper' // ES 2015
1213

13-
dayjs.extend(devHelper)
14+
dayjs.extend(devHelper);
1415
```
1516

1617
You can also load this plugin on demand yourself.

0 commit comments

Comments
 (0)