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 21, 2021
1 parent 19bf3f6 commit c00fe4f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 25 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
- 8
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
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare const trimNewlines: {
@example
```js
import trimNewlines = require('trim-newlines');
import trimNewlines from 'trim-newlines';
trimNewlines('\n🦄\r\n');
//=> '🦄'
Expand All @@ -17,7 +17,7 @@ declare const trimNewlines: {
@example
```js
import trimNewlines = require('trim-newlines');
import trimNewlines from 'trim-newlines';
trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'
Expand All @@ -30,7 +30,7 @@ declare const trimNewlines: {
@example
```js
import trimNewlines = require('trim-newlines');
import trimNewlines from 'trim-newlines';
trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
Expand All @@ -39,4 +39,4 @@ declare const trimNewlines: {
end(string: string): string;
};

export = trimNewlines;
export default trimNewlines;
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
module.exports = string => string.replace(/^[\r\n]+|[\r\n]+$/g, '');
module.exports.start = string => string.replace(/^[\r\n]+/, '');
module.exports.end = string => string.replace(/[\r\n]+$/, '');
export default function trimNewlines(string) {
return string.replace(/^[\r\n]+|[\r\n]+$/g, '');
}

trimNewlines.start = string => string.replace(/^[\r\n]+/, '');
trimNewlines.end = string => string.replace(/[\r\n]+$/, '');
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 trimNewlines = require('.');
import trimNewlines from './index.js';

expectType<string>(trimNewlines('\n🦄\r\n'));
expectType<string>(trimNewlines.start('\n\n🦄\n'));
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

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:

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Trim newlines from the start and/or end of a string",
"license": "MIT",
"repository": "sindresorhus/trim-newlines",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -36,8 +39,8 @@
"strip"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.39.1"
}
}
7 changes: 1 addition & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

> Trim [newlines](https://en.wikipedia.org/wiki/Newline) from the start and/or end of a string

## Install

```
$ npm install trim-newlines
```


## Usage

```js
const trimNewlines = require('trim-newlines');
import trimNewlines from 'trim-newlines';

trimNewlines('\n🦄\r\n');
//=> '🦄'
Expand All @@ -25,7 +23,6 @@ trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
```


## API

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

Trim from the end of a string.


## Related

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


---

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import trimNewlines from '.';
import trimNewlines from './index.js';

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

0 comments on commit c00fe4f

Please sign in to comment.