New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

trim-repeated

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trim-repeated - npm Package Compare versions

Comparing version

to
2.0.0

13

index.js

@@ -1,10 +0,11 @@

'use strict';
var escapeStringRegexp = require('escape-string-regexp');
import escapeStringRegexp from 'escape-string-regexp';
module.exports = function (str, target) {
if (typeof str !== 'string' || typeof target !== 'string') {
export default function trimRepeated(string, target) {
if (typeof string !== 'string' || typeof target !== 'string') {
throw new TypeError('Expected a string');
}
return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target);
};
const regex = new RegExp(`(?:${escapeStringRegexp(target)}){2,}`, 'g');
return string.replace(regex, target);
}
{
"name": "trim-repeated",
"version": "1.0.0",
"description": "Trim a consecutively repeated substring: foo--bar---baz → foo-bar-baz",
"license": "MIT",
"repository": "sindresorhus/trim-repeated",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "node test.js"
},
"files": [
"index.js"
],
"keywords": [
"condense",
"collapse",
"compact",
"consecutive",
"repeated",
"string",
"str",
"trim",
"remove",
"strip",
"character",
"char"
],
"dependencies": {
"escape-string-regexp": "^1.0.2"
},
"devDependencies": {
"ava": "0.0.4"
}
"name": "trim-repeated",
"version": "2.0.0",
"description": "Trim a consecutively repeated substring: foo--bar---baz → foo-bar-baz",
"license": "MIT",
"repository": "sindresorhus/trim-repeated",
"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": [
"condense",
"collapse",
"compact",
"consecutive",
"repeated",
"string",
"str",
"trim",
"remove",
"strip",
"character",
"char"
],
"dependencies": {
"escape-string-regexp": "^5.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.39.1"
}
}

@@ -1,17 +0,15 @@

# trim-repeated [![Build Status](https://travis-ci.org/sindresorhus/trim-repeated.svg?branch=master)](https://travis-ci.org/sindresorhus/trim-repeated)
# trim-repeated
> Trim a consecutively repeated substring: `foo--bar---baz` → `foo-bar-baz`
## Install
```
$ npm install --save trim-repeated
$ npm install trim-repeated
```
## Usage
```js
var trimRepeated = require('trim-repeated');
import trimRepeated from 'trim-repeated';

@@ -29,3 +27,3 @@ trimRepeated('foo--bar---baz', '-');

*Required*
*Required*\
Type: `string`

@@ -35,3 +33,3 @@

*Required*
*Required*\
Type: `string`

@@ -41,10 +39,4 @@

## Related
- [`condense-whitespace`](https://github.com/sindresorhus/condense-whitespace) - Remove leading, trailing and repeated whitespace from a string
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

Sorry, the diff of this file is not supported yet