Comparing version 0.0.1 to 0.0.2
@@ -14,8 +14,15 @@ (function() { | ||
module.exports = function(str, length) { | ||
var chars, di, found, i, j, k, l, len, len1, newWord, order, orderedCount, pos, ref, ref1, tri, unfinished, word, words; | ||
module.exports = function(str, arg) { | ||
var chars, di, found, i, j, k, keepSeparators, l, len, len1, length, newWord, order, orderedCount, pos, ref, ref1, sep, should, strict, tri, unfinished, word, words; | ||
length = arg.length, keepSeparators = arg.keepSeparators, strict = arg.strict; | ||
if (length == null) { | ||
length = 3; | ||
} | ||
if (length <= 0) { | ||
if (keepSeparators == null) { | ||
keepSeparators = false; | ||
} | ||
if (strict == null) { | ||
strict = true; | ||
} | ||
if (length <= 0 && strict) { | ||
return ""; | ||
@@ -36,2 +43,3 @@ } | ||
words = [1]; | ||
sep = 0; | ||
newWord = false; | ||
@@ -45,2 +53,3 @@ found; | ||
newWord = true; | ||
sep++; | ||
} else { | ||
@@ -98,12 +107,34 @@ if (newWord) { | ||
} | ||
pos = chars.length; | ||
i = chars.length; | ||
while (i > 0) { | ||
i--; | ||
if (words[i] === 0) { | ||
order[i] = pos; | ||
orderedCount++; | ||
pos--; | ||
if (!strict) { | ||
should = word; | ||
if (keepSeparators) { | ||
should += sep; | ||
} | ||
if (length < should) { | ||
length = should; | ||
} | ||
} | ||
if (keepSeparators) { | ||
i = 0; | ||
while (i < chars.length) { | ||
if (words[i] === 0) { | ||
order[i] = pos; | ||
orderedCount++; | ||
pos++; | ||
} | ||
i++; | ||
} | ||
pos = chars.length; | ||
} else { | ||
pos = chars.length; | ||
i = chars.length; | ||
while (i > 0) { | ||
i--; | ||
if (words[i] === 0) { | ||
order[i] = pos; | ||
orderedCount++; | ||
pos--; | ||
} | ||
} | ||
} | ||
j = 1; | ||
@@ -129,3 +160,2 @@ unfinished = true; | ||
} | ||
console.log(chars); | ||
chars = chars.map(function(val, i) { | ||
@@ -138,3 +168,2 @@ if (order[i] <= length) { | ||
}); | ||
console.log(order); | ||
return chars.join(""); | ||
@@ -141,0 +170,0 @@ }; |
{ | ||
"name": "abbreviate", | ||
"description": "abbreviate strings in style of R: Abbreviate", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/paulpflug/", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -16,3 +16,9 @@ # abbreviate | ||
abbreviate = require('abbreviate') | ||
abbr = abbreviate('Some Important String', 8) | ||
// abbreviate(string, opts) | ||
// opts: | ||
// length (default 3) | ||
// keepSeparators (default false) - keeps all separators between words | ||
// strict (default true) - if false, overwrites length to include all words | ||
abbr = abbreviate('Some Important String', {length: 8}) | ||
// abbr: 'SmImpStr' | ||
@@ -26,3 +32,3 @@ // which chars will be included for varying length? | ||
- trims the string | ||
- removes word separators (`/\s\-_,/`) | ||
- removes word separators (`/\s\-_,/`) (unless keepSeparators is true) | ||
- removes lowercase vocals | ||
@@ -34,8 +40,4 @@ - removes lowercase consonants | ||
## Release History | ||
- *v0.0.1*: First release | ||
## License | ||
Copyright (c) 2015 Paul Pflugradt | ||
Licensed under the MIT license. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12303
159
41