Skip to content

Commit ccc18e1

Browse files
committedApr 16, 2021
Require Node.js 12 and move to ESM
1 parent 108616c commit ccc18e1

File tree

8 files changed

+23
-28
lines changed

8 files changed

+23
-28
lines changed
 

‎.github/workflows/main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
1715
steps:
1816
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
2018
with:
2119
node-version: ${{ matrix.node-version }}
2220
- run: npm install

‎index.d.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ Strip UTF-8 [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark#UTF-
33
44
@example
55
```
6-
import stripBom = require('strip-bom');
6+
import stripBom from 'strip-bom';
77
88
stripBom('\uFEFFunicorn');
99
//=> 'unicorn'
1010
```
1111
*/
12-
declare function stripBom(string: string): string;
13-
14-
export = stripBom;
12+
export default function stripBom(string: string): string;

‎index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
'use strict';
2-
3-
module.exports = string => {
1+
export default function stripBom(string) {
42
if (typeof string !== 'string') {
53
throw new TypeError(`Expected a string, got ${typeof string}`);
64
}
75

86
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
9-
// conversion translates it to FEFF (UTF-16 BOM)
7+
// conversion translates it to FEFF (UTF-16 BOM).
108
if (string.charCodeAt(0) === 0xFEFF) {
119
return string.slice(1);
1210
}
1311

1412
return string;
15-
};
13+
}

‎index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import {expectType} from 'tsd';
2-
import stripBom = require('.');
2+
import stripBom from './index.js';
33

44
expectType<string>(stripBom('\uFEFFunicorn'));

‎license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

‎package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Strip UTF-8 byte order mark (BOM) from a string",
55
"license": "MIT",
66
"repository": "sindresorhus/strip-bom",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -35,8 +38,8 @@
3538
"string"
3639
],
3740
"devDependencies": {
38-
"ava": "^1.4.1",
39-
"tsd": "^0.7.2",
40-
"xo": "^0.24.0"
41+
"ava": "^3.15.0",
42+
"tsd": "^0.14.0",
43+
"xo": "^0.38.2"
4144
}
4245
}

‎readme.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,27 @@ From Wikipedia:
66

77
> The Unicode Standard permits the BOM in UTF-8, but does not require nor recommend its use. Byte order has no meaning in UTF-8.
88
9-
109
## Install
1110

1211
```
1312
$ npm install strip-bom
1413
```
1514

16-
1715
## Usage
1816

1917
```js
20-
const stripBom = require('strip-bom');
18+
import stripBom from 'strip-bom';
2119

2220
stripBom('\uFEFFunicorn');
2321
//=> 'unicorn'
2422
```
2523

26-
2724
## Related
2825

2926
- [strip-bom-cli](https://github.com/sindresorhus/strip-bom-cli) - CLI for this module
3027
- [strip-bom-buf](https://github.com/sindresorhus/strip-bom-buf) - Buffer version of this module
3128
- [strip-bom-stream](https://github.com/sindresorhus/strip-bom-stream) - Stream version of this module
3229

33-
3430
---
3531

3632
<div align="center">

‎test/test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import fs from 'fs';
2-
import path from 'path';
32
import test from 'ava';
4-
import stripBom from '..';
3+
import stripBom from '../index.js';
54

65
test('strips BOM from string', t => {
7-
t.is(stripBom(fs.readFileSync(path.join(__dirname, 'fixture-utf8'), 'utf8')), 'Unicorn\n');
6+
const filePath = new URL('fixture-utf8', import.meta.url);
7+
const fixture = fs.readFileSync(filePath, 'utf8');
8+
t.is(stripBom(fixture), 'Unicorn\n');
89
});
910

1011
test('strips BOM from the beginning of a file', t => {
11-
const fixture = fs.readFileSync(path.join(__dirname, 'fixture-utf8-bom-middle'), 'utf8');
12+
const filePath = new URL('fixture-utf8-bom-middle', import.meta.url);
13+
const fixture = fs.readFileSync(filePath, 'utf8');
1214
t.is(stripBom(fixture), fixture);
1315
});

0 commit comments

Comments
 (0)
Please sign in to comment.