Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

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 e96caf8 commit c536d3a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 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
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

module.exports = string => {
export default function trimRight(string) {
let tail = string.length;

while (/[\s\uFEFF\u00A0]/.test(string[tail - 1])) {
tail--;
}

return string.slice(0, tail);
};
}
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 <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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
@@ -1,16 +1,19 @@
{
"name": "trim-right",
"version": "1.0.1",
"description": "Similar to String#trim() but removes only whitespace on the right",
"description": "Similar to `String#trim()` but removes only whitespace on the right",
"license": "MIT",
"repository": "sindresorhus/trim-right",
"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"
Expand All @@ -30,7 +33,7 @@
"trailing"
],
"devDependencies": {
"ava": "^2.3.0",
"xo": "^0.24.0"
"ava": "^3.15.0",
"xo": "^0.39.1"
}
}
6 changes: 1 addition & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

> Similar to [`String#trim()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) but removes only whitespace on the right

## Install

```
$ npm install trim-right
```


## Usage

```js
const trimRight = require('trim-right');
import trimRight from 'trim-right';

trimRight(' unicorn ');
//=> ' unicorn'
```


## Related

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


---

<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 trimRight from '.';
import trimRight from './index.js';

test('main', t => {
t.is(trimRight(' unicorn '), ' unicorn');
Expand Down

0 comments on commit c536d3a

Please sign in to comment.