Skip to content

Commit

Permalink
feat: use named exports, export utils from main entry point
Browse files Browse the repository at this point in the history
BREAKING CHANGE: There is no longer a default export, please update any imports as per the readme
  • Loading branch information
DJTB committed Mar 14, 2022
1 parent a06c7dd commit 8c09a8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[![Codecov branch](https://img.shields.io/codecov/c/github/DJTB/hatsuon/master.svg?style=flat-square)](https://codecov.io/github/DJTB/hatsuon)
<br />
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](./code_of_conduct.md)

## Why?
Expand All @@ -28,7 +27,7 @@ npm install --save hatsuon
## Usage

```js
import hatsuon from 'hatsuon';
import { hatsuon } from 'hatsuon';

hatsuon({ reading: 'ちゅうがっこう', pitchNum: 3 });
// =>
Expand All @@ -53,7 +52,7 @@ import {
makePitchPattern,
getPitchPatternName,
getPitchNumFromPattern,
} from 'hatsuon/dist/utils';
} from 'hatsuon';
```

## Related
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { getMorae, makePitchPattern, getPitchPatternName } from './utils';

export {
isDigraph,
getMorae,
getMoraCount,
makePitchPattern,
getPitchPatternName,
getPitchNumFromPattern,
} from './utils';

/**
* Returns pitch accent information for the provided word and pitch number
*
Expand All @@ -8,8 +17,9 @@ import { getMorae, makePitchPattern, getPitchPatternName } from './utils';
* @param {number} [pitchNum=-1] pitch number
* @returns {object} pitch data
*/
export default function hatsuon({ reading = '', pitchNum = -1, locale = 'JA' } = {}) {
export function hatsuon({ reading = '', pitchNum = -1, locale = 'JA' } = {}) {
const morae = getMorae(reading);

return {
reading,
morae,
Expand Down
4 changes: 3 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hatsuon from './index';
import { hatsuon } from './index';

describe('hatsuon()', () => {
it('sane default', () =>
Expand All @@ -9,6 +9,7 @@ describe('hatsuon()', () => {
pattern: [],
patternName: '不詳',
}));

it('works', () => {
expect(hatsuon({ reading: 'よみかた', pitchNum: 3 })).toEqual({
reading: 'よみかた',
Expand All @@ -18,6 +19,7 @@ describe('hatsuon()', () => {
patternName: '中高',
});
});

it('accepts locale', () => {
expect(hatsuon({ reading: 'とっきゅう', pitchNum: 0, locale: 'EN' })).toEqual({
reading: 'とっきゅう',
Expand Down

0 comments on commit 8c09a8e

Please sign in to comment.