mirror of
https://github.com/gabemart/hipku.git
synced 2025-01-18 12:05:35 +00:00
Better way to capitalize haiku
This commit is contained in:
parent
8768da7339
commit
cf65e8bdfd
27
dist/hipku.js
vendored
27
dist/hipku.js
vendored
@ -264,7 +264,7 @@ function writeHaiku(wordArray, ipv6) {
|
|||||||
/*
|
/*
|
||||||
** Capitalize appropriate words
|
** Capitalize appropriate words
|
||||||
*/
|
*/
|
||||||
schema = capitalizeHaiku(schema, nonWords);
|
schema = capitalizeHaiku(schema);
|
||||||
haiku = schema.join('');
|
haiku = schema.join('');
|
||||||
|
|
||||||
return haiku;
|
return haiku;
|
||||||
@ -351,7 +351,7 @@ function getSchema(ipv6, octet) {
|
|||||||
return [schema, nonWords];
|
return [schema, nonWords];
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalizeHaiku(haikuArray, nonWords) {
|
function capitalizeHaiku(haikuArray) {
|
||||||
var period = '.';
|
var period = '.';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -361,32 +361,13 @@ function capitalizeHaiku(haikuArray, nonWords) {
|
|||||||
|
|
||||||
for (var i = 1; i < haikuArray.length; i++) {
|
for (var i = 1; i < haikuArray.length; i++) {
|
||||||
|
|
||||||
if (haikuArray[i] === period) {
|
if (haikuArray[i] === period && i + 2 < haikuArray.length) {
|
||||||
var isWord;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the current entry is a period then the next entry will be
|
** If the current entry is a period then the next entry will be
|
||||||
** a newLine or a space, so check two positions ahead and
|
** a newLine or a space, so check two positions ahead and
|
||||||
** capitalize that entry, so long as it's a word
|
** capitalize that entry, so long as it's a word
|
||||||
*/
|
*/
|
||||||
|
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
|
||||||
isWord = true;
|
|
||||||
|
|
||||||
if (haikuArray[i + 2] === undefined ||
|
|
||||||
haikuArray[i + 2] === null ||
|
|
||||||
haikuArray[i + 2] === '') {
|
|
||||||
isWord = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var j = 0; j < nonWords.length; j++) {
|
|
||||||
if (haikuArray[i + 2] === nonWords[j]) {
|
|
||||||
isWord = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isWord) {
|
|
||||||
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
index.js
27
index.js
@ -264,7 +264,7 @@ function writeHaiku(wordArray, ipv6) {
|
|||||||
/*
|
/*
|
||||||
** Capitalize appropriate words
|
** Capitalize appropriate words
|
||||||
*/
|
*/
|
||||||
schema = capitalizeHaiku(schema, nonWords);
|
schema = capitalizeHaiku(schema);
|
||||||
haiku = schema.join('');
|
haiku = schema.join('');
|
||||||
|
|
||||||
return haiku;
|
return haiku;
|
||||||
@ -351,7 +351,7 @@ function getSchema(ipv6, octet) {
|
|||||||
return [schema, nonWords];
|
return [schema, nonWords];
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalizeHaiku(haikuArray, nonWords) {
|
function capitalizeHaiku(haikuArray) {
|
||||||
var period = '.';
|
var period = '.';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -361,32 +361,13 @@ function capitalizeHaiku(haikuArray, nonWords) {
|
|||||||
|
|
||||||
for (var i = 1; i < haikuArray.length; i++) {
|
for (var i = 1; i < haikuArray.length; i++) {
|
||||||
|
|
||||||
if (haikuArray[i] === period) {
|
if (haikuArray[i] === period && i + 2 < haikuArray.length) {
|
||||||
var isWord;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the current entry is a period then the next entry will be
|
** If the current entry is a period then the next entry will be
|
||||||
** a newLine or a space, so check two positions ahead and
|
** a newLine or a space, so check two positions ahead and
|
||||||
** capitalize that entry, so long as it's a word
|
** capitalize that entry, so long as it's a word
|
||||||
*/
|
*/
|
||||||
|
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
|
||||||
isWord = true;
|
|
||||||
|
|
||||||
if (haikuArray[i + 2] === undefined ||
|
|
||||||
haikuArray[i + 2] === null ||
|
|
||||||
haikuArray[i + 2] === '') {
|
|
||||||
isWord = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var j = 0; j < nonWords.length; j++) {
|
|
||||||
if (haikuArray[i + 2] === nonWords[j]) {
|
|
||||||
isWord = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isWord) {
|
|
||||||
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user