Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-native2ascii

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-native2ascii - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

7

CHANGES.md

@@ -0,1 +1,8 @@

## Version 0.1.2, 2018.01.25
* Move Unicode escape and unescape logic out to new `escape-unicode` and `unescape-unicode` modules respectively
* Configure travis to also build against Node.js v9
* Replace `chai` with `assert` in unit tests
* Bump dependencies
## Version 0.1.1, 2017.12.09

@@ -2,0 +9,0 @@

2

LICENSE.md

@@ -1,2 +0,2 @@

Copyright (C) 2017 Alasdair Mercer, !ninja
Copyright (C) 2018 Alasdair Mercer, !ninja

@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "node-native2ascii",
"version": "0.1.1",
"version": "0.1.2",
"description": "Node.js implementation of Java's Native-to-ASCII Converter",

@@ -28,12 +28,13 @@ "homepage": "https://github.com/NotNinja/node-native2ascii",

"dependencies": {
"commander": "^2.12.2"
"commander": "^2.13.0",
"escape-unicode": "^0.1.0",
"unescape-unicode": "^0.1.0"
},
"devDependencies": {
"chai": "^4.1.2",
"codecov": "^3.0.0",
"eslint": "^4.13.0",
"eslint": "^4.16.0",
"eslint-config-notninja": "^0.2.3",
"mocha": "^4.0.1",
"nyc": "^11.3.0",
"sinon": "^4.1.3",
"mocha": "^5.0.0",
"nyc": "^11.4.1",
"sinon": "^4.2.1",
"tmp": "0.0.33"

@@ -40,0 +41,0 @@ },

@@ -91,3 +91,3 @@ 888 d8b .d8888b. d8b d8b

native2ascii(input[, options])
### native2ascii(input[, options])

@@ -101,3 +101,3 @@ Converts the specified `input` so that it can be encoded in ASCII by using Unicode escapes ("\uxxxx" notation) for all

### Options
#### Options

@@ -108,3 +108,3 @@ | Option | Description | Default |

### Examples
#### Examples

@@ -111,0 +111,0 @@ Unicode escape characters not in the ASCII character set so that they can be safely written encoded into ASCII:

/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
* Copyright (C) 2018 Alasdair Mercer, !ninja
*

@@ -4,0 +4,0 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy

/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
* Copyright (C) 2018 Alasdair Mercer, !ninja
*

@@ -4,0 +4,0 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy

/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
* Copyright (C) 2018 Alasdair Mercer, !ninja
*

@@ -25,3 +25,3 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy

const hexDigits = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' ];
const escapeUnicode = require('escape-unicode');

@@ -41,5 +41,5 @@ /**

if (code > 0x7f) {
result += `\\u${toHex(code)}`;
result += escapeUnicode(input, i, i + 1);
} else {
result += input.charAt(i);
result += input[i];
}

@@ -51,25 +51,2 @@ }

/**
* Converts the specified character <code>code</code> to a hexadecimal value.
*
* @param {number} code - the character code to be converted
* @return {string} The 4-digit hexadecimal string.
*/
function toHex(code) {
return toHexDigit((code >> 12) & 15) +
toHexDigit((code >> 8) & 15) +
toHexDigit((code >> 4) & 15) +
toHexDigit(code & 15);
}
/**
* Converts the specified <code>nibble</code> to a hexadecimal digit.
*
* @param {number} nibble - the nibble to be converted
* @return {string} The single-digit hexadecimal string.
*/
function toHexDigit(nibble) {
return hexDigits[nibble & 15];
}
module.exports = escape;
/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
* Copyright (C) 2018 Alasdair Mercer, !ninja
*

@@ -4,0 +4,0 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy

/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
* Copyright (C) 2018 Alasdair Mercer, !ninja
*

@@ -25,3 +25,3 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy

/* eslint complexity: "off" */
const unescapeUnicode = require('unescape-unicode');

@@ -42,9 +42,9 @@ /**

for (let i = 0, length = input.length; i < length; i++) {
let ch = input.charAt(i);
let ch = input[i];
if (ch === '\\') {
ch = input.charAt(++i);
ch = input[++i];
if (ch === 'u') {
result += getUnicode(input, i + 1);
result += unescapeUnicode(input, i + 1);
i += 4;

@@ -62,61 +62,2 @@ } else {

/**
* Attempts to convert the Unicode escape within <code>input</code> at the specified <code>offset</code>.
*
* <code>offset</code> should be the index of the first character after the "\u" prefix of the Unicode escape and will
* result in the offset being increased as it reads in the next four characters within <code>input</code>.
*
* This function will throw an error if the hexadecimal value corresponding to the Unicode escape at the specified
* <code>offset</code> is malformed.
*
* @param {string} input - the string to be converted
* @param {number} offset - the offset of the hexadecimal segment of the Unicode escape from which the Unicode character
* is to be derived relative to <code>input</code>
* @return {string} The Unicode character converted from the escape at <code>offset</code> within <code>input</code>.
* @throws {Error} If the Unicode escape is malformed.
*/
function getUnicode(input, offset) {
let unicode = 0;
for (let i = offset, end = offset + 4; i < end; i++) {
const ch = input.charAt(i);
const code = ch.charCodeAt(0);
switch (ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
unicode = (unicode << 4) + code - 0x30;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
unicode = (unicode << 4) + 10 + code - 0x41;
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
unicode = (unicode << 4) + 10 + code - 0x61;
break;
default:
throw new Error(`Malformed character found in \\uxxxx encoding: ${ch}`);
}
}
return String.fromCharCode(unicode);
}
module.exports = unescape;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc