@wessberg/stringutil
Advanced tools
Comparing version 1.0.0 to 1.0.3
export { StringUtil } from "./StringUtil"; | ||
export { IStringUtil } from "./interface/IStringUtil"; | ||
export { IStringUtil } from "./Interface/IStringUtil"; |
@@ -1,16 +0,101 @@ | ||
import { IStringUtil } from "./interface/IStringUtil"; | ||
import { IStringUtil } from "./Interface/IStringUtil"; | ||
/** | ||
* A class for performing simple operations on strings. | ||
*/ | ||
export declare class StringUtil implements IStringUtil { | ||
/** | ||
* 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 {string} str | ||
* @param {number} startingFrom | ||
* @returns {number[]} | ||
*/ | ||
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[]; | ||
/** | ||
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {RegExpMatchArray[]} | ||
*/ | ||
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[]; | ||
/** | ||
* Trims all of the provided strings. | ||
* @param {string[]} strings | ||
* @returns {string[]} | ||
*/ | ||
trimAll(strings: string[]): string[]; | ||
/** | ||
* camelCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
camelCase(str: string): string; | ||
/** | ||
* PascalCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
pascalCase(str: string): string; | ||
/** | ||
* Capitalizes the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
capitalize(str: string): string; | ||
/** | ||
* kebab-cases (dash-cases) the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
kebabCase(str: string): string; | ||
/** | ||
* lowercases the first character of the provided string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
lowerCaseFirst(str: string): string; | ||
/** | ||
* Removes all whitespace from a string. If the second argument is truthy, it will preserve spaces. | ||
* @param {string} str | ||
* @param {boolean} [preserveSpaces=false] | ||
* @returns {string} | ||
*/ | ||
removeWhitespace(str: string, preserveSpaces?: boolean): string; | ||
/** | ||
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces ( ). | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
trim(str: string): string; | ||
/** | ||
* Slices a string from a specific index or string expression. | ||
* @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; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* A class for performing simple operations on strings. | ||
*/ | ||
class StringUtil { | ||
/** | ||
* 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) { | ||
@@ -17,2 +27,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* 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) { | ||
@@ -31,2 +48,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {number[]} | ||
*/ | ||
allIndexesOf(regex, str, startingFrom = 0) { | ||
@@ -43,2 +67,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {RegExpMatchArray[]} | ||
*/ | ||
allMatchObjectsOf(regex, str, startingFrom = 0) { | ||
@@ -55,5 +86,15 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Trims all of the provided strings. | ||
* @param {string[]} strings | ||
* @returns {string[]} | ||
*/ | ||
trimAll(strings) { | ||
return strings.map(str => str.trim()); | ||
return strings.map(str => this.trim(str)); | ||
} | ||
/** | ||
* camelCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
camelCase(str) { | ||
@@ -66,5 +107,23 @@ return this.lowerCaseFirst(str | ||
} | ||
/** | ||
* PascalCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
pascalCase(str) { | ||
return this.capitalize(this.camelCase(str)); | ||
} | ||
/** | ||
* Capitalizes the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
capitalize(str) { | ||
return str.slice(0, 1).toUpperCase() + str.slice(1); | ||
} | ||
/** | ||
* kebab-cases (dash-cases) the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
kebabCase(str) { | ||
@@ -77,6 +136,17 @@ // Lower cases the string | ||
} | ||
/** | ||
* lowercases the first character of the provided string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
lowerCaseFirst(str) { | ||
return str.slice(0, 1).toLowerCase() + str.slice(1); | ||
} | ||
removeWhitespace(str, preserveSpaces) { | ||
/** | ||
* Removes all whitespace from a string. If the second argument is truthy, it will preserve spaces. | ||
* @param {string} str | ||
* @param {boolean} [preserveSpaces=false] | ||
* @returns {string} | ||
*/ | ||
removeWhitespace(str, preserveSpaces = false) { | ||
// Convert tabs to spaces and remove anything but spaces. | ||
@@ -92,2 +162,7 @@ if (preserveSpaces) | ||
} | ||
/** | ||
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces ( ). | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
trim(str) { | ||
@@ -105,2 +180,8 @@ let local = str.trim(); | ||
} | ||
/** | ||
* Slices a string from a specific index or string expression. | ||
* @param {string} str | ||
* @param {number | string} from | ||
* @returns {string} | ||
*/ | ||
takeFrom(str, from) { | ||
@@ -110,2 +191,8 @@ const index = typeof from === "number" ? from : str.indexOf(from); | ||
} | ||
/** | ||
* Slices a string from after the string expression. | ||
* @param {string} str | ||
* @param {string} from | ||
* @returns {string} | ||
*/ | ||
takeFromAfter(str, from) { | ||
@@ -112,0 +199,0 @@ return this.takeFrom(str, from).slice(from.length); |
export { StringUtil } from "./StringUtil"; | ||
export { IStringUtil } from "./interface/IStringUtil"; | ||
export { IStringUtil } from "./Interface/IStringUtil"; |
@@ -1,16 +0,101 @@ | ||
import { IStringUtil } from "./interface/IStringUtil"; | ||
import { IStringUtil } from "./Interface/IStringUtil"; | ||
/** | ||
* A class for performing simple operations on strings. | ||
*/ | ||
export declare class StringUtil implements IStringUtil { | ||
/** | ||
* 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 {string} str | ||
* @param {number} startingFrom | ||
* @returns {number[]} | ||
*/ | ||
allIndexesOf(regex: RegExp, str: string, startingFrom?: number): number[]; | ||
/** | ||
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {RegExpMatchArray[]} | ||
*/ | ||
allMatchObjectsOf(regex: RegExp, str: string, startingFrom?: number): RegExpMatchArray[]; | ||
/** | ||
* Trims all of the provided strings. | ||
* @param {string[]} strings | ||
* @returns {string[]} | ||
*/ | ||
trimAll(strings: string[]): string[]; | ||
/** | ||
* camelCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
camelCase(str: string): string; | ||
/** | ||
* PascalCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
pascalCase(str: string): string; | ||
/** | ||
* Capitalizes the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
capitalize(str: string): string; | ||
/** | ||
* kebab-cases (dash-cases) the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
kebabCase(str: string): string; | ||
/** | ||
* lowercases the first character of the provided string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
lowerCaseFirst(str: string): string; | ||
/** | ||
* Removes all whitespace from a string. If the second argument is truthy, it will preserve spaces. | ||
* @param {string} str | ||
* @param {boolean} [preserveSpaces=false] | ||
* @returns {string} | ||
*/ | ||
removeWhitespace(str: string, preserveSpaces?: boolean): string; | ||
/** | ||
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces ( ). | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
trim(str: string): string; | ||
/** | ||
* Slices a string from a specific index or string expression. | ||
* @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; | ||
} |
@@ -0,2 +1,12 @@ | ||
/** | ||
* A class for performing simple operations on strings. | ||
*/ | ||
export class StringUtil { | ||
/** | ||
* 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) { | ||
@@ -15,2 +25,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* 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) { | ||
@@ -29,2 +46,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Returns all index matches of the provided Regular Expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {number[]} | ||
*/ | ||
allIndexesOf(regex, str, startingFrom = 0) { | ||
@@ -41,2 +65,9 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Returns all match objects of the provided regular expression on the provided string, optionally starting from a specific index. | ||
* @param {RegExp} regex | ||
* @param {string} str | ||
* @param {number} startingFrom | ||
* @returns {RegExpMatchArray[]} | ||
*/ | ||
allMatchObjectsOf(regex, str, startingFrom = 0) { | ||
@@ -53,5 +84,15 @@ if (startingFrom < 0 || startingFrom > str.length) | ||
} | ||
/** | ||
* Trims all of the provided strings. | ||
* @param {string[]} strings | ||
* @returns {string[]} | ||
*/ | ||
trimAll(strings) { | ||
return strings.map(str => str.trim()); | ||
return strings.map(str => this.trim(str)); | ||
} | ||
/** | ||
* camelCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
camelCase(str) { | ||
@@ -64,5 +105,23 @@ return this.lowerCaseFirst(str | ||
} | ||
/** | ||
* PascalCases the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
pascalCase(str) { | ||
return this.capitalize(this.camelCase(str)); | ||
} | ||
/** | ||
* Capitalizes the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
capitalize(str) { | ||
return str.slice(0, 1).toUpperCase() + str.slice(1); | ||
} | ||
/** | ||
* kebab-cases (dash-cases) the given string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
kebabCase(str) { | ||
@@ -75,6 +134,17 @@ // Lower cases the string | ||
} | ||
/** | ||
* lowercases the first character of the provided string. | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
lowerCaseFirst(str) { | ||
return str.slice(0, 1).toLowerCase() + str.slice(1); | ||
} | ||
removeWhitespace(str, preserveSpaces) { | ||
/** | ||
* Removes all whitespace from a string. If the second argument is truthy, it will preserve spaces. | ||
* @param {string} str | ||
* @param {boolean} [preserveSpaces=false] | ||
* @returns {string} | ||
*/ | ||
removeWhitespace(str, preserveSpaces = false) { | ||
// Convert tabs to spaces and remove anything but spaces. | ||
@@ -90,2 +160,7 @@ if (preserveSpaces) | ||
} | ||
/** | ||
* Trims a string. It works like String.prototype.trim, except it also handles HTML spaces ( ). | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
trim(str) { | ||
@@ -103,2 +178,8 @@ let local = str.trim(); | ||
} | ||
/** | ||
* Slices a string from a specific index or string expression. | ||
* @param {string} str | ||
* @param {number | string} from | ||
* @returns {string} | ||
*/ | ||
takeFrom(str, from) { | ||
@@ -108,2 +189,8 @@ const index = typeof from === "number" ? from : str.indexOf(from); | ||
} | ||
/** | ||
* Slices a string from after the string expression. | ||
* @param {string} str | ||
* @param {string} from | ||
* @returns {string} | ||
*/ | ||
takeFromAfter(str, from) { | ||
@@ -110,0 +197,0 @@ return this.takeFrom(str, from).slice(from.length); |
{ | ||
"name": "@wessberg/stringutil", | ||
"version": "1.0.0", | ||
"version": "1.0.3", | ||
"description": "A class for performing simple operations on strings.", | ||
@@ -10,2 +10,9 @@ "main": "./dist/cjs/index.js", | ||
"typings": "./dist/es2015/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wessberg/EventUtil.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/wessberg/EventUtil/issues" | ||
}, | ||
"scripts": { | ||
@@ -15,3 +22,3 @@ "clean:dist": "rm -r -f dist", | ||
"clean": "npm run clean:dist && npm run clean:compiled", | ||
"build:pre": "npm run clean && mkdir -p dist/cjs/interface && mkdir -p dist/es2015/interface", | ||
"build:pre": "npm run clean", | ||
"build:cjs": "tsc --module commonjs --outDir dist/cjs -p tsconfig.dist.json", | ||
@@ -21,3 +28,10 @@ "build:es2015": "tsc --module es2015 --outDir dist/es2015 -p tsconfig.dist.json", | ||
"test:pre": "npm run clean:compiled && tsc --module commonjs --target es2017 --sourceMap", | ||
"test": "NODE_ENV=TEST npm run test:pre && ava" | ||
"test": "NODE_ENV=TEST npm run test:pre && ava", | ||
"tslint": "tslint -c tslint.json -p tsconfig.json", | ||
"commit": "git add . && git commit -am ", | ||
"beforepublish": "npm run tslint && npm run build && npm run commit \"$npm_config_message)[@]\"", | ||
"publish": "npm run publish:patch", | ||
"publish:major": "npm run beforepublish && npm version major && && git push && npm publish", | ||
"publish:minor": "npm run beforepublish && npm version minor && && git push && npm publish", | ||
"publish:patch": "npm run beforepublish && npm version patch && git push && npm publish" | ||
}, | ||
@@ -34,3 +48,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"typescript": "2.3.3" | ||
"@wessberg/ts-config": "0.0.5", | ||
"tslint": "^5.5.0", | ||
"typescript": "2.4.1" | ||
}, | ||
@@ -37,0 +53,0 @@ "dependencies": { |
@@ -20,2 +20,6 @@ # StringUtil [![NPM version][npm-image]][npm-url] | ||
**v1.0.1**: | ||
- Added documentation. | ||
**v1.0.0**: | ||
@@ -22,0 +26,0 @@ |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
26014
630
29
0
3