Skip to content

Commit

Permalink
chore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
dankerow committed Sep 19, 2024
1 parent eff8dac commit 6d8070d
Show file tree
Hide file tree
Showing 10 changed files with 6,871 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
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
132 changes: 132 additions & 0 deletions README.md
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).
72 changes: 72 additions & 0 deletions build.config.ts
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
}
]);
12 changes: 12 additions & 0 deletions eslint.config.mjs
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
}
})
45 changes: 45 additions & 0 deletions package.json
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]"
}
Loading

0 comments on commit 6d8070d

Please sign in to comment.