Skip to content

Commit

Permalink
fix: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Apr 18, 2020
1 parent a7d56e0 commit 50cb1ce
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

A simple `date` field for the [Commodo](https://github.com/webiny/commodo) library.
A simple date field, used with the [Commodo `withFields`](https://github.com/webiny/commodo/tree/master/packages/fields) higher order function.

## Install
```
Expand All @@ -29,7 +29,8 @@ import { date } from "commodo-fields-date";
const Company = compose(
withFields({
name: string(),
createdOn: date(),
foundedOn: date(), // Use it to store a single date.
topMoments: date({ list: true }) // Or use it to store a list of dates.
// Other fields you might need...
}),
// Other higher order functions (HOFs) you might need...
Expand All @@ -39,13 +40,34 @@ const company = new Company();
company.name = "Acme Corporation";

// The date field can accept a Date object...
company.createdOn = new Date();
company.foundedOn = new Date();
company.topMoments = [new Date(), new Date()];

// ...or an ISO 8601 formatted date/time string.
company.createdOn = "2020-04-18T15:50:44.205Z";
company.foundedOn = "2020-04-18T15:50:44.205Z";
company.topMoments = [
"2020-04-18T15:50:44.205Z",
"2020-04-10T00:00:00.000Z",
new Date()
];

// The following will throw the WithFieldsError error.
company.createdOn = "2020-04-18";
company.foundedOn = "2020-04-18";
company.topMoments = ["2020-04-18", new Date()];
```

Note: alternatively, you could've also used the [`populate`](https://github.com/webiny/commodo/tree/master/packages/fields#populatedata-object-void) method to assign the data:

```javascript
const company = new Company();
company.populate = {
foundedOn: new Date(),
topMoments: [
"2020-04-18T15:50:44.205Z",
"2020-04-10T00:00:00.000Z",
new Date()
]
};
```

## Contributors
Expand Down

0 comments on commit 50cb1ce

Please sign in to comment.