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 15, 2021
1 parent 0de4f50 commit 2f6f72d
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
6 changes: 1 addition & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
- 6
- 4
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
const toArray = require('lodash.toarray');
import toArray from 'lodash.toarray';

module.exports = (str, i, count, insert) => {
const arr = toArray(str);
arr.splice(i, count, insert);
return arr.join('');
};
export default function spliceString(string, index, count, insert) {
const array = toArray(string);
array.splice(index, count, insert);
return array.join('');
}
22 changes: 5 additions & 17 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
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:
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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
85 changes: 41 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
{
"name": "splice-string",
"version": "2.0.0",
"description": "Remove or replace part of a string like Array#splice",
"license": "MIT",
"repository": "sindresorhus/splice-string",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"splice",
"string",
"str",
"split",
"modify",
"mutate",
"replace",
"insert",
"add",
"remove",
"rm",
"delete",
"del"
],
"dependencies": {
"lodash.toarray": "^4.4.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
"name": "splice-string",
"version": "2.0.0",
"description": "Remove or replace part of a string like `Array#splice`",
"license": "MIT",
"repository": "sindresorhus/splice-string",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"splice",
"string",
"split",
"modify",
"mutate",
"replace",
"insert",
"add",
"remove",
"delete"
],
"dependencies": {
"lodash.toarray": "^4.4.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.38.2"
}
}
16 changes: 5 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

> Remove or replace part of a string like `Array#splice`
It correctly handles slicing strings with emoji.

## Install

```
$ npm install --save splice-string
$ npm install splice-string
```


## Usage

```js
const spliceString = require('splice-string');
import spliceString from 'splice-string';

spliceString('unicorn', 3, 4, 'verse');
//=> 'universe'
Expand All @@ -22,12 +22,11 @@ spliceString('❤️🐴🐴', 1, 1, '🦄');
//=> '❤️🦄🐴'
```


## API

### spliceString(input, index, count, [insert])
### spliceString(string, index, count, insert?)

#### input
#### string

Type: `string`

Expand All @@ -48,8 +47,3 @@ Number of characters to remove.
Type: `string`

String to insert in place of the removed substring.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
30 changes: 15 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import test from 'ava';
import m from './';
import spliceString from './index.js';

test(t => {
t.is(m('foobar', 3, 3, 'foo'), 'foofoo');
t.is(m('foobar', 5, 3, '1'), 'fooba1');
t.is(m('unicorn', 3, 4, 'verse'), 'universe');
t.is(m('unicorn', 3, 4, 'verse'), 'universe');
t.is(m('example', 0, 0, 'a'), 'aexample');
t.is(m('exam\nple', null, null, 'a'), 'aexam\nple');
t.is(m('example', 2, 0, 'a'), 'exaample');
t.is(m('\u0024example', 3, 1, ''), '$exmple');
t.is(m('🐴🐴🐴', 1, 1, '🦄'), '🐴🦄🐴');
t.is(m('🐴🐴🐴', 999, 1, '🦄'), '🐴🐴🐴🦄');
t.is(m('🐴🐴🐴', 0, 999, '🦄'), '🦄');
t.is(m('🐴🐴🐴', 0, 999, ''), '');
t.is(m('❤️🐴🐴', 1, 1, '🦄'), '❤️🦄🐴');
test('main', t => {
t.is(spliceString('foobar', 3, 3, 'foo'), 'foofoo');
t.is(spliceString('foobar', 5, 3, '1'), 'fooba1');
t.is(spliceString('unicorn', 3, 4, 'verse'), 'universe');
t.is(spliceString('unicorn', 3, 4, 'verse'), 'universe');
t.is(spliceString('example', 0, 0, 'a'), 'aexample');
t.is(spliceString('exam\nple', null, null, 'a'), 'aexam\nple');
t.is(spliceString('example', 2, 0, 'a'), 'exaample');
t.is(spliceString('\u0024example', 3, 1, ''), '$exmple');
t.is(spliceString('🐴🐴🐴', 1, 1, '🦄'), '🐴🦄🐴');
t.is(spliceString('🐴🐴🐴', 999, 1, '🦄'), '🐴🐴🐴🦄');
t.is(spliceString('🐴🐴🐴', 0, 999, '🦄'), '🦄');
t.is(spliceString('🐴🐴🐴', 0, 999, ''), '');
t.is(spliceString('❤️🐴🐴', 1, 1, '🦄'), '❤️🦄🐴');
});

0 comments on commit 2f6f72d

Please sign in to comment.