File tree Expand file tree Collapse file tree 3 files changed +805
-43
lines changed Expand file tree Collapse file tree 3 files changed +805
-43
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ var toString = require('nlcst-to-string');
2020 * Constants.
2121 */
2222
23- var ALL = / [ - ' ’ ] / g;
23+ var ALL = / [ - ' ] / g;
2424var DASH = / - / g;
2525var APOSTROPHE = / ’ / g;
2626var QUOTE = '\'' ;
@@ -30,18 +30,28 @@ var EMPTY = '';
3030 * Normalize `value`.
3131 *
3232 * @param {string } value - Value to normalize.
33- * @param {boolean } allowApostrophes - Do not strip
34- * apostrophes.
33+ * @param {Object? } options - Control stripping
34+ * apostrophes and dashes .
3535 * @return {string } - Normalized `value`.
3636 */
37- function normalize ( value , allowApostrophes ) {
37+ function normalize ( value , options ) {
38+ var settings = options || { } ;
39+ var allowApostrophes = settings . allowApostrophes ;
40+ var allowDashes = settings . allowDashes ;
3841 var result = ( typeof value === 'string' ? value : toString ( value ) )
39- . toLowerCase ( ) ;
42+ . toLowerCase ( )
43+ . replace ( APOSTROPHE , QUOTE ) ;
44+
45+ if ( allowApostrophes && allowDashes ) {
46+ return result ;
47+ }
4048
4149 if ( allowApostrophes ) {
42- return result
43- . replace ( APOSTROPHE , QUOTE )
44- . replace ( DASH , EMPTY ) ;
50+ return result . replace ( DASH , EMPTY ) ;
51+ }
52+
53+ if ( allowDashes ) {
54+ return result . replace ( QUOTE , EMPTY ) ;
4555 }
4656
4757 return result . replace ( ALL , EMPTY ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ normalize({
4444
4545## API
4646
47- ### ` normalize(value[, allowApostrophes ]) `
47+ ### ` normalize(value[, options ]) `
4848
4949Quote a value.
5050
@@ -53,8 +53,13 @@ Quote a value.
5353* ` value ` ([ ` Node ` ] [ nlcst-node ] , ` Array.<Node> ` , or ` string ` )
5454 — Value to normalize;
5555
56- * ` allowApostrophes ` (` boolean ` , default: ` false ` )
57- — Do not strip apostrophes (but do normalize them).
56+ * ` options ` (` Object? ` ):
57+
58+ * ` allowApostrophes ` (` boolean ` , default: ` false ` )
59+ — Do not strip apostrophes (` ' ` );
60+
61+ * ` allowDashes ` (` boolean ` , default: ` false ` )
62+ — Do not strip hyphens (` - ` ).
5863
5964** Returns** : ` string ` — Normalized value.
6065
You can’t perform that action at this time.
0 commit comments