Socket
Socket
Sign inDemoInstall

@wessberg/stringutil

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wessberg/stringutil - npm Package Compare versions

Comparing version 1.0.15 to 1.0.16

9

CHANGELOG.md

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

<a name="1.0.16"></a>
## <small>1.0.16 (2018-05-04)</small>
* 1.0.16 ([4bab235](https://github.com/wessberg/StringUtil/commit/4bab235))
* Bumped version ([b902b65](https://github.com/wessberg/StringUtil/commit/b902b65))
* Removed a few deprecated methods. Added a few new ones ([2c2b675](https://github.com/wessberg/StringUtil/commit/2c2b675))
<a name="1.0.15"></a>

@@ -2,0 +11,0 @@ ## <small>1.0.15 (2018-03-31)</small>

9

dist/cjs/string-util/i-string-util.d.ts

@@ -13,6 +13,4 @@ export interface IStringUtil {

isInKebabCase(str: string): boolean;
allMatchesOf(regex: RegExp, str: string, startingFrom?: number): string[];
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[];
allMatchesAndCaptureGroupsOf(regex: RegExp, str: string, startingFrom?: number): string[][];
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[];
allIndexesOf(str: string, regexp: RegExp, from?: number): number[];
matchAll(str: string, regexp: RegExp, from?: number): RegExpExecArray[];
trimAll(strings: string[]): string[];

@@ -26,6 +24,5 @@ camelCase(str: string): string;

containsWhitespace(str: string): boolean;
containsOnlyWhitespace(str: string): boolean;
trim(str: string): string;
takeFrom(str: string, from: number | string): string;
takeFromAfter(str: string, from: string): string;
unquote(str: string): string;
}

@@ -79,33 +79,17 @@ import { IStringUtil } from "./i-string-util";

/**
* Returns all RegExp matches and capture groups for the given regular expression and string, optionally starting from a specific character.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[][]}
*/
allMatchesAndCaptureGroupsOf(regex: RegExp, str: string, startingFrom?: number): string[][];
/**
* Returns all RegExp matches of the given regular expression on the given string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[]}
*/
allMatchesOf(regex: RegExp, str: string, startingFrom?: number): string[];
/**
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {RegExp} regexp
* @param {string} str
* @param {number} startingFrom
* @param {number} [from=0]
* @returns {number[]}
*/
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[];
allIndexesOf(str: string, regexp: RegExp, from?: number): number[];
/**
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* Matches all occurrences of the given RegExp, including capture groups, globally. Supports both global RegExps and non-global RegExps
* @param {string} str
* @param {number} startingFrom
* @returns {RegExpMatchArray[]}
* @param {RegExp} regexp
* @param {number} [from=0]
* @returns {RegExpExecArray[]}
*/
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[];
matchAll(str: string, regexp: RegExp, from?: number): RegExpExecArray[];
/**

@@ -155,21 +139,13 @@ * Trims all of the provided strings.

/**
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).
* Returns true if the given string contains nothing but whitespace
* @param {string} str
* @returns {string}
* @returns {boolean}
*/
trim(str: string): string;
containsOnlyWhitespace(str: string): boolean;
/**
* Slices a string from a specific index or string expression.
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).
* @param {string} str
* @param {number | string} from
* @returns {string}
*/
takeFrom(str: string, from: number | string): string;
/**
* Slices a string from after the string expression.
* @param {string} str
* @param {string} from
* @returns {string}
*/
takeFromAfter(str: string, from: string): string;
trim(str: string): string;
}

@@ -113,74 +113,33 @@ "use strict";

/**
* Returns all RegExp matches and capture groups for the given regular expression and string, optionally starting from a specific character.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[][]}
*/
allMatchesAndCaptureGroupsOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
let currentString = str;
while ((match = regex.exec(currentString)) != null) {
if (match.index >= startingFrom)
matches.push(match.slice(1));
currentString = currentString.slice(currentString.indexOf(match[1]) + match[1].length);
}
return matches;
}
/**
* Returns all RegExp matches of the given regular expression on the given string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[]}
*/
allMatchesOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
let currentString = str;
while ((match = regex.exec(currentString)) != null) {
if (match.index >= startingFrom)
matches.push(match[1]);
currentString = currentString.slice(currentString.indexOf(match[1]) + match[1].length);
}
return matches;
}
/**
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {RegExp} regexp
* @param {string} str
* @param {number} startingFrom
* @param {number} [from=0]
* @returns {number[]}
*/
allIndexesOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
while ((match = regex.exec(str)) != null) {
if (match.index >= startingFrom)
matches.push(match.index);
}
return matches;
allIndexesOf(str, regexp, from = 0) {
return this.matchAll(str, regexp, from).map(match => match.index);
}
/**
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* Matches all occurrences of the given RegExp, including capture groups, globally. Supports both global RegExps and non-global RegExps
* @param {string} str
* @param {number} startingFrom
* @returns {RegExpMatchArray[]}
* @param {RegExp} regexp
* @param {number} [from=0]
* @returns {RegExpExecArray[]}
*/
allMatchObjectsOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
matchAll(str, regexp, from = 0) {
let flags = regexp.flags;
if (!flags.includes("g")) {
flags += "g";
}
// Normalize the regular expression and make sure it *does* include the Global ('g') flag
const normalizedRegExp = new RegExp(regexp, flags);
const matches = [];
let match;
while ((match = regex.exec(str)) != null) {
if (match.index >= startingFrom)
while (true) {
const match = normalizedRegExp.exec(str);
if (match == null)
break;
if (match.index >= from) {
matches.push(match);
}
}

@@ -258,3 +217,5 @@ return matches;

// Remove any kind of whitespace.
return str.replace(/[ \n\t\r]/g, "").replace(/&nbsp;/, "");
return str
.replace(/[ \n\t\r]/g, "")
.replace(/&nbsp;/, "");
}

@@ -267,5 +228,13 @@ /**

containsWhitespace(str) {
return /(&nbsp;|\t|\n|\r|\s)/.test(str);
return str.length !== this.removeWhitespace(str).length;
}
/**
* Returns true if the given string contains nothing but whitespace
* @param {string} str
* @returns {boolean}
*/
containsOnlyWhitespace(str) {
return this.removeWhitespace(str).length === 0;
}
/**
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).

@@ -287,23 +256,4 @@ * @param {string} str

}
/**
* Slices a string from a specific index or string expression.
* @param {string} str
* @param {number | string} from
* @returns {string}
*/
takeFrom(str, from) {
const index = typeof from === "number" ? from : str.indexOf(from);
return str.slice(index);
}
/**
* Slices a string from after the string expression.
* @param {string} str
* @param {string} from
* @returns {string}
*/
takeFromAfter(str, from) {
return this.takeFrom(str, from).slice(from.length);
}
}
exports.StringUtil = StringUtil;
//# sourceMappingURL=string-util.js.map

@@ -13,6 +13,4 @@ export interface IStringUtil {

isInKebabCase(str: string): boolean;
allMatchesOf(regex: RegExp, str: string, startingFrom?: number): string[];
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[];
allMatchesAndCaptureGroupsOf(regex: RegExp, str: string, startingFrom?: number): string[][];
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[];
allIndexesOf(str: string, regexp: RegExp, from?: number): number[];
matchAll(str: string, regexp: RegExp, from?: number): RegExpExecArray[];
trimAll(strings: string[]): string[];

@@ -26,6 +24,5 @@ camelCase(str: string): string;

containsWhitespace(str: string): boolean;
containsOnlyWhitespace(str: string): boolean;
trim(str: string): string;
takeFrom(str: string, from: number | string): string;
takeFromAfter(str: string, from: string): string;
unquote(str: string): string;
}

@@ -79,33 +79,17 @@ import { IStringUtil } from "./i-string-util";

/**
* Returns all RegExp matches and capture groups for the given regular expression and string, optionally starting from a specific character.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[][]}
*/
allMatchesAndCaptureGroupsOf(regex: RegExp, str: string, startingFrom?: number): string[][];
/**
* Returns all RegExp matches of the given regular expression on the given string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[]}
*/
allMatchesOf(regex: RegExp, str: string, startingFrom?: number): string[];
/**
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {RegExp} regexp
* @param {string} str
* @param {number} startingFrom
* @param {number} [from=0]
* @returns {number[]}
*/
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[];
allIndexesOf(str: string, regexp: RegExp, from?: number): number[];
/**
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* Matches all occurrences of the given RegExp, including capture groups, globally. Supports both global RegExps and non-global RegExps
* @param {string} str
* @param {number} startingFrom
* @returns {RegExpMatchArray[]}
* @param {RegExp} regexp
* @param {number} [from=0]
* @returns {RegExpExecArray[]}
*/
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[];
matchAll(str: string, regexp: RegExp, from?: number): RegExpExecArray[];
/**

@@ -155,21 +139,13 @@ * Trims all of the provided strings.

/**
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).
* Returns true if the given string contains nothing but whitespace
* @param {string} str
* @returns {string}
* @returns {boolean}
*/
trim(str: string): string;
containsOnlyWhitespace(str: string): boolean;
/**
* Slices a string from a specific index or string expression.
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).
* @param {string} str
* @param {number | string} from
* @returns {string}
*/
takeFrom(str: string, from: number | string): string;
/**
* Slices a string from after the string expression.
* @param {string} str
* @param {string} from
* @returns {string}
*/
takeFromAfter(str: string, from: string): string;
trim(str: string): string;
}

@@ -111,74 +111,33 @@ /**

/**
* Returns all RegExp matches and capture groups for the given regular expression and string, optionally starting from a specific character.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[][]}
*/
allMatchesAndCaptureGroupsOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
let currentString = str;
while ((match = regex.exec(currentString)) != null) {
if (match.index >= startingFrom)
matches.push(match.slice(1));
currentString = currentString.slice(currentString.indexOf(match[1]) + match[1].length);
}
return matches;
}
/**
* Returns all RegExp matches of the given regular expression on the given string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {string} str
* @param {number} startingFrom
* @returns {string[]}
*/
allMatchesOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
let currentString = str;
while ((match = regex.exec(currentString)) != null) {
if (match.index >= startingFrom)
matches.push(match[1]);
currentString = currentString.slice(currentString.indexOf(match[1]) + match[1].length);
}
return matches;
}
/**
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* @param {RegExp} regexp
* @param {string} str
* @param {number} startingFrom
* @param {number} [from=0]
* @returns {number[]}
*/
allIndexesOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
const matches = [];
let match;
while ((match = regex.exec(str)) != null) {
if (match.index >= startingFrom)
matches.push(match.index);
}
return matches;
allIndexesOf(str, regexp, from = 0) {
return this.matchAll(str, regexp, from).map(match => match.index);
}
/**
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index.
* @param {RegExp} regex
* Matches all occurrences of the given RegExp, including capture groups, globally. Supports both global RegExps and non-global RegExps
* @param {string} str
* @param {number} startingFrom
* @returns {RegExpMatchArray[]}
* @param {RegExp} regexp
* @param {number} [from=0]
* @returns {RegExpExecArray[]}
*/
allMatchObjectsOf(regex, str, startingFrom = 0) {
if (startingFrom < 0 || startingFrom > str.length)
throw new RangeError(`Given 'startingFrom' value: ${startingFrom} is out of bounds!`);
matchAll(str, regexp, from = 0) {
let flags = regexp.flags;
if (!flags.includes("g")) {
flags += "g";
}
// Normalize the regular expression and make sure it *does* include the Global ('g') flag
const normalizedRegExp = new RegExp(regexp, flags);
const matches = [];
let match;
while ((match = regex.exec(str)) != null) {
if (match.index >= startingFrom)
while (true) {
const match = normalizedRegExp.exec(str);
if (match == null)
break;
if (match.index >= from) {
matches.push(match);
}
}

@@ -256,3 +215,5 @@ return matches;

// Remove any kind of whitespace.
return str.replace(/[ \n\t\r]/g, "").replace(/&nbsp;/, "");
return str
.replace(/[ \n\t\r]/g, "")
.replace(/&nbsp;/, "");
}

@@ -265,5 +226,13 @@ /**

containsWhitespace(str) {
return /(&nbsp;|\t|\n|\r|\s)/.test(str);
return str.length !== this.removeWhitespace(str).length;
}
/**
* Returns true if the given string contains nothing but whitespace
* @param {string} str
* @returns {boolean}
*/
containsOnlyWhitespace(str) {
return this.removeWhitespace(str).length === 0;
}
/**
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces (&nbsp;).

@@ -285,22 +254,3 @@ * @param {string} str

}
/**
* Slices a string from a specific index or string expression.
* @param {string} str
* @param {number | string} from
* @returns {string}
*/
takeFrom(str, from) {
const index = typeof from === "number" ? from : str.indexOf(from);
return str.slice(index);
}
/**
* Slices a string from after the string expression.
* @param {string} str
* @param {string} from
* @returns {string}
*/
takeFromAfter(str, from) {
return this.takeFrom(str, from).slice(from.length);
}
}
//# sourceMappingURL=string-util.js.map
{
"name": "@wessberg/stringutil",
"version": "1.0.15",
"version": "1.0.16",
"description": "A class for performing simple operations on strings.",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc