Skip to content

Commit ade0844

Browse files
revise S.capitalize
1 parent b991da4 commit ade0844

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

scriptum.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ A.splitAt = p => xs => {
20512051
};
20522052

20532053

2054-
A.tuplewise = ({size, padding = null, overlap = false}) => xs => {
2054+
A.ngram = ({size, padding = null, overlap = false}) => xs => {
20552055
const ys = [];
20562056

20572057
for (let i = 0; i < xs.length; overlap ? i++ : i += size) {
@@ -2071,10 +2071,10 @@ A.tuplewise = ({size, padding = null, overlap = false}) => xs => {
20712071
};
20722072

20732073

2074-
A.bigram = A.tuplewise({size: 2, overlap: true});
2074+
A.bigram = A.ngram({size: 2, overlap: true});
20752075

20762076

2077-
A.trigram = A.tuplewise({size: 3, overlap: true});
2077+
A.trigram = A.ngram({size: 3, overlap: true});
20782078

20792079

20802080
//█████ Combinations, Subsets, Subsequences ███████████████████████████████████
@@ -9321,7 +9321,7 @@ S.splitAscii = s => {
93219321

93229322
S.splitName = s => {
93239323

9324-
// aslo split edge case "A.B. Foo" to ["A.", "B.", "Foo"]
9324+
// aslo split edge case "A.B.Foo" to ["A.", "B.", "Foo"]
93259325

93269326
if (/,/.test(s)) {
93279327
const [lastName, firstName] = s.split(/, +/),
@@ -11369,34 +11369,12 @@ S.Ctor.cmpWith = opt => (o, p) =>
1136911369

1137011370
// capitalize a word and its potential word components
1137111371

11372-
S.capitalize = word => {
11373-
const xs = word.split("-");
11372+
S.capitalize = nouns => {
11373+
const lowercasedName = nouns.toLowerCase();
1137411374

11375-
for (let i = 0; i < xs.length; i++) {
11376-
if (xs[i] === "") continue;
11377-
else if (xs[i - 1] === "") xs[i] = xs[i].toLowerCase();
11378-
else xs[i] = xs[i] [0].toUpperCase() + xs[i].slice(1).toLowerCase();
11379-
11380-
const ys = xs[i].split(".");
11381-
11382-
for (let i2 = 0; i2 < ys.length; i2++) {
11383-
if (ys[i2] === "") continue;
11384-
ys[i2] = ys[i2] [0].toUpperCase() + ys[i2].slice(1);
11385-
}
11386-
11387-
xs[i] = ys.join(".");
11388-
11389-
if (/\p{L}+'\p{L}{2,}/v.test(xs[i])) {
11390-
const zs = xs[i].split("'");
11391-
11392-
for (let i2 = 0; i2 < zs.length; i2++)
11393-
zs[i2] = zs[i2] [0].toUpperCase() + zs[i2].slice(1);
11394-
11395-
xs[i] = zs.join("'");
11396-
}
11397-
}
11398-
11399-
return xs.join("-");
11375+
return lowercasedName.replace(/(^|[\s'-\.])(\w)/g, (match, separator, char) => {
11376+
return separator + char.toUpperCase();
11377+
});
1140011378
};
1140111379

1140211380

0 commit comments

Comments
 (0)