diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18531b3..3b8aa86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/index.d.ts b/index.d.ts index 4185720..0aa9fbd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,7 @@ declare const trimNewlines: { @example ```js - import trimNewlines = require('trim-newlines'); + import trimNewlines from 'trim-newlines'; trimNewlines('\nšŸ¦„\r\n'); //=> 'šŸ¦„' @@ -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' @@ -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šŸ¦„' @@ -39,4 +39,4 @@ declare const trimNewlines: { end(string: string): string; }; -export = trimNewlines; +export default trimNewlines; diff --git a/index.js b/index.js index 9dda4de..d02f7f7 100644 --- a/index.js +++ b/index.js @@ -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]+$/, ''); diff --git a/index.test-d.ts b/index.test-d.ts index 6ce3e92..e941958 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import trimNewlines = require('.'); +import trimNewlines from './index.js'; expectType(trimNewlines('\nšŸ¦„\r\n')); expectType(trimNewlines.start('\n\nšŸ¦„\n')); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (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: diff --git a/package.json b/package.json index a1b9e59..ee61a97 100644 --- a/package.json +++ b/package.json @@ -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": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -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" } } diff --git a/readme.md b/readme.md index 7f084b7..2b8561b 100644 --- a/readme.md +++ b/readme.md @@ -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'); //=> 'šŸ¦„' @@ -25,7 +23,6 @@ trimNewlines.end('\nšŸ¦„\r\n'); //=> '\nšŸ¦„' ``` - ## API ### trimNewlines(string) @@ -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. - ---
diff --git a/test.js b/test.js index c48f1e9..e677076 100644 --- a/test.js +++ b/test.js @@ -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');