aboutsummaryrefslogtreecommitdiff
path: root/hash_script/node_modules/encoding/lib
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-07-28 15:32:10 +1000
committerYuchen Pei <hi@ypei.me>2022-07-28 15:32:10 +1000
commit5b10a10743b8459f64fe83e0ff420f69da79c9a4 (patch)
treec61904d688247790181d4955a4074b8c94302c03 /hash_script/node_modules/encoding/lib
parentb98cb70b1bcd5b211aaa5d2675f96416911c0647 (diff)
Moving scripts and utilities into a new utilities dir
Diffstat (limited to 'hash_script/node_modules/encoding/lib')
-rw-r--r--hash_script/node_modules/encoding/lib/encoding.js113
-rw-r--r--hash_script/node_modules/encoding/lib/iconv-loader.js14
2 files changed, 0 insertions, 127 deletions
diff --git a/hash_script/node_modules/encoding/lib/encoding.js b/hash_script/node_modules/encoding/lib/encoding.js
deleted file mode 100644
index cbea3ce..0000000
--- a/hash_script/node_modules/encoding/lib/encoding.js
+++ /dev/null
@@ -1,113 +0,0 @@
-'use strict';
-
-var iconvLite = require('iconv-lite');
-// Load Iconv from an external file to be able to disable Iconv for webpack
-// Add /\/iconv-loader$/ to webpack.IgnorePlugin to ignore it
-var Iconv = require('./iconv-loader');
-
-// Expose to the world
-module.exports.convert = convert;
-
-/**
- * Convert encoding of an UTF-8 string or a buffer
- *
- * @param {String|Buffer} str String to be converted
- * @param {String} to Encoding to be converted to
- * @param {String} [from='UTF-8'] Encoding to be converted from
- * @param {Boolean} useLite If set to ture, force to use iconvLite
- * @return {Buffer} Encoded string
- */
-function convert(str, to, from, useLite) {
- from = checkEncoding(from || 'UTF-8');
- to = checkEncoding(to || 'UTF-8');
- str = str || '';
-
- var result;
-
- if (from !== 'UTF-8' && typeof str === 'string') {
- str = new Buffer(str, 'binary');
- }
-
- if (from === to) {
- if (typeof str === 'string') {
- result = new Buffer(str);
- } else {
- result = str;
- }
- } else if (Iconv && !useLite) {
- try {
- result = convertIconv(str, to, from);
- } catch (E) {
- console.error(E);
- try {
- result = convertIconvLite(str, to, from);
- } catch (E) {
- console.error(E);
- result = str;
- }
- }
- } else {
- try {
- result = convertIconvLite(str, to, from);
- } catch (E) {
- console.error(E);
- result = str;
- }
- }
-
-
- if (typeof result === 'string') {
- result = new Buffer(result, 'utf-8');
- }
-
- return result;
-}
-
-/**
- * Convert encoding of a string with node-iconv (if available)
- *
- * @param {String|Buffer} str String to be converted
- * @param {String} to Encoding to be converted to
- * @param {String} [from='UTF-8'] Encoding to be converted from
- * @return {Buffer} Encoded string
- */
-function convertIconv(str, to, from) {
- var response, iconv;
- iconv = new Iconv(from, to + '//TRANSLIT//IGNORE');
- response = iconv.convert(str);
- return response.slice(0, response.length);
-}
-
-/**
- * Convert encoding of astring with iconv-lite
- *
- * @param {String|Buffer} str String to be converted
- * @param {String} to Encoding to be converted to
- * @param {String} [from='UTF-8'] Encoding to be converted from
- * @return {Buffer} Encoded string
- */
-function convertIconvLite(str, to, from) {
- if (to === 'UTF-8') {
- return iconvLite.decode(str, from);
- } else if (from === 'UTF-8') {
- return iconvLite.encode(str, to);
- } else {
- return iconvLite.encode(iconvLite.decode(str, from), to);
- }
-}
-
-/**
- * Converts charset name if needed
- *
- * @param {String} name Character set
- * @return {String} Character set name
- */
-function checkEncoding(name) {
- return (name || '').toString().trim().
- replace(/^latin[\-_]?(\d+)$/i, 'ISO-8859-$1').
- replace(/^win(?:dows)?[\-_]?(\d+)$/i, 'WINDOWS-$1').
- replace(/^utf[\-_]?(\d+)$/i, 'UTF-$1').
- replace(/^ks_c_5601\-1987$/i, 'CP949').
- replace(/^us[\-_]?ascii$/i, 'ASCII').
- toUpperCase();
-}
diff --git a/hash_script/node_modules/encoding/lib/iconv-loader.js b/hash_script/node_modules/encoding/lib/iconv-loader.js
deleted file mode 100644
index 8e925fd..0000000
--- a/hash_script/node_modules/encoding/lib/iconv-loader.js
+++ /dev/null
@@ -1,14 +0,0 @@
-'use strict';
-
-var iconv_package;
-var Iconv;
-
-try {
- // this is to fool browserify so it doesn't try (in vain) to install iconv.
- iconv_package = 'iconv';
- Iconv = require(iconv_package).Iconv;
-} catch (E) {
- // node-iconv not present
-}
-
-module.exports = Iconv;