contractions
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -14,3 +14,9 @@ 'use strict'; | ||
keys = Object.keys(this._expandLookup); | ||
keys.sort(function(a, b){ return b.length - a.length; }); | ||
keys.sort((a, b) => { | ||
var diff = b.length - a.length; | ||
if (diff !== 0) diff = this._expandLookup[b].length - this._expandLookup[a].length; | ||
return diff; | ||
}); | ||
this._expandRegexp = new RegExp(keys.join('|'), 'gi'); | ||
@@ -27,3 +33,9 @@ | ||
keys = Object.keys(this._contractLookup); | ||
keys.sort(function(a, b){ return b.length - a.length; }); | ||
keys.sort((a, b) => { | ||
var diff = b.length - a.length; | ||
if (diff !== 0) diff = this._contractLookup[b].length - this._contractLookup[a].length; | ||
return diff; | ||
}); | ||
this._contractRegexp = new RegExp(keys.join('|'), 'gi'); | ||
@@ -30,0 +42,0 @@ |
{ | ||
"name": "contractions", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"licenses": [ | ||
@@ -5,0 +5,0 @@ { |
@@ -17,9 +17,33 @@ Contractions | ||
````javascript | ||
var Contractions = require('contractions'); | ||
var contractions = require('contractions'); | ||
console.log(Contractions.expand("I don't know who ya'll are.")); | ||
console.log(contractions.expand("I don't know who ya'll are.")); | ||
// Outputs: I do not know who you all are. | ||
console.log(Contractions.contract("You all will have not seen this.")); | ||
console.log(contractions.contract("You all will have not seen this.")); | ||
// Outputs: Y'all'll'ven't seen this. | ||
```` | ||
You can also use your own list of contractions / strings. | ||
Note: Longer strings take precedent over short strings. | ||
````javascript | ||
var Contractions = require('contractions').Contractions; | ||
var contractions = new Contractions({ | ||
'asap': 'as soon as possible', // only lower case characters should be used in the list | ||
'a.s.a.p.': 'as soon as possible' | ||
}); | ||
var text = 'asap'; | ||
text = contractions.expand(text); | ||
console.log(text); | ||
// Outputs: as soon as possible | ||
text = contractions.contract(text); | ||
console.log(text); | ||
// Outputs: a.s.a.p. | ||
```` |
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
7790
193
49