strip-outer
Advanced tools
Comparing version
20
index.js
@@ -1,11 +0,15 @@ | ||
'use strict'; | ||
var escapeStringRegexp = require('escape-string-regexp'); | ||
export default function stripOuter(string, substring) { | ||
if (typeof string !== 'string' || typeof substring !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
module.exports = function (str, sub) { | ||
if (typeof str !== 'string' || typeof sub !== 'string') { | ||
throw new TypeError(); | ||
if (string.startsWith(substring)) { | ||
string = string.slice(substring.length); | ||
} | ||
sub = escapeStringRegexp(sub); | ||
return str.replace(new RegExp('^' + sub + '|' + sub + '$', 'g'), ''); | ||
}; | ||
if (string.endsWith(substring)) { | ||
string = string.slice(0, -substring.length); | ||
} | ||
return string; | ||
} |
{ | ||
"name": "strip-outer", | ||
"version": "1.0.1", | ||
"description": "Strip a substring from the start/end of a string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/strip-outer", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"strip", | ||
"trim", | ||
"remove", | ||
"outer", | ||
"str", | ||
"string", | ||
"substring", | ||
"start", | ||
"end", | ||
"wrap", | ||
"leading", | ||
"trailing", | ||
"regex", | ||
"regexp" | ||
], | ||
"dependencies": { | ||
"escape-string-regexp": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "strip-outer", | ||
"version": "2.0.0", | ||
"description": "Strip a substring from the start/end of a string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/strip-outer", | ||
"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.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"strip", | ||
"trim", | ||
"remove", | ||
"outer", | ||
"string", | ||
"substring", | ||
"start", | ||
"end", | ||
"wrap", | ||
"leading", | ||
"trailing" | ||
], | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -1,17 +0,15 @@ | ||
# strip-outer [](https://travis-ci.org/sindresorhus/strip-outer) | ||
# strip-outer | ||
> Strip a substring from the start/end of a string | ||
## Install | ||
``` | ||
$ npm install --save strip-outer | ||
$ npm install strip-outer | ||
``` | ||
## Usage | ||
```js | ||
const stripOuter = require('strip-outer'); | ||
import stripOuter from 'strip-outer'; | ||
@@ -24,6 +22,1 @@ stripOuter('foobarfoo', 'foo'); | ||
``` | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
0
-100%12
33.33%0
-100%Yes
NaN2482
-6.3%22
-24.14%- Removed
- Removed