Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
use esm import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Sep 19, 2019
1 parent aa0d018 commit 4106287
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions MIGRATION.md
@@ -1,4 +1,17 @@
# Migration Guide

## Migrating from v3 to v4
o-date is an esm module now, so if you are using commonjs you'll want to import it like this:

```js
let ODate = require("o-date").default // note the .default
```
esm users can import it as so:

```js
import ODate from "o-date"
```


## Migrating from v2 to v3
We removed the ability to use o-date on the server in v3, the npm package `@financial-times/ft-date-format` is the server version of o-date, it is a drop-in replacement for o-date's server use.
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -34,9 +34,15 @@ document.addEventListener('DOMContentLoaded', function() {
});
```

You can also run `require('o-date').init()` once the DOM has loaded if you don't want to initialise other modules at the same time.
You can also import `o-date` as a module.

Run `require('o-date').init(el)` on any elements containing dates that are added to the page after DOM load, and if you keep a reference to the returned object you can clean them up with `oDateItem.destroy()` to stop processing.
```
import ODate from 'o-date'
```

You can run `ODate.init()` once the DOM has loaded if you don't want to initialise other modules at the same time.

Run `ODate.init(el)` on any elements containing dates that are added to the page after DOM load, and if you keep a reference to the returned object you can clean them up with `oDateItem.destroy()` to stop processing.

#### o-date#format(date, tpl)

Expand Down
6 changes: 2 additions & 4 deletions main.js
@@ -1,9 +1,9 @@
const ftDateFormat = require('ft-date-format');
import ftDateFormat from 'ft-date-format';

const updateEventName = 'oDate.update';
let interval;

function ODate(rootEl) {
export default function ODate(rootEl) {
if (!rootEl) {
rootEl = document.body;
} else if (!(rootEl instanceof HTMLElement)) {
Expand Down Expand Up @@ -145,5 +145,3 @@ const constructAll = function() {
if (typeof window !== 'undefined') {
document.addEventListener('o.DOMContentLoaded', constructAll);
}

module.exports = ODate;

0 comments on commit 4106287

Please sign in to comment.