-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Showing
7 changed files
with
78 additions
and
16 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
# `string.camelToHyphen()` _(ext/string\_/camel-to-hyphen)_ | ||
|
||
Convert camelCase string to hyphen separated, e.g. `oneTwoThree` into `one-to-three`. Useful when converting names from js property convention into filename convention. | ||
|
||
```javascript | ||
const camelToHyphen = require("ext/string_/camelToHyphen"); | ||
|
||
camelToHyphen.call("razDwaTrzy"); // raz-dwa-trzy | ||
``` |
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,49 @@ | ||
"use strict"; | ||
|
||
var ensureString = require("type/string/ensure") | ||
, objHasOwnProperty = Object.prototype.hasOwnProperty; | ||
|
||
var capitalLetters = { | ||
A: true, | ||
B: true, | ||
C: true, | ||
D: true, | ||
E: true, | ||
F: true, | ||
G: true, | ||
H: true, | ||
I: true, | ||
J: true, | ||
K: true, | ||
L: true, | ||
M: true, | ||
N: true, | ||
O: true, | ||
P: true, | ||
Q: true, | ||
R: true, | ||
S: true, | ||
T: true, | ||
U: true, | ||
V: true, | ||
W: true, | ||
X: true, | ||
Y: true, | ||
Z: true | ||
}; | ||
|
||
module.exports = function () { | ||
var input = ensureString(this); | ||
if (!input) return input; | ||
var outputLetters = []; | ||
for (var index = 0, letter; (letter = input[index]); ++index) { | ||
if (objHasOwnProperty.call(capitalLetters, letter)) { | ||
if (index) outputLetters.push("-"); | ||
outputLetters.push(letter.toLowerCase()); | ||
} else { | ||
outputLetters.push(letter); | ||
} | ||
} | ||
|
||
return outputLetters.join(""); | ||
}; |
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,13 @@ | ||
"use strict"; | ||
|
||
var assert = require("chai").assert; | ||
|
||
var camelToHyphen = require("../../string_/camel-to-hyphen"); | ||
|
||
describe("string_/camel-to-hyphen", function () { | ||
it("should convert camel notation to hyphen", function () { | ||
assert.equal(camelToHyphen.call("razDwaTRzy4yFoo45My"), "raz-dwa-t-rzy4y-foo45-my"); | ||
assert.equal(camelToHyphen.call("razDwaTRzy4yFoo45My-"), "raz-dwa-t-rzy4y-foo45-my-"); | ||
assert.equal(camelToHyphen.call("razDwaTRzy4yFoo45My--"), "raz-dwa-t-rzy4y-foo45-my--"); | ||
}); | ||
}); |