nlcst-normalize
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,8 @@ <!--remark setext--> | ||
1.1.0 / 2016-01-18 | ||
================== | ||
* Add support for `allowApostrophes` ([9f169d5](https://github.com/wooorm/nlcst-normalize/commit/9f169d5)) | ||
1.0.0 / 2016-01-14 | ||
================== |
22
index.js
@@ -23,3 +23,6 @@ /** | ||
var EXPRESSION_REMOVE = /['’-]/g; | ||
var ALL = /[-'’]/g; | ||
var DASH = /-/g; | ||
var APOSTROPHE = /’/g; | ||
var QUOTE = '\''; | ||
var EMPTY = ''; | ||
@@ -31,8 +34,17 @@ | ||
* @param {string} value - Value to normalize. | ||
* @param {boolean} allowApostrophes - Do not strip | ||
* apostrophes. | ||
* @return {string} - Normalized `value`. | ||
*/ | ||
function normalize(value) { | ||
return (typeof value === 'string' ? value : toString(value)) | ||
.toLowerCase() | ||
.replace(EXPRESSION_REMOVE, EMPTY); | ||
function normalize(value, allowApostrophes) { | ||
var result = (typeof value === 'string' ? value : toString(value)) | ||
.toLowerCase(); | ||
if (allowApostrophes) { | ||
return result | ||
.replace(APOSTROPHE, QUOTE) | ||
.replace(DASH, EMPTY); | ||
} | ||
return result.replace(ALL, EMPTY); | ||
} | ||
@@ -39,0 +51,0 @@ |
{ | ||
"name": "nlcst-normalize", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Normalize a word for easier comparison", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,2 +24,3 @@ # nlcst-normalize [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
normalize('Block-level'); // 'blocklevel' | ||
normalize('Don’t', true); // 'don\'t' | ||
@@ -47,3 +48,3 @@ normalize({ | ||
### `normalize(value)` | ||
### `normalize(value[, allowApostrophes])` | ||
@@ -55,4 +56,7 @@ Quote a value. | ||
* `value` ([`Node`][nlcst-node], `Array.<Node>`, or `string`) | ||
— Value to normalize. | ||
— Value to normalize; | ||
* `allowApostrophes` (`boolean`, default: `false`) | ||
— Do not strip apostrophes (but do normalize them). | ||
**Returns**: `string` — Normalized value. | ||
@@ -59,0 +63,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5798
43
88