Skip to content

Commit c00fe4f

Browse files
committed
Require Node.js 12 and move to ESM
1 parent 19bf3f6 commit c00fe4f

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
16-
- 8
1716
steps:
1817
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
18+
- uses: actions/setup-node@v2
2019
with:
2120
node-version: ${{ matrix.node-version }}
2221
- run: npm install

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare const trimNewlines: {
44
55
@example
66
```js
7-
import trimNewlines = require('trim-newlines');
7+
import trimNewlines from 'trim-newlines';
88
99
trimNewlines('\n🦄\r\n');
1010
//=> '🦄'
@@ -17,7 +17,7 @@ declare const trimNewlines: {
1717
1818
@example
1919
```js
20-
import trimNewlines = require('trim-newlines');
20+
import trimNewlines from 'trim-newlines';
2121
2222
trimNewlines.start('\n🦄\r\n');
2323
//=> '🦄\r\n'
@@ -30,7 +30,7 @@ declare const trimNewlines: {
3030
3131
@example
3232
```js
33-
import trimNewlines = require('trim-newlines');
33+
import trimNewlines from 'trim-newlines';
3434
3535
trimNewlines.end('\n🦄\r\n');
3636
//=> '\n🦄'
@@ -39,4 +39,4 @@ declare const trimNewlines: {
3939
end(string: string): string;
4040
};
4141

42-
export = trimNewlines;
42+
export default trimNewlines;

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
'use strict';
2-
module.exports = string => string.replace(/^[\r\n]+|[\r\n]+$/g, '');
3-
module.exports.start = string => string.replace(/^[\r\n]+/, '');
4-
module.exports.end = string => string.replace(/[\r\n]+$/, '');
1+
export default function trimNewlines(string) {
2+
return string.replace(/^[\r\n]+|[\r\n]+$/g, '');
3+
}
4+
5+
trimNewlines.start = string => string.replace(/^[\r\n]+/, '');
6+
trimNewlines.end = string => string.replace(/[\r\n]+$/, '');

index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import trimNewlines = require('.');
2+
import trimNewlines from './index.js';
33

44
expectType<string>(trimNewlines('\n🦄\r\n'));
55
expectType<string>(trimNewlines.start('\n\n🦄\n'));

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Trim newlines from the start and/or end of a string",
55
"license": "MIT",
66
"repository": "sindresorhus/trim-newlines",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
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"
@@ -36,8 +39,8 @@
3639
"strip"
3740
],
3841
"devDependencies": {
39-
"ava": "^1.4.1",
40-
"tsd": "^0.7.2",
41-
"xo": "^0.24.0"
42+
"ava": "^3.15.0",
43+
"tsd": "^0.14.0",
44+
"xo": "^0.39.1"
4245
}
4346
}

readme.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
> Trim [newlines](https://en.wikipedia.org/wiki/Newline) from the start and/or end of a string
44
5-
65
## Install
76

87
```
98
$ npm install trim-newlines
109
```
1110

12-
1311
## Usage
1412

1513
```js
16-
const trimNewlines = require('trim-newlines');
14+
import trimNewlines from 'trim-newlines';
1715

1816
trimNewlines('\n🦄\r\n');
1917
//=> '🦄'
@@ -25,7 +23,6 @@ trimNewlines.end('\n🦄\r\n');
2523
//=> '\n🦄'
2624
```
2725

28-
2926
## API
3027

3128
### trimNewlines(string)
@@ -40,13 +37,11 @@ Trim from the start of a string.
4037

4138
Trim from the end of a string.
4239

43-
4440
## Related
4541

4642
- [trim-left](https://github.com/sindresorhus/trim-left) - Similar to `String#trim()` but removes only whitespace on the left
4743
- [trim-right](https://github.com/sindresorhus/trim-right) - Similar to `String#trim()` but removes only whitespace on the right.
4844

49-
5045
---
5146

5247
<div align="center">

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import trimNewlines from '.';
2+
import trimNewlines from './index.js';
33

44
test('main', t => {
55
t.is(trimNewlines('\nx\n'), 'x');

0 commit comments

Comments
 (0)