-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ardalan Amini
committed
Jan 28, 2018
1 parent
e9240ba
commit 10751a2
Showing
12 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export { } | ||
|
||
declare global { | ||
interface String { | ||
chars(): Array<string> | ||
} | ||
} | ||
|
||
/** | ||
* Returns an array of the string's character | ||
* @memberof String | ||
* @returns {string[]} | ||
* @example | ||
* 'Hello'.chars(); // ['H', 'e', 'l', 'l', 'o'] | ||
*/ | ||
String.prototype.chars = function(): Array<string> { | ||
return this.split('') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require('../../../es6/string/chars') | ||
|
||
describe("String.prototype.chars", () => { | ||
test("'Hello'.chars() returns ['H', 'e', 'l', 'l', 'o']", () => { | ||
expect('Hello'.chars()) | ||
.toEqual(['H', 'e', 'l', 'l', 'o']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export { } | ||
|
||
declare global { | ||
interface String { | ||
humanize(): string | ||
} | ||
} | ||
|
||
/** | ||
* Converts an underscored, camelized, or dasherized string into a humanized one. Also removes beginning and ending whitespace | ||
* @memberof String | ||
* @returns {string} | ||
* @example | ||
* ' capitalize dash-CamelCase_underscore trim '.humanize(); // 'Capitalize dash camel case underscore trim' | ||
*/ | ||
String.prototype.humanize = function(): string { | ||
let s = this.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) || [''] | ||
|
||
return s.map(x => x.toLowerCase()).join(' ').replace(/^[a-z]/, (char) => char.toUpperCase()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require('../../../es6/string/humanize') | ||
|
||
describe("String.prototype.humanize", () => { | ||
test("' capitalize dash-CamelCase_underscore trim '.humanize() returns 'Capitalize dash camel case underscore trim'", () => { | ||
expect(' capitalize dash-CamelCase_underscore trim '.humanize()) | ||
.toBe('Capitalize dash camel case underscore trim') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export { } | ||
|
||
declare global { | ||
interface String { | ||
swapCase(): string | ||
} | ||
} | ||
|
||
/** | ||
* Returns a copy of the string in which all the case-based characters have had their case swapped | ||
* @memberof String | ||
* @returns {string} | ||
* @example | ||
* 'Hello'.swapCase(); // 'hELLO' | ||
*/ | ||
String.prototype.swapCase = function(): string { | ||
return this.replace(/\S/g, (c) => c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require('../../../es6/string/swapCase') | ||
|
||
describe("String.prototype.swapCase", () => { | ||
test("'Hello'.swapCase() returns 'hELLO'", () => { | ||
expect('Hello'.swapCase()) | ||
.toBe('hELLO') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "prototyped.js", | ||
"version": "0.3.2", | ||
"description": "Common typescript ready prototypes available in both es6 and es5", | ||
"version": "0.4.0", | ||
"description": "Common typescript ready prototypes available in both es5 and es6", | ||
"author": "Ardalan Amini <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/ardalanamini/prototyped.js#readme", | ||
|
@@ -66,6 +66,9 @@ | |
"defer", | ||
"cache", | ||
"string", | ||
"chars", | ||
"humanize", | ||
"swapCase", | ||
"capitalize", | ||
"decapitalize", | ||
"mask", | ||
|