strip-outer
Advanced tools
Comparing version 1.0.1 to 2.0.0
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 [![Build Status](https://travis-ci.org/sindresorhus/strip-outer.svg?branch=master)](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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
12
0
Yes
2482
22
- Removedescape-string-regexp@^1.0.2
- Removedescape-string-regexp@1.0.5(transitive)