utf8-encoding
Advanced tools
Comparing version 0.0.9 to 0.1.0
{ | ||
"name": "utf8-encoding", | ||
"description": "utf8 encoder/decoder of whatwg Encoding Living Standard https://encoding.spec.whatwg.org/", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"author": "Jxck", | ||
@@ -42,8 +42,8 @@ "bugs": { | ||
"bower": "bower install", | ||
"clean": "\\rm -f *.js", | ||
"postinstall": "mv node_modules/obtain-unicode/obtain-unicode.d.ts types/", | ||
"clean": "\\rm -f *.js npm-debug.log", | ||
"type": "cp node_modules/obtain-unicode/obtain-unicode.d.ts types/", | ||
"prepublish": "npm run tsc", | ||
"test": "npm run tsc && node test/test.js && \\rm -f npm-debug.log && echo open test/index.html in your browser", | ||
"tsc": "tsc utf8-encoding.ts --target ES5 --module commonjs --noImplicitAny" | ||
"tsc": "tsc utf8-encoding.ts --target ES5 --module commonjs" | ||
} | ||
} |
@@ -7,6 +7,7 @@ var TextEncoder = TextEncoder || require('../utf8-encoding').TextEncoder; | ||
console.log('.'); | ||
// console.log(actual, expected); | ||
console.assert(actual === expected, '\nact: ' + actual + '\nexp: ' + expected); | ||
} | ||
(function example() { | ||
function example() { | ||
var encoder = new TextEncoder(); | ||
@@ -18,8 +19,10 @@ var decoder = new TextDecoder(); | ||
// "beer!🍻 | ||
})(); | ||
}; | ||
(function test() { | ||
var encoder = new TextEncoder(); | ||
var decoder = new TextDecoder(); | ||
function test(textencoder, textdecoder) { | ||
var encoder = new textencoder(); | ||
var decoder = new textdecoder(); | ||
[ | ||
[ "", [ ]], | ||
[ "aAzZ09", [ 97, 65, 122, 90, 48, 57 ]], | ||
@@ -46,2 +49,24 @@ [ "~`!@", [ 126, 96, 33, 64 ]], | ||
}); | ||
}; | ||
function compat() { | ||
// unspecified in spec ? | ||
// assert(decoder.decode([]), _decoder.decode([])); | ||
// assert(decoder.decode(null), _decoder.decode(null)); | ||
// assert(decoder.decode(undefined), _decoder.decode(undefined)); | ||
}; | ||
(function TestEncoding() { | ||
try { | ||
example(); | ||
test(TextEncoder, TextDecoder); | ||
if (typeof nativeTextEncoder !== 'undefined' | ||
&& typeof nativeTextDecoder !== 'undefined') { | ||
test(nativeTextEncoder, nativeTextDecoder); | ||
compat(); | ||
} | ||
} catch(err) { | ||
console.error(err); | ||
} | ||
})(); |
@@ -7,2 +7,11 @@ /// <reference path="types/webidl.d.ts" /> | ||
} | ||
// save platform implementation if exists | ||
var nativeTextEncoder; | ||
if (typeof this.TextEncoder !== "undefined") { | ||
nativeTextEncoder = this.TextEncoder; | ||
} | ||
var nativeTextDecoder; | ||
if (typeof this.TextDecoder !== "undefined") { | ||
nativeTextDecoder = this.TextDecoder; | ||
} | ||
var UTF8Encoder; | ||
@@ -232,3 +241,3 @@ (function (UTF8Encoder) { | ||
// step 2-2 | ||
if (["utf-8", "utf8"].indexOf(this._encoding) > -1 && this.ignoreBOMFlag === false && this.bomSeenFlag === false) { | ||
if (["utf-8", "utf8"].indexOf(this._encoding) !== -1 && this.ignoreBOMFlag === false && this.bomSeenFlag === false) { | ||
// step 2-2-1 | ||
@@ -390,3 +399,3 @@ if (token === 0xFEFF) { | ||
})(UTF8Encoder || (UTF8Encoder = {})); | ||
this.TextEncoder = this.TextEncoder || UTF8Encoder.TextEncoder; | ||
this.TextDecoder = this.TextDecoder || UTF8Encoder.TextDecoder; | ||
this.TextEncoder = nativeTextEncoder || UTF8Encoder.TextEncoder; | ||
this.TextDecoder = nativeTextDecoder || UTF8Encoder.TextDecoder; |
@@ -30,2 +30,13 @@ /// <reference path="types/webidl.d.ts" /> | ||
// save platform implementation if exists | ||
var nativeTextEncoder; | ||
if (typeof this.TextEncoder !== "undefined") { | ||
nativeTextEncoder = this.TextEncoder; | ||
} | ||
var nativeTextDecoder; | ||
if (typeof this.TextDecoder !== "undefined") { | ||
nativeTextDecoder = this.TextDecoder; | ||
} | ||
module UTF8Encoder { | ||
@@ -316,3 +327,3 @@ "use strict"; | ||
// step 2-2 | ||
if (["utf-8", "utf8"].indexOf(this._encoding) > -1 | ||
if (["utf-8", "utf8"].indexOf(this._encoding) !== -1 | ||
&& this.ignoreBOMFlag === false | ||
@@ -510,3 +521,3 @@ && this.bomSeenFlag === false) { | ||
this.TextEncoder = this.TextEncoder || UTF8Encoder.TextEncoder; | ||
this.TextDecoder = this.TextDecoder || UTF8Encoder.TextDecoder; | ||
this.TextEncoder = nativeTextEncoder || UTF8Encoder.TextEncoder; | ||
this.TextDecoder = nativeTextDecoder || UTF8Encoder.TextDecoder; |
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
33444
929
0