Comparing version
@@ -6,6 +6,6 @@ #!/usr/bin/env node | ||
var util = require("util"), | ||
isNullOrUndefined = util.isNullOrUndefined, | ||
isNumber = util.isNumber, | ||
isArray = util.isArray, | ||
isString = util.isString; | ||
isNullOrUndefined = util.isNullOrUndefined, | ||
isNumber = util.isNumber, | ||
isArray = util.isArray, | ||
isString = util.isString; | ||
@@ -275,2 +275,3 @@ var utils = require("../utils"); | ||
for (var i = _startCount; i < _endCount; i++) { | ||
@@ -317,23 +318,12 @@ | ||
var smartCount = function(_string, _subString, _startCount, _endCount){ | ||
var _char_startnumber, | ||
_char_endnumber; | ||
if(_startCount && !isDigit(_startCount) && !isNumber(_startCount)){ | ||
var c = utils._parse_char(_startCount), | ||
r = utils._find_letter_position(_string, c); | ||
var _parse_startCount = utils._parse_char(_startCount), | ||
_char_startnumber = _parse_startCount.charNumber, | ||
_char_start = _parse_startCount.char, | ||
n = 0, | ||
_n; | ||
if (c.charNumber > r.c) return 0; | ||
_char_startnumber = r.r; | ||
for (var i = 0; i < _string.length; i++) { | ||
if (_string[i] == _char_start){ | ||
n++; | ||
if (n == _char_startnumber){ | ||
_n = i; | ||
break; | ||
} | ||
} | ||
} | ||
if(_char_startnumber > n) return 0; | ||
_char_startnumber = _n; | ||
}else if(isDigit(_startCount) || isNumber(_startCount)){ | ||
@@ -346,19 +336,7 @@ _char_startnumber = _startCount; | ||
if(_endCount && !isDigit(_endCount) && !isNumber(_endCount)){ | ||
var _parse_endCount = utils._parse_char(_endCount), | ||
_char_endnumber = _parse_endCount.charNumber, | ||
_char_end = _parse_endCount.char, | ||
n = 0, | ||
_n; | ||
var c = utils._parse_char(_endCount), | ||
r = utils._find_letter_position(_string, c); | ||
for (var i = 0; i < _string.length; i++) { | ||
if (_string[i] == _char_end){ | ||
n++; | ||
if (n == _char_endnumber){ | ||
_n = i; | ||
break; | ||
} | ||
} | ||
} | ||
if(_char_endnumber > n) return 0; | ||
_char_endnumber = _n; | ||
if (c.charNumber > r.c) return 0; | ||
_char_endnumber = r.r; | ||
@@ -1119,2 +1097,2 @@ }else if(isDigit(_endCount) || isNumber(_endCount)){ | ||
}; | ||
exports.rJust = rJust; | ||
exports.rJust = rJust; |
@@ -32,2 +32,31 @@ var util = require("util"), | ||
} | ||
exports._parse_char = _parse_char; | ||
exports._parse_char = _parse_char; | ||
/* | ||
* Shall find the correct letter position in the string | ||
* based on the object that the _parse_char function returns. | ||
* | ||
* @param {string} simple string. | ||
* @param {object} object returned from _parse_char function. | ||
* @return {object}. | ||
* @private | ||
*/ | ||
function _find_letter_position(_string, object){ | ||
var n = 0, | ||
r; | ||
for (var i = 0; i < _string.length; i++) { | ||
if (_string[i] == object.char){ | ||
n++; | ||
if(n == object.charNumber){ | ||
r = i; | ||
break; | ||
} | ||
} | ||
} | ||
return { | ||
"r": r, | ||
"n": n | ||
}; | ||
} | ||
exports._find_letter_position = _find_letter_position; |
{ | ||
"name": "l-string", | ||
"version": "1.0.41", | ||
"version": "1.0.42", | ||
"description": "this is a module that you can use to manipulate strings ... ", | ||
@@ -11,3 +11,3 @@ "main": "./l-string.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.11.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "bugs": { |
@@ -111,2 +111,7 @@ **l-string** :thumbsup: :trollface: [](https://travis-ci.org/leoxnidas/l-string) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BQKLKSBKH4DPE) | ||
Version 1.0.42. | ||
--------------- | ||
- fixed issues in smartCount function. | ||
- new private function added, called _find_letter_position | ||
Version 1.0.41. | ||
@@ -113,0 +118,0 @@ --------------- |
@@ -43,5 +43,6 @@ #!/usr/bin/env node | ||
console.log("leo".slugify()) | ||
console.log("leoanrdo esparis, leonardo esparis".smartCount("leo", "l1", 20)) | ||
console.log("leoanrdo esparis, leonardo esparis".smartCount("leo", "l1", "1o")) | ||
console.log("<h1>\"\'<>&leonardo</h1>".escape()) | ||
@@ -54,1 +55,3 @@ console.log("<h1>leo</h1>".removeTag()) | ||
console.log(d.addIdName2Tag("h12", "pepe").addAttr2Tag("h13", "data-city2", "algo2").addIdName2Tag("h12", "pep22e")) | ||
53838
1.02%1475
0.55%213
2.4%