node-stringprep
Advanced tools
Comparing version 0.2.2 to 0.2.3
19
index.js
@@ -33,3 +33,6 @@ 'use strict'; | ||
StringPrep.prototype.UNHANDLED_FALLBACK = 'Unhandled JS fallback' | ||
StringPrep.prototype.LIBICU_NOT_AVAILABLE = 'libicu unavailable' | ||
StringPrep.prototype.useJsFallbacks = true | ||
StringPrep.prototype.prepare = function(value) { | ||
@@ -42,5 +45,11 @@ this.value = value | ||
} catch (e) {} | ||
if (false === this.useJsFallbacks) | ||
throw new Error(this.LIBICU_NOT_AVAILABLE) | ||
return this.jsFallback() | ||
} | ||
StringPrep.prototype.isNative = function() { | ||
return (null !== this.stringPrep) | ||
} | ||
StringPrep.prototype.jsFallback = function() { | ||
@@ -69,5 +78,13 @@ switch (this.operation) { | ||
StringPrep.prototype.disableJsFallbacks = function() { | ||
this.useJsFallbacks = false | ||
} | ||
StringPrep.prototype.enableJsFallbacks = function() { | ||
this.useJsFallbacks = true | ||
} | ||
module.exports = { | ||
toUnicode: toUnicode, | ||
StringPrep: StringPrep | ||
} | ||
} |
{ | ||
"name": "node-stringprep", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "description": "ICU StringPrep profiles", |
@@ -5,2 +5,3 @@ 'use strict'; | ||
/* jshint -W030 */ | ||
describe('Should use JS fallbacks for StringPrep', function() { | ||
@@ -69,2 +70,50 @@ | ||
}) | ||
}) | ||
describe('Can disable fallbacks', function() { | ||
var StringPrep = proxyquire('../index', { 'bindings': null }).StringPrep | ||
it('Should allow javascript fallbacks to be disabled', function(done) { | ||
var prep = new StringPrep('nameprep') | ||
try { | ||
prep.disableJsFallbacks() | ||
prep.prepare('UPPERCASE') | ||
done('Should have thrown exception') | ||
} catch (e) { | ||
e.message.should.equal(prep.LIBICU_NOT_AVAILABLE) | ||
done() | ||
} | ||
}) | ||
it('Should allow javascript fallbacks to be re-enabled', function(done) { | ||
var prep = new StringPrep('nameprep') | ||
try { | ||
prep.disableJsFallbacks() | ||
prep.prepare('UPPERCASE') | ||
done('Should have thrown exception') | ||
} catch (e) { | ||
e.message.should.equal(prep.LIBICU_NOT_AVAILABLE) | ||
prep.enableJsFallbacks() | ||
prep.prepare('UPPERCASE') | ||
done() | ||
} | ||
}) | ||
}) | ||
describe('\'isNative\' method test', function() { | ||
it('Reports true with native', function() { | ||
var StringPrep = require('../index').StringPrep | ||
var prep = new StringPrep('resourceprep') | ||
prep.isNative().should.be.true | ||
}) | ||
it('Reports false without native', function() { | ||
var StringPrep = proxyquire('../index', { 'bindings': null }).StringPrep | ||
var prep = new StringPrep('resourceprep') | ||
prep.isNative().should.be.false | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
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
20354
210
70