node-stringprep
Advanced tools
Comparing version 0.1.12 to 0.2.0
71
index.js
@@ -1,1 +0,70 @@ | ||
module.exports = require('bindings')('node_stringprep.node') | ||
'use strict'; | ||
try { | ||
var bindings = require('bindings')('node_stringprep.node') | ||
} catch (ex) { | ||
console.warn( | ||
'Cannot load StringPrep-' + | ||
require('./package.json').version + | ||
' bindings (using fallback). You may need to ' + | ||
'`npm install node-stringprep`' | ||
) | ||
} | ||
var toUnicode = function(value) { | ||
try { | ||
return bindings.toUnicode(value) | ||
} catch (e) { | ||
return value | ||
} | ||
} | ||
var StringPrep = function(operation) { | ||
this.operation = operation | ||
try { | ||
this.stringPrep = new bindings.StringPrep(this.operation) | ||
} catch (e) { | ||
this.stringPrep = null | ||
} | ||
} | ||
StringPrep.prototype.UNKNOWN_PROFILE_TYPE = 'Unknown profile type' | ||
StringPrep.prototype.UNHANDLED_FALLBACK = 'Unhandled JS fallback' | ||
StringPrep.prototype.prepare = function(value) { | ||
this.value = value | ||
try { | ||
if (this.stringPrep) { | ||
return this.stringPrep.prepare(this.value) | ||
} | ||
} catch (e) {} | ||
return this.jsFallback() | ||
} | ||
StringPrep.prototype.jsFallback = function() { | ||
switch (this.operation) { | ||
case 'nameprep': | ||
case 'nodeprep': | ||
return this.value.toLowerCase() | ||
case 'resourceprep': | ||
return this.value | ||
case 'nfs4_cs_prep': | ||
case 'nfs4_cis_prep': | ||
case 'nfs4_mixed_prep prefix': | ||
case 'nfs4_mixed_prep suffix': | ||
case 'iscsi': | ||
case 'mib': | ||
case 'saslprep': | ||
case 'trace': | ||
case 'ldap': | ||
case 'ldapci': | ||
throw new Error(this.UNHANDLED_FALLBACK) | ||
default: | ||
throw new Error(this.UNKNOWN_PROFILE_TYPE) | ||
} | ||
} | ||
module.exports = { | ||
toUnicode: toUnicode, | ||
StringPrep: StringPrep | ||
} |
{ | ||
"name": "node-stringprep", | ||
"version": "0.1.12", | ||
"version": "0.2.0", | ||
"main": "index.js", | ||
@@ -12,3 +12,3 @@ "description": "ICU StringPrep profiles", | ||
"scripts": { | ||
"test": "node test/leakcheck.js" | ||
"test": "grunt test" | ||
}, | ||
@@ -19,3 +19,9 @@ "dependencies": { | ||
}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"proxyquire": "~0.5.2", | ||
"grunt-mocha-cli": "~1.3.0", | ||
"grunt-contrib-jshint": "~0.7.2", | ||
"should": "~2.1.1", | ||
"grunt": "~0.4.2" | ||
}, | ||
"repository": { | ||
@@ -22,0 +28,0 @@ "type": "git", |
@@ -1,21 +0,17 @@ | ||
var SP = require('../index') | ||
var next = global.setImmediate | ||
? function () { setImmediate(run) } | ||
: function () { process.nextTick(run) } | ||
'use strict'; | ||
function run() { | ||
var p = new SP.StringPrep('nameprep') | ||
var r = p.prepare('A\u0308ffin') | ||
if (r !== 'äffin') | ||
throw r | ||
next() | ||
} | ||
require('should') | ||
try { | ||
run() | ||
console.log('Success') | ||
process.exit(0) | ||
} catch (e) { | ||
console.log(e.stack) | ||
process.exit(1) | ||
} | ||
it('Should not leak', function(done) { | ||
var SP = require('../index') | ||
try { | ||
var p = new SP.StringPrep('nameprep') | ||
var result = p.prepare('A\u0308ffin') | ||
result.should.equal('äffin') | ||
done() | ||
} catch (e) { | ||
done(e) | ||
} | ||
}) |
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
17049
13
155
5