Comparing version 1.0.0 to 1.1.0
@@ -26,2 +26,5 @@ 'use strict'; | ||
* // => 'sun' | ||
* | ||
* v.decapitalize('moon'); | ||
* // => 'moon' | ||
*/ | ||
@@ -28,0 +31,0 @@ function decapitalize(subject) { |
@@ -84,2 +84,10 @@ 'use strict'; | ||
/** | ||
* Regular expression to match whitespaces | ||
* | ||
* @type {RegExp} | ||
* @ignore | ||
*/ | ||
var REGEXP_WHITESPACE = exports.REGEXP_WHITESPACE = new RegExp('[' + whitespace + ']'); | ||
/** | ||
* Regular expression to match whitespaces from the left side | ||
@@ -154,2 +162,12 @@ * | ||
*/ | ||
var REGEXP_FLAGS = exports.REGEXP_FLAGS = /[gimuy]*$/; | ||
var REGEXP_FLAGS = exports.REGEXP_FLAGS = /[gimuy]*$/; | ||
/** | ||
* Regular expression to match a list of tags. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-name | ||
* @type {RegExp} | ||
* @ignore | ||
*/ | ||
var REGEXP_TAG_LIST = exports.REGEXP_TAG_LIST = /<([A-Za-z0-9]+)>/g; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.getLatinCharacter = getLatinCharacter; | ||
/** | ||
@@ -126,14 +127,35 @@ * Generated diacritics map. See bellow the base code. | ||
var diacriticsMap = {}; | ||
var index = void 0; | ||
var diacriticsMap = null; | ||
Object.keys(diacritics).forEach(function (key) { | ||
var characters = diacritics[key]; | ||
for (index = 0; index < characters.length; index++) { | ||
var character = characters[index]; | ||
diacriticsMap[character] = key; | ||
/** | ||
* Creates a map of the diacritics. | ||
* | ||
* @ignore | ||
* @returns {Object} Returns the diacritics map. | ||
*/ | ||
function getDiacriticsMap() { | ||
if (diacriticsMap !== null) { | ||
return diacriticsMap; | ||
} | ||
}); | ||
diacriticsMap = {}; | ||
Object.keys(diacritics).forEach(function (key) { | ||
var characters = diacritics[key]; | ||
for (var index = 0; index < characters.length; index++) { | ||
var character = characters[index]; | ||
diacriticsMap[character] = key; | ||
} | ||
}); | ||
return diacriticsMap; | ||
} | ||
exports.default = diacriticsMap; | ||
module.exports = exports["default"]; | ||
/** | ||
* Get the latin character from character with diacritics. | ||
* | ||
* @ignore | ||
* @param {string} character The character with diacritics. | ||
* @returns {string} Returns the character without diacritics. | ||
*/ | ||
function getLatinCharacter(character) { | ||
var characterWithoutDiacritic = getDiacriticsMap()[character]; | ||
return characterWithoutDiacritic ? characterWithoutDiacritic : character; | ||
} |
@@ -29,2 +29,5 @@ 'use strict'; | ||
* // => false | ||
* | ||
* v.isEmpty('sun'); | ||
* // => false | ||
*/ | ||
@@ -31,0 +34,0 @@ function isEmpty(subject) { |
@@ -30,3 +30,6 @@ 'use strict'; | ||
* | ||
* v.isNumeric('NaN'); | ||
* v.isNumeric('1.5E+2'); | ||
* // => true | ||
* | ||
* v.isNumeric('five'); | ||
* // => false | ||
@@ -33,0 +36,0 @@ */ |
@@ -16,21 +16,8 @@ 'use strict'; | ||
var _diacritics_map2 = _interopRequireDefault(_diacritics_map); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Removes the diacritics from `character`. | ||
* Returns the `cleanCharacter` from combining marks regular expression match. | ||
* | ||
* @ignore | ||
* @param {string} character The character with diacritics. | ||
* @returns {string} Returns the character without diacritics. | ||
*/ | ||
function removeDiacritics(character) { | ||
var characterWithoutDiacritic = _diacritics_map2.default[character]; | ||
return characterWithoutDiacritic ? characterWithoutDiacritic : character; | ||
} | ||
/** | ||
* Returns the `cleanCharacter` from combining marks regular expression match. | ||
* @ignore | ||
* @param {string} character The character with combining marks | ||
@@ -68,4 +55,4 @@ * @param {string} cleanCharacter The character without combining marks. | ||
} | ||
return subjectString.replace(_const.REGEXP_NON_LATIN, removeDiacritics).replace(_const.REGEXP_COMBINING_MARKS, removeCombiningMarks); | ||
return subjectString.replace(_const.REGEXP_NON_LATIN, _diacritics_map.getLatinCharacter).replace(_const.REGEXP_COMBINING_MARKS, removeCombiningMarks); | ||
} | ||
module.exports = exports['default']; |
@@ -26,2 +26,5 @@ 'use strict'; | ||
* // => 'green' | ||
* | ||
* v.lowerCase('BLUE'); | ||
* // => 'blue' | ||
*/ | ||
@@ -28,0 +31,0 @@ function lowerCase(subject) { |
{ | ||
"name": "voca", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "The ultimate JavaScript string library", | ||
@@ -23,3 +23,4 @@ "homepage": "https://vocajs.com", | ||
"wrap", | ||
"case" | ||
"case", | ||
"strip" | ||
], | ||
@@ -38,30 +39,26 @@ "repository": { | ||
"eslint": "eslint . --ext .js", | ||
"build": "npm run build-dist && npm run build-npm-package", | ||
"build-dist": "rollup -c config/rollup_dist.js && rollup -c config/rollup_dist_min.js && rollup -c config/rollup_test.js", | ||
"build-npm-package": "npm run prepare-npm-package && rollup -c config/rollup_dist_mod.js && node config/transform.js && rollup -c config/rollup_dist_es.js", | ||
"prepare-npm-package": "rm -rf dist_mod && mkdir dist_mod && cp package.json README.md LICENSE.md ./dist_mod", | ||
"build-dist": "rollup -c config/rollup_dist.js && rollup -c config/rollup_dist_min.js && rollup -c config/rollup_test.js", | ||
"build-npm-package": "npm run prepare-npm-package && rollup -c config/rollup_dist_mod.js && node config/transform.js && rollup -c config/rollup_dist_es.js", | ||
"prepare-npm-package": "rm -rf dist_mod && mkdir dist_mod && cp package.json README.md LICENSE.md ./dist_mod", | ||
"test": "mocha test/index.js --reporter dot", | ||
"test-npm-package": "mocha test/modules_common.js test/modules_es2015.js --reporter dot", | ||
"test-sl": "grunt --gruntfile ./test_runner/gruntfile.js --base .", | ||
"coverage": "istanbul cover _mocha -- test/index.js --reporter spec", | ||
"report-coverage": "cat ./coverage/lcov.info | codecov", | ||
"verify": "npm run eslint && npm run coverage", | ||
"jsdoc": "jsdoc --configure .jsdoc.json", | ||
"deploy": "rollup -c config/rollup_dist.js && cp dist/voca.js docs/scripts && scp -r docs/* rainishere:/home/rainishere/webapps/voca_docs" | ||
"deploy": "rollup -c config/rollup_dist.js && cp dist/voca.js docs/scripts && scp -r docs/* rainishere:/home/rainishere/webapps/voca_docs", | ||
"precommit": "npm run eslint && npm run test" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.18.0", | ||
"babel-core": "6.20.0", | ||
"babel-core": "6.21.0", | ||
"babel-eslint": "7.1.1", | ||
"babel-plugin-add-module-exports": "0.2.1", | ||
"babel-plugin-module-resolver": "2.4.0", | ||
"babel-plugin-transform-es2015-block-scoping": "6.20.0", | ||
"babel-plugin-transform-es2015-block-scoping": "6.21.0", | ||
"babel-plugin-transform-es2015-destructuring": "6.19.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.18.0", | ||
"babel-plugin-transform-es2015-parameters": "6.18.0", | ||
"babel-plugin-transform-es2015-parameters": "6.21.0", | ||
"babel-plugin-transform-es2015-shorthand-properties": "6.18.0", | ||
@@ -74,4 +71,3 @@ "babel-plugin-transform-es2015-spread": "6.8.0", | ||
"codecov.io": "0.1.6", | ||
"eslint": "3.12.0", | ||
"ghooks": "1.3.2", | ||
"eslint": "3.12.2", | ||
"glob": "7.1.1", | ||
@@ -81,2 +77,3 @@ "grunt": "1.0.1", | ||
"grunt-saucelabs": "9.0.0", | ||
"husky": "0.12.0", | ||
"istanbul": "1.1.0-alpha.1", | ||
@@ -86,13 +83,8 @@ "jsdoc": "3.4.3", | ||
"mocha": "3.2.0", | ||
"rollup": "0.36.4", | ||
"rollup-plugin-babel": "2.6.1", | ||
"rollup": "0.38.0", | ||
"rollup-plugin-babel": "2.7.1", | ||
"rollup-plugin-uglify": "1.0.1", | ||
"source-map-support": "0.4.6" | ||
"source-map-support": "0.4.8" | ||
}, | ||
"dependencies": {}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run eslint && npm run test" | ||
} | ||
} | ||
} | ||
"dependencies": {} | ||
} |
@@ -48,3 +48,3 @@ 'use strict'; | ||
* v.padLeft('bird', 6, '-'); | ||
* // => '--bird-' | ||
* // => '--bird' | ||
* | ||
@@ -51,0 +51,0 @@ * v.padLeft('cat', 6, '-='); |
@@ -5,3 +5,2 @@ # [![Voca JavaScript library logo][logo]][voca] | ||
[](https://codecov.io/github/panzerdp/voca) | ||
[](https://david-dm.org/panzerdp/voca) | ||
[](https://www.npmjs.com/package/voca) | ||
@@ -17,3 +16,3 @@ | ||
The Voca library offers helpful functions to make string manipulations comfortable: *change case, trim, pad, slugifly, | ||
The Voca library offers helpful functions to make string manipulations comfortable: *change case, trim, pad, slugify, | ||
latinise, sprintf'y, truncate, escape* and much more. The *modular design* allows to load the entire library, or | ||
@@ -61,3 +60,3 @@ individual functions to minimize the application builds. The library is *fully tested*, *well documented* and *long-term supported*. | ||
words('welcome to Earth'); // => ['welcome', 'to', 'Earth'] | ||
slugify('café latté'); // => 'caffe-latte' | ||
slugify('caffé latté'); // => 'caffe-latte' | ||
``` | ||
@@ -82,3 +81,3 @@ | ||
<script type="text/javascript"> | ||
v.last('wonderful world', 4); // => 'world' | ||
v.last('wonderful world', 5); // => 'world' | ||
</script> | ||
@@ -108,4 +107,3 @@ ``` | ||
 | ||
[Dmitri Pavlutin](https://rainsoft.io/about-me/) | ||
[Dmitri Pavlutin](https://rainsoft.io/about-me/) | ||
[@panzerdp](https://twitter.com/panzerdp) | ||
@@ -120,5 +118,5 @@ [dmitri@rainsoft.io](mailto:dmitri@rainsoft.io) | ||
[CONTRIBUTING]: https://github.com/panzerdp/voca/blob/master/.github/CONTRIBUTING.md | ||
[voca_min_js]: https://raw.githubusercontent.com/panzerdp/voca/1.0.0/dist/voca.min.js | ||
[source_map]: https://raw.githubusercontent.com/panzerdp/voca/1.0.0/dist/voca.min.js.map | ||
[voca_js]: https://raw.githubusercontent.com/panzerdp/voca/1.0.0/dist/voca.js | ||
[voca_min_js]: https://raw.githubusercontent.com/panzerdp/voca/1.1.0/dist/voca.min.js | ||
[source_map]: https://raw.githubusercontent.com/panzerdp/voca/1.1.0/dist/voca.min.js.map | ||
[voca_js]: https://raw.githubusercontent.com/panzerdp/voca/1.1.0/dist/voca.js | ||
[voca]: https://vocajs.com | ||
@@ -200,2 +198,4 @@ [logo]: https://github.com/panzerdp/voca/raw/master/jsdoc/template/static/images/voca-logo@300px.png | ||
[split]: https://vocajs.com/#split | ||
[words]: https://vocajs.com/#words | ||
[words]: https://vocajs.com/#words | ||
[stripTags]: https://vocajs.com/#stripTags |
@@ -37,3 +37,3 @@ 'use strict'; | ||
* // => 'g**d m*rning' | ||
* v.replaceAll('evening', \n\, 's'); | ||
* v.replaceAll('evening', /n/, 's'); | ||
* // => 'evesisg' | ||
@@ -40,0 +40,0 @@ * |
@@ -37,3 +37,3 @@ 'use strict'; | ||
* | ||
* v.slugify('café latté'); | ||
* v.slugify('caffé latté'); | ||
* // => 'caffe-latte' | ||
@@ -40,0 +40,0 @@ * |
@@ -25,3 +25,3 @@ 'use strict'; | ||
/** | ||
* Removes whitespaces from the left part of the `subject`. | ||
* Removes whitespaces from the left side of the `subject`. | ||
* | ||
@@ -51,3 +51,3 @@ * @function trimLeft | ||
} | ||
var whitespaceStringLength = whitespaceString.length; | ||
var whitespaceLength = whitespaceString.length; | ||
var matchWhitespace = true; | ||
@@ -57,3 +57,3 @@ var totalWhitespaceLength = 0; | ||
if (subjectString.indexOf(whitespaceString, totalWhitespaceLength) === totalWhitespaceLength) { | ||
totalWhitespaceLength += whitespaceStringLength; | ||
totalWhitespaceLength += whitespaceLength; | ||
} else { | ||
@@ -60,0 +60,0 @@ matchWhitespace = false; |
@@ -25,3 +25,3 @@ 'use strict'; | ||
/** | ||
* Removes whitespaces from the right part of the `subject`. | ||
* Removes whitespaces from the right side of the `subject`. | ||
* | ||
@@ -51,4 +51,4 @@ * @function trimRight | ||
} | ||
var whitespaceStringLength = whitespaceString.length; | ||
var valueStringLength = subjectString.length; | ||
var whitespaceLength = whitespaceString.length; | ||
var subjectLength = subjectString.length; | ||
var matchWhitespace = true; | ||
@@ -58,5 +58,5 @@ var totalWhitespaceLength = 0; | ||
while (matchWhitespace) { | ||
position = valueStringLength - totalWhitespaceLength - whitespaceStringLength; | ||
position = subjectLength - totalWhitespaceLength - whitespaceLength; | ||
if (subjectString.indexOf(whitespaceString, position) === position) { | ||
totalWhitespaceLength += whitespaceStringLength; | ||
totalWhitespaceLength += whitespaceLength; | ||
} else { | ||
@@ -66,4 +66,4 @@ matchWhitespace = false; | ||
} | ||
return subjectString.substring(0, valueStringLength - totalWhitespaceLength); | ||
return subjectString.substring(0, subjectLength - totalWhitespaceLength); | ||
} | ||
module.exports = exports['default']; |
@@ -31,3 +31,3 @@ 'use strict'; | ||
/** | ||
* Removes whitespaces from left and right parts of the `subject`. | ||
* Removes whitespaces from left and right sides of the `subject`. | ||
* | ||
@@ -34,0 +34,0 @@ * @function trim |
@@ -15,7 +15,7 @@ 'use strict'; | ||
* v.version | ||
* // => '1.0.0' | ||
* // => '1.1.0' | ||
*/ | ||
var version = '1.0.0'; | ||
var version = '1.1.0'; | ||
exports.default = version; | ||
module.exports = exports['default']; |
@@ -29,5 +29,5 @@ 'use strict'; | ||
* @memberOf Format | ||
* @param {string} [format=''] The format string. | ||
* @param {Array.<number|string>} replacements The array of replacements to produce the string. | ||
* @return {string} Returns the produced string. | ||
* @param {string} format=''] The format string. | ||
* @param {Array} replacements The array of replacements to produce the string. | ||
* @return {string} Returns the produced string. | ||
* @example | ||
@@ -34,0 +34,0 @@ * v.vprintf('%s', ['Welcome']) |
@@ -20,6 +20,2 @@ 'use strict'; | ||
var _nil_default = require('./helper/undefined/nil_default'); | ||
var _nil_default2 = _interopRequireDefault(_nil_default); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -33,2 +29,18 @@ | ||
/** | ||
* Determine the word wrap options. The missing values are filled with defaults. | ||
* | ||
* @param {Object} options The options object. | ||
* @return {Object} The word wrap options, with default settings if necessary. | ||
* @ignore | ||
*/ | ||
function determineOptions(options) { | ||
return { | ||
width: (0, _coerce_to_number2.default)(options[OPTION_WIDTH], 75), | ||
newLine: (0, _coerce_to_string2.default)(options[OPTION_NEW_LINE], '\n'), | ||
indent: (0, _coerce_to_string2.default)(options[OPTION_INDENT], ''), | ||
cut: (0, _coerce_to_boolean2.default)(options[OPTION_CUT], false) | ||
}; | ||
} | ||
/** | ||
* Wraps `subject` to a given number of characters using a string break character. | ||
@@ -69,18 +81,20 @@ * | ||
*/ | ||
function wordWrap(subject, options) { | ||
function wordWrap(subject) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var subjectString = (0, _coerce_to_string2.default)(subject); | ||
options = (0, _nil_default2.default)(options, {}); | ||
var width = (0, _coerce_to_number2.default)(options[OPTION_WIDTH], 75); | ||
var newLine = (0, _coerce_to_string2.default)(options[OPTION_NEW_LINE], '\n'); | ||
var indent = (0, _coerce_to_string2.default)(options[OPTION_INDENT], ''); | ||
var cut = (0, _coerce_to_boolean2.default)(options[OPTION_CUT], false); | ||
var _determineOptions = determineOptions(options), | ||
width = _determineOptions.width, | ||
newLine = _determineOptions.newLine, | ||
indent = _determineOptions.indent, | ||
cut = _determineOptions.cut; | ||
if (subjectString === '' || width <= 0) { | ||
return indent; | ||
} | ||
var subjectLength = subjectString.length; | ||
var substring = subjectString.substring.bind(subjectString); | ||
var offset = 0; | ||
var wrappedLine = ''; | ||
while (subjectLength - offset > width) { | ||
@@ -93,7 +107,7 @@ if (subjectString[offset] === ' ') { | ||
if (spaceToWrapAt >= offset) { | ||
wrappedLine += indent + subjectString.substring(offset, spaceToWrapAt) + newLine; | ||
wrappedLine += indent + substring(offset, spaceToWrapAt) + newLine; | ||
offset = spaceToWrapAt + 1; | ||
} else { | ||
if (cut) { | ||
wrappedLine += indent + subjectString.substring(offset, width + offset) + newLine; | ||
wrappedLine += indent + substring(offset, width + offset) + newLine; | ||
offset += width; | ||
@@ -103,6 +117,6 @@ } else { | ||
if (spaceToWrapAt >= 0) { | ||
wrappedLine += indent + subjectString.substring(offset, spaceToWrapAt) + newLine; | ||
wrappedLine += indent + substring(offset, spaceToWrapAt) + newLine; | ||
offset = spaceToWrapAt + 1; | ||
} else { | ||
wrappedLine += indent + subjectString.substring(offset); | ||
wrappedLine += indent + substring(offset); | ||
offset = subjectLength; | ||
@@ -114,3 +128,3 @@ } | ||
if (offset < subjectLength) { | ||
wrappedLine += indent + subjectString.substring(offset); | ||
wrappedLine += indent + substring(offset); | ||
} | ||
@@ -117,0 +131,0 @@ return wrappedLine; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
406464
105
11511
30