Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 18, 2021
1 parent 7ee093f commit 01765af
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 57 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
57 changes: 25 additions & 32 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
declare namespace transliterate {
interface Options {
/**
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key.
@default []
@example
```
import transliterate = require('@sindresorhus/transliterate');
transliterate('Я люблю единорогов', {
customReplacements: [
['единорогов', '🦄']
]
})
//=> 'Ya lyublyu 🦄'
```
*/
readonly customReplacements?: ReadonlyArray<[string, string]>;
}
export interface Options {
/**
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key.
@default []
@example
```
import transliterate from '@sindresorhus/transliterate';
transliterate('Я люблю единорогов', {
customReplacements: [
['единорогов', '🦄']
]
})
//=> 'Ya lyublyu 🦄'
```
*/
readonly customReplacements?: ReadonlyArray<[string, string]>;
}

/**
Expand All @@ -32,7 +30,7 @@ Convert Unicode characters to Latin characters using [transliteration](https://e
@example
```
import transliterate = require('@sindresorhus/transliterate');
import transliterate from '@sindresorhus/transliterate';
transliterate('Fußgängerübergänge');
//=> 'Fussgaengeruebergaenge'
Expand All @@ -47,9 +45,4 @@ transliterate('tôi yêu những chú kỳ lân');
//=> 'toi yeu nhung chu ky lan'
```
*/
declare function transliterate(
string: string,
options?: transliterate.Options
): string;

export = transliterate;
export default function transliterate(string: string, options?: Options): string;
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
const deburr = require('lodash.deburr');
const escapeStringRegexp = require('escape-string-regexp');
const builtinReplacements = require('./replacements');
import deburr from 'lodash.deburr';
import escapeStringRegexp from 'escape-string-regexp';
import builtinReplacements from './replacements.js';

const doCustomReplacements = (string, replacements) => {
for (const [key, value] of replacements) {
Expand All @@ -12,7 +11,7 @@ const doCustomReplacements = (string, replacements) => {
return string;
};

module.exports = (string, options) => {
export default function transliterate(string, options) {
if (typeof string !== 'string') {
throw new TypeError(`Expected a string, got \`${typeof string}\``);
}
Expand All @@ -32,4 +31,4 @@ module.exports = (string, options) => {
string = deburr(string);

return string;
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import transliterate = require('.');
import transliterate from './index.js';

expectType<string>(transliterate('Я люблю единорогов'));
expectType<string>(
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "[email protected]",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -35,12 +37,12 @@
"replace"
],
"dependencies": {
"escape-string-regexp": "^2.0.0",
"escape-string-regexp": "^5.0.0",
"lodash.deburr": "^4.1.0"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.11.0",
"xo": "^0.26.1"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ npm install @sindresorhus/transliterate
## Usage

```js
const transliterate = require('@sindresorhus/transliterate');
import transliterate from '@sindresorhus/transliterate';

transliterate('Fußgängerübergänge');
//=> 'Fussgaengeruebergaenge'
Expand Down Expand Up @@ -54,7 +54,7 @@ The replacements are run on the original string before any other transformations
This only overrides a default replacement if you set an item with the same key.

```js
const transliterate = require('@sindresorhus/transliterate');
import transliterate from '@sindresorhus/transliterate';

transliterate('Я люблю единорогов', {
customReplacements: [
Expand Down
6 changes: 3 additions & 3 deletions replacements.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = [
const replacements = [
// German umlauts
['ß', 'ss'],
['ä', 'ae'],
Expand Down Expand Up @@ -795,3 +793,5 @@ module.exports = [
// ['ø', 'oe'],
// ['å', 'aa']
];

export default replacements;
5 changes: 2 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import transliterate from '.';
import replacements from './replacements';
import transliterate from './index.js';
import replacements from './replacements.js';

test('main', t => {
t.is(transliterate('Foo ÿ'), 'Foo y');
Expand Down Expand Up @@ -130,4 +130,3 @@ test.failing('supports Swedish', t => {
test('supports Ukrainian', t => {
t.is(transliterate('Є Ґ ї'), 'Ye G yi');
});

0 comments on commit 01765af

Please sign in to comment.