node-stringprep
Advanced tools
Comparing version 0.5.0 to 0.5.1
22
index.js
'use strict'; | ||
// from unicode/uidna.h | ||
var UIDNA_ALLOW_UNASSIGNED = 1 | ||
var UIDNA_USE_STD3_RULES = 2 | ||
try { | ||
@@ -14,5 +18,7 @@ var bindings = require('bindings')('node_stringprep.node') | ||
var toUnicode = function(value) { | ||
var toUnicode = function(value, options) { | ||
options = options || {} | ||
try { | ||
return bindings.toUnicode(value) | ||
return bindings.toUnicode(value, | ||
(options.allowUnassigned && UIDNA_ALLOW_UNASSIGNED) | 0) | ||
} catch (e) { | ||
@@ -23,7 +29,13 @@ return value | ||
var toASCII = function(value) { | ||
var toASCII = function(value, options) { | ||
options = options || {} | ||
try { | ||
return bindings.toASCII(value) | ||
return bindings.toASCII(value, | ||
(options.allowUnassigned && UIDNA_ALLOW_UNASSIGNED) | | ||
(options.useSTD3Rules && UIDNA_USE_STD3_RULES)) | ||
} catch (e) { | ||
return value | ||
if (options.throwIfError) | ||
throw e | ||
else | ||
return value | ||
} | ||
@@ -30,0 +42,0 @@ } |
{ | ||
"name": "node-stringprep", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "description": "ICU StringPrep profiles", |
@@ -9,5 +9,28 @@ 'use strict'; | ||
var result = SP.toASCII('I\u2665U') | ||
var result = SP.toASCII('i\u2665u') | ||
result.should.equal('xn--iu-t0x') | ||
done() | ||
}) | ||
it('Should throw on error', function(done) { | ||
var SP = require('../index') | ||
SP.toASCII.bind(SP, '\ud83d\ude03', { throwIfError: true }).should.throw() | ||
done() | ||
}) | ||
it('Should convert unassigned code point', function(done) { | ||
var SP = require('../index') | ||
var result = SP.toASCII('\ud83d\ude03', { allowUnassigned : true }) | ||
result.should.equal('xn--h28h') | ||
done() | ||
}) | ||
it('Should error on non-STD3 char', function(done) { | ||
var SP = require('../index') | ||
SP.toASCII.bind(SP, 'abc#def', { throwIfError: true, useSTD3Rules: true }).should.throw() | ||
done() | ||
}) |
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
21082
14
266