-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
6,871 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.vscode | ||
.idea | ||
node_modules | ||
*.log | ||
.DS_Store | ||
coverage | ||
dist | ||
types | ||
.gen | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# chartjs-adapter-intl | ||
|
||
[![npm](https://img.shields.io/npm/v/chartjs-adapter-intl.svg?style=flat-square)](https://www.npmjs.com/package/chartjs-adapter-intl) | ||
[![npm](https://img.shields.io/npm/dm/chartjs-adapter-intl.svg?style=flat-square)](https://www.npmjs.com/package/chartjs-adapter-intl) | ||
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dankerow/chartjs-adapter-intl/test.yml?branch=master&style=flat-square)](https://github.com/dankerow/chartjs-adapter-intl/actions/workflows/test.yml) | ||
|
||
## Introduction | ||
|
||
`chartjs-adapter-intl` is a date adapter for [Chart.js](https://www.chartjs.org/) that uses the native `Intl.DateTimeFormat` API for date formatting and parsing. | ||
|
||
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **3.0.0** or later. | ||
|
||
**Note:** once loaded, this adapter overrides the default date-adapter provided in Chart.js (as a side effect). | ||
|
||
## Installation | ||
|
||
You can install this adapter via pnpm: | ||
|
||
```sh | ||
pnpm install chartjs-adapter-intl | ||
``` | ||
|
||
via npm: | ||
|
||
```sh | ||
npm add chartjs-adapter-intl | ||
``` | ||
|
||
via yarn: | ||
|
||
```sh | ||
yarn add chartjs-adapter-intl | ||
``` | ||
|
||
### CDN | ||
|
||
By default, `https://cdn.jsdelivr.net/npm/chartjs-adapter-intl` returns the latest (minified) version, however it's [highly recommended](https://www.jsdelivr.com/features) to always specify a version in order to avoid breaking changes. This can be achieved by appending `@{version}` to the URL: | ||
|
||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/chart.js@^3"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-intl"></script> | ||
``` | ||
|
||
Read more about jsDelivr versioning on their [website](http://www.jsdelivr.com/). | ||
|
||
## Usage | ||
|
||
To use this adapter, you need to import it into your project. The adapter will automatically register itself with Chart.js. | ||
|
||
```javascript | ||
import { Chart } from 'chart.js'; | ||
import 'chartjs-adapter-intl'; | ||
|
||
const config = { | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [ | ||
{ x: '2023-01-01T00:00:00Z', y: 10 }, | ||
{ x: '2023-01-02T00:00:00Z', y: 20 } | ||
] | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
x: { | ||
type: 'time', | ||
time: { | ||
unit: 'day' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const myChart = new Chart(document.querySelector('#myChart'), config); | ||
``` | ||
|
||
## Configuration | ||
|
||
This adapter supports the following configuration options: | ||
|
||
- `locale`: The locale to use for formatting dates. Defaults to `'en-US'`. | ||
|
||
```javascript | ||
const config = { | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [ | ||
{ x: '2023-01-01T00:00:00Z', y: 10 }, | ||
{ x: '2023-01-02T00:00:00Z', y: 20 } | ||
] | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
x: { | ||
type: 'time', | ||
adapters: { | ||
date: { | ||
locale: 'fr-FR' | ||
} | ||
}, | ||
time: { | ||
unit: 'day' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const myChart = new Chart(document.querySelector('#myChart'), config); | ||
``` | ||
|
||
## Development | ||
|
||
To build the project, run: | ||
|
||
```sh | ||
pnpm run build | ||
``` | ||
|
||
To run tests, use: | ||
|
||
```sh | ||
pnpm test | ||
``` | ||
|
||
## License | ||
|
||
`chartjs-adapter-intl` is available under the [MIT license](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
import { readFileSync } from 'node:fs' | ||
|
||
const { name, version, homepage, license } = JSON.parse(readFileSync('./package.json').toString()) | ||
|
||
const banner = `/*! | ||
* ${name} v${version} | ||
* ${homepage} | ||
* (c) ${new Date().getFullYear()} chartjs-adapter-intl Contributors | ||
* Released under the ${license} license | ||
*/` | ||
|
||
const globals = { 'chart.js': 'Chart' } | ||
const externals = ['chart.js'] | ||
|
||
export default defineBuildConfig([ | ||
{ | ||
entries: [ | ||
'./src/index' | ||
], | ||
|
||
rollup: { | ||
output: { | ||
dir: 'dist', | ||
entryFileNames: 'chartjs-adapter-intl.esm.js', | ||
format: 'esm', | ||
indent: false, | ||
globals | ||
} | ||
}, | ||
|
||
externals | ||
}, | ||
{ | ||
entries: [ | ||
'./src/index' | ||
], | ||
|
||
rollup: { | ||
output: { | ||
dir: 'dist', | ||
entryFileNames: 'chartjs-adapter-intl.umd.js', | ||
format: 'umd', | ||
indent: false, | ||
globals | ||
} | ||
}, | ||
|
||
externals | ||
}, | ||
{ | ||
entries: [ | ||
'./src/index' | ||
], | ||
|
||
rollup: { | ||
esbuild: { | ||
minify: true | ||
}, | ||
output: { | ||
dir: 'dist', | ||
entryFileNames: 'chartjs-adapter-intl.umd.min.js', | ||
format: 'umd', | ||
indent: false, | ||
banner, | ||
globals | ||
} | ||
}, | ||
|
||
externals | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import unjs from 'eslint-config-unjs' | ||
|
||
// https://github.com/unjs/eslint-config | ||
export default unjs({ | ||
ignores: [], | ||
rules: { | ||
'no-undef': 0, | ||
'unicorn/no-null': 0, | ||
'unicorn/consistent-destructuring': 0, | ||
'unicorn/no-await-expression-member': 0 | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "chartjs-adapter-intl", | ||
"version": "0.0.0", | ||
"description": "Chart.js adapter to use native ECMAScript Internationalization API for date formatting", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dankerow/chartjs-adapter-intl.git" | ||
}, | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "module", | ||
"jsdelivr": "dist/chartjs-adapter-intl.umd.min.js", | ||
"unpkg": "dist/chartjs-adapter-intl.umd.min.js", | ||
"main": "dist/chartjs-adapter-intl.esm.js", | ||
"exports": { | ||
".": "./dist/chartjs-adapter-intl.esm.js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "unbuild", | ||
"dev": "vitest", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"prepack": "pnpm build", | ||
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags", | ||
"test": "pnpm lint && vitest run --coverage" | ||
}, | ||
"peerDependencies": { | ||
"chart.js": ">=3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.5.5", | ||
"@vitest/coverage-v8": "^2.1.1", | ||
"changelogen": "^0.5.5", | ||
"chart.js": "^4.4.4", | ||
"eslint": "^9.10.0", | ||
"eslint-config-unjs": "^0.3.2", | ||
"typescript": "^5.5.3", | ||
"unbuild": "^2.0.0", | ||
"vitest": "^2.1.1" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Oops, something went wrong.