Projektstart

This commit is contained in:
2026-01-22 15:49:12 +01:00
parent 7212eb6f7a
commit 57e5f652f8
10637 changed files with 2598792 additions and 64 deletions

21
backend/node_modules/encoding-japanese/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2012 polygonplanet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

831
backend/node_modules/encoding-japanese/README.md generated vendored Normal file
View File

@@ -0,0 +1,831 @@
encoding.js
===========
[![NPM Version](https://img.shields.io/npm/v/encoding-japanese.svg)](https://www.npmjs.com/package/encoding-japanese)
[![GitHub Actions Build Status](https://github.com/polygonplanet/encoding.js/actions/workflows/ci.yml/badge.svg)](https://github.com/polygonplanet/encoding.js/actions)
[![GitHub License](https://img.shields.io/github/license/polygonplanet/encoding.js.svg)](https://github.com/polygonplanet/encoding.js/blob/master/LICENSE)
Convert and detect character encoding in JavaScript.
[**README (日本語)**](README_ja.md)
## Table of contents
- [Features](#features)
* [How to Use Character Encoding in Strings?](#how-to-use-character-encoding-in-strings)
- [Installation](#installation)
* [npm](#npm)
+ [TypeScript](#typescript)
* [Browser (standalone)](#browser-standalone)
* [CDN](#cdn)
- [Supported encodings](#supported-encodings)
* [About `UNICODE`](#about-unicode)
- [Example usage](#example-usage)
- [Demo](#demo)
- [API](#api)
* [detect : Detects character encoding](#encodingdetect-data-encodings)
* [convert : Converts character encoding](#encodingconvert-data-to-from)
+ [Specify conversion options to the argument `to` as an object](#specify-conversion-options-to-the-argument-to-as-an-object)
+ [Specify the return type by the `type` option](#specify-the-return-type-by-the-type-option)
+ [Specify handling for unrepresentable characters](#specify-handling-for-unrepresentable-characters)
+ [Replacing characters with HTML entities when they cannot be represented](#replacing-characters-with-html-entities-when-they-cannot-be-represented)
+ [Ignoring characters when they cannot be represented](#ignoring-characters-when-they-cannot-be-represented)
+ [Throwing an Error when they cannot be represented](#throwing-an-error-when-they-cannot-be-represented)
+ [Specify BOM in UTF-16](#specify-bom-in-utf-16)
* [urlEncode : Encodes to percent-encoded string](#encodingurlencode-data)
* [urlDecode : Decodes from percent-encoded string](#encodingurldecode-string)
* [base64Encode : Encodes to Base64 formatted string](#encodingbase64encode-data)
* [base64Decode : Decodes from Base64 formatted string](#encodingbase64decode-string)
* [codeToString : Converts character code array to string](#encodingcodetostring-code)
* [stringToCode : Converts string to character code array](#encodingstringtocode-string)
* [Japanese Zenkaku/Hankaku conversion](#japanese-zenkakuhankaku-conversion)
- [Other examples](#other-examples)
* [Example using the `fetch API` and Typed Arrays (Uint8Array)](#example-using-the-fetch-api-and-typed-arrays-uint8array)
* [Convert encoding for file using the File APIs](#convert-encoding-for-file-using-the-file-apis)
- [Contributing](#contributing)
- [License](#license)
## Features
encoding.js is a JavaScript library for converting and detecting character encodings,
supporting both Japanese character encodings (`Shift_JIS`, `EUC-JP`, `ISO-2022-JP`) and Unicode formats (`UTF-8`, `UTF-16`).
Since JavaScript string values are internally encoded as UTF-16 code units
([ref: ECMAScript® 2019 Language Specification - 6.1.4 The String Type](https://www.ecma-international.org/ecma-262/10.0/index.html#sec-ecmascript-language-types-string-type)),
they cannot directly handle other character encodings as strings. However, encoding.js overcomes this limitation by treating these encodings as arrays instead of strings,
enabling the conversion between different character sets.
Each character encoding is represented as an array of numbers corresponding to character code values, for example, `[130, 160]` represents "あ" in UTF-8.
The array of character codes used in its methods can also be utilized with TypedArray objects, such as `Uint8Array`, or with `Buffer` in Node.js.
### How to Use Character Encoding in Strings?
Numeric arrays of character codes can be converted to strings using methods such as [`Encoding.codeToString`](#encodingcodetostring-code).
However, due to the JavaScript specifications mentioned above, some character encodings may not be handled properly when converted directly to strings.
If you prefer to use strings instead of numeric arrays, you can convert them to percent-encoded strings,
such as `'%82%A0'`, using [`Encoding.urlEncode`](#encodingurlencode-data) and [`Encoding.urlDecode`](#encodingurldecode-string) for passing to other resources.
Similarly, [`Encoding.base64Encode`](#encodingbase64encode-data) and [`Encoding.base64Decode`](#encodingbase64decode-string) allow for encoding and decoding to and from base64,
which can then be passed as strings.
## Installation
### npm
encoding.js is published under the package name `encoding-japanese` on npm.
```bash
npm install --save encoding-japanese
```
#### Using ES6 `import`
```javascript
import Encoding from 'encoding-japanese';
```
#### Using CommonJS `require`
```javascript
const Encoding = require('encoding-japanese');
```
#### TypeScript
TypeScript type definitions for encoding.js are available at [@types/encoding-japanese](https://www.npmjs.com/package/@types/encoding-japanese) (thanks to [@rhysd](https://github.com/rhysd)).
```bash
npm install --save-dev @types/encoding-japanese
```
### Browser (standalone)
To use encoding.js in a browser environment, you can either install it via npm or download it directly from the [release list](https://github.com/polygonplanet/encoding.js/tags).
The package includes both `encoding.js` and `encoding.min.js`.
Note: Cloning the repository via `git clone` might give you access to the *master* (or *main*) branch, which could still be in a development state.
```html
<!-- To include the full version -->
<script src="encoding.js"></script>
<!-- Or, to include the minified version for production -->
<script src="encoding.min.js"></script>
```
When the script is loaded, the object `Encoding` is defined in the global scope (i.e., `window.Encoding`).
### CDN
You can use encoding.js (package name: `encoding-japanese`) directly from a CDN via a script tag:
```html
<script src="https://unpkg.com/encoding-japanese@2.2.0/encoding.min.js"></script>
```
In this example we use [unpkg](https://unpkg.com/encoding-japanese/), but you can use any CDN that provides npm packages,
for example [cdnjs](https://cdnjs.com/libraries/encoding-japanese) or [jsDelivr](https://www.jsdelivr.com/package/npm/encoding-japanese).
## Supported encodings
|Value in encoding.js|[`detect()`](#encodingdetect-data-encodings)|[`convert()`](#encodingconvert-data-to-from)|MIME Name (Note)|
|:------:|:----:|:-----:|:---|
|ASCII |✓ | |US-ASCII (Code point range: `0-127`)|
|BINARY |✓ | |(Binary string. Code point range: `0-255`)|
|EUCJP |✓ |✓ |EUC-JP|
|JIS |✓ |✓ |ISO-2022-JP|
|SJIS |✓ |✓ |Shift_JIS|
|UTF8 |✓ |✓ |UTF-8|
|UTF16 |✓ |✓ |UTF-16|
|UTF16BE |✓ |✓ |UTF-16BE (big-endian)|
|UTF16LE |✓ |✓ |UTF-16LE (little-endian)|
|UTF32 |✓ | |UTF-32|
|UNICODE |✓ |✓ |(JavaScript string. *See [About `UNICODE`](#about-unicode) below) |
### About `UNICODE`
In encoding.js, `UNICODE` is defined as the internal character encoding that JavaScript strings (JavaScript string objects) can handle directly.
As mentioned in the [Features](#features) section, JavaScript strings are internally encoded using UTF-16 code units.
This means that other character encodings cannot be directly handled without conversion.
Therefore, when converting to a character encoding that is properly representable in JavaScript, you should specify `UNICODE`.
(Note: Even if the HTML file's encoding is UTF-8, you should specify `UNICODE` instead of `UTF8` when processing the encoding in JavaScript.)
When using [`Encoding.convert`](#encodingconvert-data-to-from), if you specify a character encoding other than `UNICODE` (such as `UTF8` or `SJIS`), the values in the returned character code array will range from `0-255`.
However, if you specify `UNICODE`, the values will range from `0-65535`, which corresponds to the range of values returned by `String.prototype.charCodeAt()` (Code Units).
## Example usage
Convert character encoding from JavaScript string (`UNICODE`) to `SJIS`.
```javascript
const unicodeArray = Encoding.stringToCode('こんにちは'); // Convert string to code array
const sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE'
});
console.log(sjisArray);
// [130, 177, 130, 241, 130, 201, 130, 191, 130, 205] ('こんにちは' array in SJIS)
```
Convert character encoding from `SJIS` to `UNICODE`.
```javascript
const sjisArray = [
130, 177, 130, 241, 130, 201, 130, 191, 130, 205
]; // 'こんにちは' array in SJIS
const unicodeArray = Encoding.convert(sjisArray, {
to: 'UNICODE',
from: 'SJIS'
});
const str = Encoding.codeToString(unicodeArray); // Convert code array to string
console.log(str); // 'こんにちは'
```
Detect character encoding.
```javascript
const data = [
227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175
]; // 'こんにちは' array in UTF-8
const detectedEncoding = Encoding.detect(data);
console.log(`Character encoding is ${detectedEncoding}`); // 'Character encoding is UTF8'
```
(Node.js) Example of reading a text file written in `SJIS`.
```javascript
const fs = require('fs');
const Encoding = require('encoding-japanese');
const sjisBuffer = fs.readFileSync('./sjis.txt');
const unicodeArray = Encoding.convert(sjisBuffer, {
to: 'UNICODE',
from: 'SJIS'
});
console.log(Encoding.codeToString(unicodeArray));
```
## Demo
* [Test for character encoding conversion (Demo)](https://polygonplanet.github.io/encoding.js/tests/encoding-test.html)
* [Detect and Convert encoding from file (Demo)](https://polygonplanet.github.io/encoding.js/tests/detect-file-encoding.html)
----
## API
* [detect](#encodingdetect-data-encodings)
* [convert](#encodingconvert-data-to-from)
* [urlEncode](#encodingurlencode-data)
* [urlDecode](#encodingurldecode-string)
* [base64Encode](#encodingbase64encode-data)
* [base64Decode](#encodingbase64decode-string)
* [codeToString](#encodingcodetostring-code)
* [stringToCode](#encodingstringtocode-string)
* [Japanese Zenkaku/Hankaku conversion](#japanese-zenkakuhankaku-conversion)
----
### Encoding.detect (data, [encodings])
Detects the character encoding of the given data.
#### Parameters
* **data** *(Array\<number\>|TypedArray|Buffer|string)* : The code array or string to detect character encoding.
* **\[encodings\]** *(string|Array\<string\>|Object)* : (Optional) Specifies a specific character encoding,
or an array of encodings to limit the detection. Detects automatically if this argument is omitted or `AUTO` is specified.
Supported encoding values can be found in the "[Supported encodings](#supported-encodings)" section.
#### Return value
*(string|boolean)*: Returns a string representing the detected encoding (e.g., `SJIS`, `UTF8`) listed in the "[Supported encodings](#supported-encodings)" section, or `false` if the encoding cannot be detected.
If the `encodings` argument is provided, it returns the name of the detected encoding if the `data` matches any of the specified encodings, or `false` otherwise.
#### Examples
Example of detecting character encoding.
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const detectedEncoding = Encoding.detect(sjisArray);
console.log(`Encoding is ${detectedEncoding}`); // 'Encoding is SJIS'
```
Example of using the `encodings` argument to specify the character encoding to be detected.
This returns a string detected encoding if the specified encoding matches, or `false` otherwise:
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const detectedEncoding = Encoding.detect(sjisArray, 'SJIS');
if (detectedEncoding) {
console.log('Encoding is SJIS');
} else {
console.log('Encoding does not match SJIS');
}
```
Example of specifying multiple encodings:
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const detectedEncoding = Encoding.detect(sjisArray, ['UTF8', 'SJIS']);
if (detectedEncoding) {
console.log(`Encoding is ${detectedEncoding}`); // 'Encoding is SJIS'
} else {
console.log('Encoding does not match UTF8 and SJIS');
}
```
----
### Encoding.convert (data, to[, from])
Converts the character encoding of the given data.
#### Parameters
* **data** *(Array\<number\>|TypedArray|Buffer|string)* : The code array or string to convert character encoding.
* **to** *(string|Object)* : The character encoding name of the conversion destination as a string, or conversion options as an object.
* **\[from\]** *(string|Array\<string\>)* : (Optional) The character encoding name of the conversion source as a string,
or an array of encoding names. Detects automatically if this argument is omitted or `AUTO` is specified.
Supported encoding values can be found in the "[Supported encodings](#supported-encodings)" section.
#### Return value
*(Array\<number\>|TypedArray|string)* : Returns a numeric character code array of the converted character encoding if `data` is an array or a buffer,
or returns the converted string if `data` is a string.
#### Examples
Example of converting a character code array to Shift_JIS from UTF-8:
```javascript
const utf8Array = [227, 129, 130]; // 'あ' in UTF-8
const sjisArray = Encoding.convert(utf8Array, 'SJIS', 'UTF8');
console.log(sjisArray); // [130, 160] ('あ' in SJIS)
```
TypedArray such as `Uint8Array`, and `Buffer` of Node.js can be converted in the same usage:
```javascript
const utf8Array = new Uint8Array([227, 129, 130]);
const sjisArray = Encoding.convert(utf8Array, 'SJIS', 'UTF8');
```
Converts character encoding by auto-detecting the encoding name of the source:
```javascript
// The character encoding is automatically detected when the argument `from` is omitted
const utf8Array = [227, 129, 130];
let sjisArray = Encoding.convert(utf8Array, 'SJIS');
// Or explicitly specify 'AUTO' to auto-detecting
sjisArray = Encoding.convert(utf8Array, 'SJIS', 'AUTO');
```
#### Specify conversion options to the argument `to` as an object
You can pass the second argument `to` as an object for improving readability.
Also, the following options such as `type`, `fallback`, and `bom` must be specified with an object.
```javascript
const utf8Array = [227, 129, 130];
const sjisArray = Encoding.convert(utf8Array, {
to: 'SJIS',
from: 'UTF8'
});
```
#### Specify the return type by the `type` option
`convert` returns an array by default, but you can change the return type by specifying the `type` option.
Also, if the argument `data` is passed as a string and the` type` option is not specified, then `type` ='string' is assumed (returns as a string).
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const unicodeString = Encoding.convert(sjisArray, {
to: 'UNICODE',
from: 'SJIS',
type: 'string' // Specify 'string' to return as string
});
console.log(unicodeString); // 'おはよ'
```
The following `type` options are supported.
* **string** : Return as a string.
* **arraybuffer** : Return as an ArrayBuffer (Actually returns a `Uint16Array` due to historical reasons).
* **array** : Return as an Array. (*default*)
`type: 'string'` can be used as a shorthand for converting a code array to a string,
as performed by [`Encoding.codeToString`](#encodingcodetostring-code).
Note: Specifying `type: 'string'` may not handle conversions properly, except when converting to `UNICODE`.
#### Specify handling for unrepresentable characters
With the `fallback` option, you can specify how to handle characters that cannot be represented in the target encoding.
The `fallback` option supports the following values:
* **html-entity**: Replace characters with HTML entities (decimal HTML numeric character references).
* **html-entity-hex**: Replace characters with HTML entities (hexadecimal HTML numeric character references).
* **ignore**: Ignore characters that cannot be represented.
* **error**: Throw an error if any character cannot be represented.
#### Replacing characters with HTML entities when they cannot be represented
Characters that cannot be represented in the target character set are replaced with '?' (U+003F) by default,
but by specifying `html-entity` as the `fallback` option, you can replace them with HTML entities (Numeric character references), such as `&#127843;`.
Example of specifying `{ fallback: 'html-entity' }` option:
```javascript
const unicodeArray = Encoding.stringToCode('寿司🍣ビール🍺');
// No fallback specified
let sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE'
});
console.log(sjisArray); // Converted to a code array of '寿司?ビール?'
// Specify `fallback: html-entity`
sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE',
fallback: 'html-entity'
});
console.log(sjisArray); // Converted to a code array of '寿司&#127843;ビール&#127866;'
```
Example of specifying `{ fallback: 'html-entity-hex' }` option:
```javascript
const unicodeArray = Encoding.stringToCode('ホッケの漢字は𩸽');
const sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE',
fallback: 'html-entity-hex'
});
console.log(sjisArray); // Converted to a code array of 'ホッケの漢字は&#x29e3d;'
```
#### Ignoring characters when they cannot be represented
By specifying `ignore` as a `fallback` option, characters that cannot be represented in the target encoding format can be ignored.
Example of specifying `{ fallback: 'ignore' }` option:
```javascript
const unicodeArray = Encoding.stringToCode('寿司🍣ビール🍺');
// No fallback specified
let sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE'
});
console.log(sjisArray); // Converted to a code array of '寿司?ビール?'
// Specify `fallback: ignore`
sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE',
fallback: 'ignore'
});
console.log(sjisArray); // Converted to a code array of '寿司ビール'
```
#### Throwing an Error when they cannot be represented
If you need to throw an error when a character cannot be represented in the target character encoding,
specify `error` as a `fallback` option. This will cause an exception to be thrown.
Example of specifying `{ fallback: 'error' }` option:
```javascript
const unicodeArray = Encoding.stringToCode('おにぎり🍙ラーメン🍜');
try {
const sjisArray = Encoding.convert(unicodeArray, {
to: 'SJIS',
from: 'UNICODE',
fallback: 'error' // Specify 'error' to throw an exception
});
} catch (e) {
console.error(e); // Error: Character cannot be represented: [240, 159, 141, 153]
}
```
#### Specify BOM in UTF-16
You can add a BOM (byte order mark) by specifying the `bom` option when converting to `UTF16`.
The default is no BOM.
```javascript
const utf16Array = Encoding.convert(utf8Array, {
to: 'UTF16',
from: 'UTF8',
bom: true // Specify to add the BOM
});
```
`UTF16` byte order is big-endian by default.
If you want to convert as little-endian, specify the `{ bom: 'LE' }` option.
```javascript
const utf16leArray = Encoding.convert(utf8Array, {
to: 'UTF16',
from: 'UTF8',
bom: 'LE' // Specify to add the BOM as little-endian
});
```
If you do not need BOM, use `UTF16BE` or `UTF16LE`.
`UTF16BE` is big-endian, and `UTF16LE` is little-endian, and both have no BOM.
```javascript
const utf16beArray = Encoding.convert(utf8Array, {
to: 'UTF16BE',
from: 'UTF8'
});
```
----
### Encoding.urlEncode (data)
Encodes a numeric character code array into a percent-encoded string formatted as a URI component in `%xx` format.
urlEncode escapes all characters except the following, just like [`encodeURIComponent()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
```
A-Z a-z 0-9 - _ . ! ~ * ' ( )
```
#### Parameters
* **data** *(Array\<number\>|TypedArray|Buffer|string)* : The numeric character code array or string that will be encoded into a percent-encoded URI component.
#### Return value
*(string)* : Returns a percent-encoded string formatted as a URI component in `%xx` format.
#### Examples
Example of URL encoding a Shift_JIS array:
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const encoded = Encoding.urlEncode(sjisArray);
console.log(encoded); // '%82%A8%82%CD%82%E6'
```
----
### Encoding.urlDecode (string)
Decodes a percent-encoded string formatted as a URI component in `%xx` format to a numeric character code array.
#### Parameters
* **string** *(string)* : The string to decode.
#### Return value
*(Array\<number\>)* : Returns a numeric character code array.
#### Examples
Example of decoding a percent-encoded Shift_JIS string:
```javascript
const encoded = '%82%A8%82%CD%82%E6'; // 'おはよ' encoded as percent-encoded SJIS string
const sjisArray = Encoding.urlDecode(encoded);
console.log(sjisArray); // [130, 168, 130, 205, 130, 230]
```
----
### Encoding.base64Encode (data)
Encodes a numeric character code array into a Base64 encoded string.
#### Parameters
* **data** *(Array\<number\>|TypedArray|Buffer|string)* : The numeric character code array or string to encode.
#### Return value
*(string)* : Returns a Base64 encoded string.
#### Examples
Example of Base64 encoding a Shift_JIS array:
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const encodedStr = Encoding.base64Encode(sjisArray);
console.log(encodedStr); // 'gqiCzYLm'
```
----
### Encoding.base64Decode (string)
Decodes a Base64 encoded string to a numeric character code array.
#### Parameters
* **string** *(string)* : The Base64 encoded string to decode.
#### Return value
*(Array\<number\>)* : Returns a Base64 decoded numeric character code array.
#### Examples
Example of `base64Encode` and `base64Decode`:
```javascript
const sjisArray = [130, 177, 130, 241, 130, 201, 130, 191, 130, 205]; // 'こんにちは' array in SJIS
const encodedStr = Encoding.base64Encode(sjisArray);
console.log(encodedStr); // 'grGC8YLJgr+CzQ=='
const decodedArray = Encoding.base64Decode(encodedStr);
console.log(decodedArray); // [130, 177, 130, 241, 130, 201, 130, 191, 130, 205]
```
----
### Encoding.codeToString (code)
Converts a numeric character code array to string.
#### Parameters
* **code** *(Array\<number\>|TypedArray|Buffer)* : The numeric character code array to convert.
#### Return value
*(string)* : Returns a converted string.
#### Examples
Example of converting a character code array to a string:
```javascript
const sjisArray = [130, 168, 130, 205, 130, 230]; // 'おはよ' array in SJIS
const unicodeArray = Encoding.convert(sjisArray, {
to: 'UNICODE',
from: 'SJIS'
});
const unicodeStr = Encoding.codeToString(unicodeArray);
console.log(unicodeStr); // 'おはよ'
```
----
### Encoding.stringToCode (string)
Converts a string to a numeric character code array.
#### Parameters
* **string** *(string)* : The string to convert.
#### Return value
*(Array\<number\>)* : Returns a numeric character code array converted from the string.
#### Examples
Example of converting a string to a character code array:
```javascript
const unicodeArray = Encoding.stringToCode('おはよ');
console.log(unicodeArray); // [12362, 12399, 12424]
```
----
### Japanese Zenkaku/Hankaku conversion
The following methods convert Japanese full-width (zenkaku) and half-width (hankaku) characters,
suitable for use with `UNICODE` strings or numeric character code arrays of `UNICODE`.
Returns a converted string if the argument `data` is a string.
Returns a numeric character code array if the argument `data` is a code array.
- **Encoding.toHankakuCase (data)** : Converts full-width (zenkaku) symbols and alphanumeric characters to their half-width (hankaku) equivalents.
- **Encoding.toZenkakuCase (data)** : Converts half-width (hankaku) symbols and alphanumeric characters to their full-width (zenkaku) equivalents.
- **Encoding.toHiraganaCase (data)** : Converts full-width katakana to full-width hiragana.
- **Encoding.toKatakanaCase (data)** : Converts full-width hiragana to full-width katakana.
- **Encoding.toHankanaCase (data)** : Converts full-width katakana to half-width katakana.
- **Encoding.toZenkanaCase (data)** : Converts half-width katakana to full-width katakana.
- **Encoding.toHankakuSpace (data)** : Converts the em space (U+3000) to the single space (U+0020).
- **Encoding.toZenkakuSpace (data)** : Converts the single space (U+0020) to the em space (U+3000).
#### Parameters
- **data** *(Array\<number\>|TypedArray|Buffer|string)* : The string or numeric character code array to convert.
#### Return value
*(Array\<number\>|string)* : Returns a converted string or numeric character code array.
#### Examples
Example of converting zenkaku and hankaku strings:
```javascript
console.log(Encoding.toHankakuCase('')); // 'abcDEF123@!#*='
console.log(Encoding.toZenkakuCase('abcDEF123@!#*=')); // ''
console.log(Encoding.toHiraganaCase('アイウエオァィゥェォヴボポ')); // 'あいうえおぁぃぅぇぉゔぼぽ'
console.log(Encoding.toKatakanaCase('あいうえおぁぃぅぇぉゔぼぽ')); // 'アイウエオァィゥェォヴボポ'
console.log(Encoding.toHankanaCase('アイウエオァィゥェォヴボポ')); // 'アイウエオァィゥェォヴボポ'
console.log(Encoding.toZenkanaCase('アイウエオァィゥェォヴボポ')); // 'アイウエオァィゥェォヴボポ'
console.log(Encoding.toHankakuSpace('あいうえお abc 123')); // 'あいうえお abc 123'
console.log(Encoding.toZenkakuSpace('あいうえお abc 123')); // 'あいうえお abc 123'
```
Example of converting zenkaku and hankaku code arrays:
```javascript
const unicodeArray = Encoding.stringToCode('abc123!# あいうアイウ ABCアイウ');
console.log(Encoding.codeToString(Encoding.toHankakuCase(unicodeArray)));
// 'abc123!# あいうアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toZenkakuCase(unicodeArray)));
// 'abc123!# あいうアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toHiraganaCase(unicodeArray)));
// 'abc123!# あいうあいう ABCアイウ'
console.log(Encoding.codeToString(Encoding.toKatakanaCase(unicodeArray)));
// 'abc123!# アイウアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toHankanaCase(unicodeArray)));
// 'abc123!# あいうアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toZenkanaCase(unicodeArray)));
// 'abc123!# あいうアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toHankakuSpace(unicodeArray)));
// ' あいうアイウ ABCアイウ'
console.log(Encoding.codeToString(Encoding.toZenkakuSpace(unicodeArray)));
// ' あいうアイウ ABCアイウ'
```
----
## Other examples
### Example using the `Fetch API` and Typed Arrays (Uint8Array)
This example reads a text file encoded in Shift_JIS as binary data,
and displays it as a string after converting it to Unicode using [Encoding.convert](#encodingconvert-data-to-from).
```javascript
(async () => {
try {
const response = await fetch('shift_jis.txt');
const buffer = await response.arrayBuffer();
// Code array with Shift_JIS file contents
const sjisArray = new Uint8Array(buffer);
// Convert encoding to UNICODE (JavaScript Code Units) from Shift_JIS
const unicodeArray = Encoding.convert(sjisArray, {
to: 'UNICODE',
from: 'SJIS'
});
// Convert to string from code array for display
const unicodeString = Encoding.codeToString(unicodeArray);
console.log(unicodeString);
} catch (error) {
console.error('Error loading the file:', error);
}
})();
```
<details>
<summary>XMLHttpRequest version of this example</summary>
```javascript
const req = new XMLHttpRequest();
req.open('GET', 'shift_jis.txt', true);
req.responseType = 'arraybuffer';
req.onload = (event) => {
const buffer = req.response;
if (buffer) {
// Code array with Shift_JIS file contents
const sjisArray = new Uint8Array(buffer);
// Convert encoding to UNICODE (JavaScript Code Units) from Shift_JIS
const unicodeArray = Encoding.convert(sjisArray, {
to: 'UNICODE',
from: 'SJIS'
});
// Convert to string from code array for display
const unicodeString = Encoding.codeToString(unicodeArray);
console.log(unicodeString);
}
};
req.send(null);
```
</details>
### Convert encoding for file using the File APIs
This example uses the File API to read the content of a selected file, detects its character encoding,
and converts the file content to UNICODE from any character encoding such as `Shift_JIS` or `EUC-JP`.
The converted content is then displayed in a textarea.
```html
<input type="file" id="file">
<div id="encoding"></div>
<textarea id="content" rows="5" cols="80"></textarea>
<script>
function onFileSelect(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const codes = new Uint8Array(e.target.result);
const detectedEncoding = Encoding.detect(codes);
const encoding = document.getElementById('encoding');
encoding.textContent = `Detected encoding: ${detectedEncoding}`;
// Convert encoding to UNICODE
const unicodeString = Encoding.convert(codes, {
to: 'UNICODE',
from: detectedEncoding,
type: 'string'
});
document.getElementById('content').value = unicodeString;
};
reader.readAsArrayBuffer(file);
}
document.getElementById('file').addEventListener('change', onFileSelect);
</script>
```
[**Demo**](https://polygonplanet.github.io/encoding.js/tests/detect-file-encoding.html)
## Contributing
We welcome contributions from everyone.
For bug reports and feature requests, please [create an issue on GitHub](https://github.com/polygonplanet/encoding.js/issues).
### Pull requests
Before submitting a pull request, please run `npm run test` to ensure there are no errors.
We only accept pull requests that pass all tests.
## License
This project is licensed under the terms of the MIT license.
See the [LICENSE](LICENSE) file for details.

6082
backend/node_modules/encoding-japanese/encoding.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

69
backend/node_modules/encoding-japanese/package.json generated vendored Normal file
View File

@@ -0,0 +1,69 @@
{
"name": "encoding-japanese",
"version": "2.2.0",
"description": "Convert and detect character encoding in JavaScript",
"main": "src/index.js",
"files": [
"encoding.js",
"encoding.min.js",
"src/*"
],
"scripts": {
"build": "npm run compile && npm run minify",
"compile": "browserify src/index.js -o encoding.js -s Encoding -p [ bannerify --file src/banner.js ] --no-bundle-external --bare",
"minify": "uglifyjs encoding.js -o encoding.min.js --comments -c -m -b ascii_only=true,beautify=false",
"test": "eslint . && npm run build && mocha tests/test",
"watch": "watchify src/index.js -o encoding.js -s Encoding -p [ bannerify --file src/banner.js ] --no-bundle-external --bare --poll=300 -v"
},
"engines": {
"node": ">=8.10.0"
},
"repository": {
"type": "git",
"url": "https://github.com/polygonplanet/encoding.js.git"
},
"author": "polygonplanet <polygon.planet.aqua@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/polygonplanet/encoding.js/issues"
},
"homepage": "https://github.com/polygonplanet/encoding.js",
"keywords": [
"base64",
"charset",
"convert",
"detect",
"encoding",
"euc-jp",
"eucjp",
"iconv",
"iso-2022-jp",
"japanese",
"jis",
"shift_jis",
"sjis",
"unicode",
"urldecode",
"urlencode",
"utf-16",
"utf-32",
"utf-8"
],
"dependencies": {},
"devDependencies": {
"bannerify": "^1.0.1",
"browserify": "^17.0.0",
"eslint": "^8.57.0",
"mocha": "^10.4.0",
"package-json-versionify": "^1.0.4",
"power-assert": "^1.6.1",
"uglify-js": "^3.17.4",
"uglifyify": "^5.0.2",
"watchify": "^4.0.0"
},
"browserify": {
"transform": [
"package-json-versionify"
]
}
}

6
backend/node_modules/encoding-japanese/src/banner.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/*!
* <%= pkg.name %> v<%= pkg.version %> - <%= pkg.description %>
* Copyright (c) 2012 <%= pkg.author %>
* <%= pkg.homepage %>
* @license <%= pkg.license %>
*/

139
backend/node_modules/encoding-japanese/src/config.js generated vendored Normal file
View File

@@ -0,0 +1,139 @@
var util = require('./util');
var EncodingTable = require('./encoding-table');
// Fallback character when a character can't be represented
exports.FALLBACK_CHARACTER = 63; // '?'
var HAS_TYPED = exports.HAS_TYPED = typeof Uint8Array !== 'undefined' && typeof Uint16Array !== 'undefined';
// Test for String.fromCharCode.apply
var CAN_CHARCODE_APPLY = false;
var CAN_CHARCODE_APPLY_TYPED = false;
try {
if (String.fromCharCode.apply(null, [0x61]) === 'a') {
CAN_CHARCODE_APPLY = true;
}
} catch (e) {}
if (HAS_TYPED) {
try {
if (String.fromCharCode.apply(null, new Uint8Array([0x61])) === 'a') {
CAN_CHARCODE_APPLY_TYPED = true;
}
} catch (e) {}
}
exports.CAN_CHARCODE_APPLY = CAN_CHARCODE_APPLY;
exports.CAN_CHARCODE_APPLY_TYPED = CAN_CHARCODE_APPLY_TYPED;
// Function.prototype.apply stack max range
exports.APPLY_BUFFER_SIZE = 65533;
exports.APPLY_BUFFER_SIZE_OK = null;
var EncodingNames = exports.EncodingNames = {
UTF32: {
order: 0
},
UTF32BE: {
alias: ['UCS4']
},
UTF32LE: null,
UTF16: {
order: 1
},
UTF16BE: {
alias: ['UCS2']
},
UTF16LE: null,
BINARY: {
order: 2
},
ASCII: {
order: 3,
alias: ['ISO646', 'CP367']
},
JIS: {
order: 4,
alias: ['ISO2022JP']
},
UTF8: {
order: 5
},
EUCJP: {
order: 6
},
SJIS: {
order: 7,
alias: ['CP932', 'MSKANJI', 'WINDOWS31J']
},
UNICODE: {
order: 8
}
};
var EncodingAliases = {};
exports.EncodingAliases = EncodingAliases;
exports.EncodingOrders = (function() {
var aliases = EncodingAliases;
var names = util.objectKeys(EncodingNames);
var orders = [];
var name, encoding, j, l;
for (var i = 0, len = names.length; i < len; i++) {
name = names[i];
aliases[name] = name;
encoding = EncodingNames[name];
if (encoding != null) {
if (encoding.order != null) {
orders[orders.length] = name;
}
if (encoding.alias) {
// Create encoding aliases
for (j = 0, l = encoding.alias.length; j < l; j++) {
aliases[encoding.alias[j]] = name;
}
}
}
}
orders.sort(function(a, b) {
return EncodingNames[a].order - EncodingNames[b].order;
});
return orders;
}());
function init_JIS_TO_UTF8_TABLE() {
if (EncodingTable.JIS_TO_UTF8_TABLE === null) {
EncodingTable.JIS_TO_UTF8_TABLE = {};
var keys = util.objectKeys(EncodingTable.UTF8_TO_JIS_TABLE);
var i = 0;
var len = keys.length;
var key, value;
for (; i < len; i++) {
key = keys[i];
value = EncodingTable.UTF8_TO_JIS_TABLE[key];
if (value > 0x5F) {
EncodingTable.JIS_TO_UTF8_TABLE[value] = key | 0;
}
}
EncodingTable.JISX0212_TO_UTF8_TABLE = {};
keys = util.objectKeys(EncodingTable.UTF8_TO_JISX0212_TABLE);
len = keys.length;
for (i = 0; i < len; i++) {
key = keys[i];
value = EncodingTable.UTF8_TO_JISX0212_TABLE[key];
EncodingTable.JISX0212_TO_UTF8_TABLE[value] = key | 0;
}
}
}
exports.init_JIS_TO_UTF8_TABLE = init_JIS_TO_UTF8_TABLE;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,502 @@
/**
* Binary (exe, images and so, etc.)
*
* Note:
* This function is not considered for Unicode
*/
function isBINARY(data) {
var i = 0;
var len = data && data.length;
var c;
for (; i < len; i++) {
c = data[i];
if (c > 0xFF) {
return false;
}
if ((c >= 0x00 && c <= 0x07) || c === 0xFF) {
return true;
}
}
return false;
}
exports.isBINARY = isBINARY;
/**
* ASCII (ISO-646)
*/
function isASCII(data) {
var i = 0;
var len = data && data.length;
var b;
for (; i < len; i++) {
b = data[i];
if (b > 0xFF ||
(b >= 0x80 && b <= 0xFF) ||
b === 0x1B) {
return false;
}
}
return true;
}
exports.isASCII = isASCII;
/**
* ISO-2022-JP (JIS)
*
* RFC1468 Japanese Character Encoding for Internet Messages
* RFC1554 ISO-2022-JP-2: Multilingual Extension of ISO-2022-JP
* RFC2237 Japanese Character Encoding for Internet Messages
*/
function isJIS(data) {
var i = 0;
var len = data && data.length;
var b, esc1, esc2;
for (; i < len; i++) {
b = data[i];
if (b > 0xFF || (b >= 0x80 && b <= 0xFF)) {
return false;
}
if (b === 0x1B) {
if (i + 2 >= len) {
return false;
}
esc1 = data[i + 1];
esc2 = data[i + 2];
if (esc1 === 0x24) {
if (esc2 === 0x28 || // JIS X 0208-1990/2000/2004
esc2 === 0x40 || // JIS X 0208-1978
esc2 === 0x42) { // JIS X 0208-1983
return true;
}
} else if (esc1 === 0x26 && // JIS X 0208-1990
esc2 === 0x40) {
return true;
} else if (esc1 === 0x28) {
if (esc2 === 0x42 || // ASCII
esc2 === 0x49 || // JIS X 0201 Halfwidth Katakana
esc2 === 0x4A) { // JIS X 0201-1976 Roman set
return true;
}
}
}
}
return false;
}
exports.isJIS = isJIS;
/**
* EUC-JP
*/
function isEUCJP(data) {
var i = 0;
var len = data && data.length;
var b;
for (; i < len; i++) {
b = data[i];
if (b < 0x80) {
continue;
}
if (b > 0xFF || b < 0x8E) {
return false;
}
if (b === 0x8E) {
if (i + 1 >= len) {
return false;
}
b = data[++i];
if (b < 0xA1 || 0xDF < b) {
return false;
}
} else if (b === 0x8F) {
if (i + 2 >= len) {
return false;
}
b = data[++i];
if (b < 0xA2 || 0xED < b) {
return false;
}
b = data[++i];
if (b < 0xA1 || 0xFE < b) {
return false;
}
} else if (0xA1 <= b && b <= 0xFE) {
if (i + 1 >= len) {
return false;
}
b = data[++i];
if (b < 0xA1 || 0xFE < b) {
return false;
}
} else {
return false;
}
}
return true;
}
exports.isEUCJP = isEUCJP;
/**
* Shift-JIS (SJIS)
*/
function isSJIS(data) {
var i = 0;
var len = data && data.length;
var b;
while (i < len && data[i] > 0x80) {
if (data[i++] > 0xFF) {
return false;
}
}
for (; i < len; i++) {
b = data[i];
if (b <= 0x80 ||
(0xA1 <= b && b <= 0xDF)) {
continue;
}
if (b === 0xA0 || b > 0xEF || i + 1 >= len) {
return false;
}
b = data[++i];
if (b < 0x40 || b === 0x7F || b > 0xFC) {
return false;
}
}
return true;
}
exports.isSJIS = isSJIS;
/**
* UTF-8
*/
function isUTF8(data) {
var i = 0;
var len = data && data.length;
var b;
for (; i < len; i++) {
b = data[i];
if (b > 0xFF) {
return false;
}
if (b === 0x09 || b === 0x0A || b === 0x0D ||
(b >= 0x20 && b <= 0x7E)) {
continue;
}
if (b >= 0xC2 && b <= 0xDF) {
if (i + 1 >= len || data[i + 1] < 0x80 || data[i + 1] > 0xBF) {
return false;
}
i++;
} else if (b === 0xE0) {
if (i + 2 >= len ||
data[i + 1] < 0xA0 || data[i + 1] > 0xBF ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF) {
return false;
}
i += 2;
} else if ((b >= 0xE1 && b <= 0xEC) ||
b === 0xEE || b === 0xEF) {
if (i + 2 >= len ||
data[i + 1] < 0x80 || data[i + 1] > 0xBF ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF) {
return false;
}
i += 2;
} else if (b === 0xED) {
if (i + 2 >= len ||
data[i + 1] < 0x80 || data[i + 1] > 0x9F ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF) {
return false;
}
i += 2;
} else if (b === 0xF0) {
if (i + 3 >= len ||
data[i + 1] < 0x90 || data[i + 1] > 0xBF ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF ||
data[i + 3] < 0x80 || data[i + 3] > 0xBF) {
return false;
}
i += 3;
} else if (b >= 0xF1 && b <= 0xF3) {
if (i + 3 >= len ||
data[i + 1] < 0x80 || data[i + 1] > 0xBF ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF ||
data[i + 3] < 0x80 || data[i + 3] > 0xBF) {
return false;
}
i += 3;
} else if (b === 0xF4) {
if (i + 3 >= len ||
data[i + 1] < 0x80 || data[i + 1] > 0x8F ||
data[i + 2] < 0x80 || data[i + 2] > 0xBF ||
data[i + 3] < 0x80 || data[i + 3] > 0xBF) {
return false;
}
i += 3;
} else {
return false;
}
}
return true;
}
exports.isUTF8 = isUTF8;
/**
* UTF-16 (LE or BE)
*
* RFC2781: UTF-16, an encoding of ISO 10646
*
* @link http://www.ietf.org/rfc/rfc2781.txt
*/
function isUTF16(data) {
var i = 0;
var len = data && data.length;
var pos = null;
var b1, b2, next, prev;
if (len < 2) {
if (data[0] > 0xFF) {
return false;
}
} else {
b1 = data[0];
b2 = data[1];
if (b1 === 0xFF && // BOM (little-endian)
b2 === 0xFE) {
return true;
}
if (b1 === 0xFE && // BOM (big-endian)
b2 === 0xFF) {
return true;
}
for (; i < len; i++) {
if (data[i] === 0x00) {
pos = i;
break;
} else if (data[i] > 0xFF) {
return false;
}
}
if (pos === null) {
return false; // Non ASCII
}
next = data[pos + 1]; // BE
if (next !== void 0 && next > 0x00 && next < 0x80) {
return true;
}
prev = data[pos - 1]; // LE
if (prev !== void 0 && prev > 0x00 && prev < 0x80) {
return true;
}
}
return false;
}
exports.isUTF16 = isUTF16;
/**
* UTF-16BE (big-endian)
*
* RFC 2781 4.3 Interpreting text labelled as UTF-16
* Text labelled "UTF-16BE" can always be interpreted as being big-endian
* when BOM does not founds (SHOULD)
*
* @link http://www.ietf.org/rfc/rfc2781.txt
*/
function isUTF16BE(data) {
var i = 0;
var len = data && data.length;
var pos = null;
var b1, b2;
if (len < 2) {
if (data[0] > 0xFF) {
return false;
}
} else {
b1 = data[0];
b2 = data[1];
if (b1 === 0xFE && // BOM
b2 === 0xFF) {
return true;
}
for (; i < len; i++) {
if (data[i] === 0x00) {
pos = i;
break;
} else if (data[i] > 0xFF) {
return false;
}
}
if (pos === null) {
return false; // Non ASCII
}
if (pos % 2 === 0) {
return true;
}
}
return false;
}
exports.isUTF16BE = isUTF16BE;
/**
* UTF-16LE (little-endian)
*/
function isUTF16LE(data) {
var i = 0;
var len = data && data.length;
var pos = null;
var b1, b2;
if (len < 2) {
if (data[0] > 0xFF) {
return false;
}
} else {
b1 = data[0];
b2 = data[1];
if (b1 === 0xFF && // BOM
b2 === 0xFE) {
return true;
}
for (; i < len; i++) {
if (data[i] === 0x00) {
pos = i;
break;
} else if (data[i] > 0xFF) {
return false;
}
}
if (pos === null) {
return false; // Non ASCII
}
if (pos % 2 !== 0) {
return true;
}
}
return false;
}
exports.isUTF16LE = isUTF16LE;
/**
* UTF-32
*
* Unicode 3.2.0: Unicode Standard Annex #19
*
* @link http://www.iana.org/assignments/charset-reg/UTF-32
* @link http://www.unicode.org/reports/tr19/tr19-9.html
*/
function isUTF32(data) {
var i = 0;
var len = data && data.length;
var pos = null;
var b1, b2, b3, b4;
var next, prev;
if (len < 4) {
for (; i < len; i++) {
if (data[i] > 0xFF) {
return false;
}
}
} else {
b1 = data[0];
b2 = data[1];
b3 = data[2];
b4 = data[3];
if (b1 === 0x00 && b2 === 0x00 && // BOM (big-endian)
b3 === 0xFE && b4 === 0xFF) {
return true;
}
if (b1 === 0xFF && b2 === 0xFE && // BOM (little-endian)
b3 === 0x00 && b4 === 0x00) {
return true;
}
for (; i < len; i++) {
if (data[i] === 0x00 && data[i + 1] === 0x00 && data[i + 2] === 0x00) {
pos = i;
break;
} else if (data[i] > 0xFF) {
return false;
}
}
if (pos === null) {
return false;
}
// The byte order should be the big-endian when BOM is not detected.
next = data[pos + 3];
if (next !== void 0 && next > 0x00 && next <= 0x7F) {
// big-endian
return data[pos + 2] === 0x00 && data[pos + 1] === 0x00;
}
prev = data[pos - 1];
if (prev !== void 0 && prev > 0x00 && prev <= 0x7F) {
// little-endian
return data[pos + 1] === 0x00 && data[pos + 2] === 0x00;
}
}
return false;
}
exports.isUTF32 = isUTF32;
/**
* JavaScript Unicode array
*/
function isUNICODE(data) {
var i = 0;
var len = data && data.length;
var c;
for (; i < len; i++) {
c = data[i];
if (c < 0 || c > 0x10FFFF) {
return false;
}
}
return true;
}
exports.isUNICODE = isUNICODE;

View File

@@ -0,0 +1,4 @@
exports.UTF8_TO_JIS_TABLE = require('./utf8-to-jis-table');
exports.UTF8_TO_JISX0212_TABLE = require('./utf8-to-jisx0212-table');
exports.JIS_TO_UTF8_TABLE = require('./jis-to-utf8-table');
exports.JISX0212_TO_UTF8_TABLE = require('./jisx0212-to-utf8-table');

593
backend/node_modules/encoding-japanese/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,593 @@
var config = require('./config');
var util = require('./util');
var EncodingDetect = require('./encoding-detect');
var EncodingConvert = require('./encoding-convert');
var KanaCaseTable = require('./kana-case-table');
var version = require('../package.json').version;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var Encoding = {
version: version,
/**
* Encoding orders
*/
orders: config.EncodingOrders,
/**
* Detects character encoding
*
* If encodings is "AUTO", or the encoding-list as an array, or
* comma separated list string it will be detected automatically
*
* @param {Array.<number>|TypedArray|string} data The data being detected
* @param {(Object|string|Array.<string>)=} [encodings] The encoding-list of
* character encoding
* @return {string|boolean} The detected character encoding, or false
*/
detect: function(data, encodings) {
if (data == null || data.length === 0) {
return false;
}
if (util.isObject(encodings) && !util.isArray(encodings)) {
encodings = encodings.encoding;
}
if (util.isString(data)) {
data = util.stringToBuffer(data);
}
if (encodings == null) {
encodings = Encoding.orders;
} else {
if (util.isString(encodings)) {
encodings = encodings.toUpperCase();
if (encodings === 'AUTO') {
encodings = Encoding.orders;
} else if (~encodings.indexOf(',')) {
encodings = encodings.split(/\s*,\s*/);
} else {
encodings = [encodings];
}
}
}
var len = encodings.length;
var e, encoding, method;
for (var i = 0; i < len; i++) {
e = encodings[i];
encoding = util.canonicalizeEncodingName(e);
if (!encoding) {
continue;
}
method = 'is' + encoding;
if (!hasOwnProperty.call(EncodingDetect, method)) {
throw new Error('Undefined encoding: ' + e);
}
if (EncodingDetect[method](data)) {
return encoding;
}
}
return false;
},
/**
* Convert character encoding
*
* If `from` is "AUTO", or the encoding-list as an array, or
* comma separated list string it will be detected automatically
*
* @param {Array.<number>|TypedArray|string} data The data being converted
* @param {(string|Object)} to The name of encoding to
* @param {(string|Array.<string>)=} [from] The encoding-list of
* character encoding
* @return {Array|TypedArray|string} The converted data
*/
convert: function(data, to, from) {
var result, type, options;
if (!util.isObject(to)) {
options = {};
} else {
options = to;
from = options.from;
to = options.to;
if (options.type) {
type = options.type;
}
}
if (util.isString(data)) {
type = type || 'string';
data = util.stringToBuffer(data);
} else if (data == null || data.length === 0) {
data = [];
}
var encodingFrom;
if (from != null && util.isString(from) &&
from.toUpperCase() !== 'AUTO' && !~from.indexOf(',')) {
encodingFrom = util.canonicalizeEncodingName(from);
} else {
encodingFrom = Encoding.detect(data);
}
var encodingTo = util.canonicalizeEncodingName(to);
var method = encodingFrom + 'To' + encodingTo;
if (hasOwnProperty.call(EncodingConvert, method)) {
result = EncodingConvert[method](data, options);
} else {
// Returns the raw data if the method is undefined
result = data;
}
switch (('' + type).toLowerCase()) {
case 'string':
return util.codeToString_fast(result);
case 'arraybuffer':
return util.codeToBuffer(result);
default: // array
return util.bufferToCode(result);
}
},
/**
* Encode a character code array to URL string like encodeURIComponent
*
* @param {Array.<number>|TypedArray} data The data being encoded
* @return {string} The percent encoded string
*/
urlEncode: function(data) {
if (util.isString(data)) {
data = util.stringToBuffer(data);
}
var alpha = util.stringToCode('0123456789ABCDEF');
var results = [];
var i = 0;
var len = data && data.length;
var b;
for (; i < len; i++) {
b = data[i];
// urlEncode is for an array of numbers in the range 0-255 (Uint8Array), but if an array
// of numbers greater than 255 is passed (Unicode code unit i.e. charCodeAt range),
// it will be tentatively encoded as UTF-8 using encodeURIComponent.
if (b > 0xFF) {
return encodeURIComponent(util.codeToString_fast(data));
}
if ((b >= 0x61 /*a*/ && b <= 0x7A /*z*/) ||
(b >= 0x41 /*A*/ && b <= 0x5A /*Z*/) ||
(b >= 0x30 /*0*/ && b <= 0x39 /*9*/) ||
b === 0x21 /*!*/ ||
(b >= 0x27 /*'*/ && b <= 0x2A /***/) ||
b === 0x2D /*-*/ || b === 0x2E /*.*/ ||
b === 0x5F /*_*/ || b === 0x7E /*~*/
) {
results[results.length] = b;
} else {
results[results.length] = 0x25; /*%*/
if (b < 0x10) {
results[results.length] = 0x30; /*0*/
results[results.length] = alpha[b];
} else {
results[results.length] = alpha[b >> 4 & 0xF];
results[results.length] = alpha[b & 0xF];
}
}
}
return util.codeToString_fast(results);
},
/**
* Decode a percent encoded string to
* character code array like decodeURIComponent
*
* @param {string} string The data being decoded
* @return {Array.<number>} The decoded array
*/
urlDecode: function(string) {
var results = [];
var i = 0;
var len = string && string.length;
var c;
while (i < len) {
c = string.charCodeAt(i++);
if (c === 0x25 /*%*/) {
results[results.length] = parseInt(
string.charAt(i++) + string.charAt(i++), 16);
} else {
results[results.length] = c;
}
}
return results;
},
/**
* Encode a character code array to Base64 encoded string
*
* @param {Array.<number>|TypedArray} data The data being encoded
* @return {string} The Base64 encoded string
*/
base64Encode: function(data) {
if (util.isString(data)) {
data = util.stringToBuffer(data);
}
return util.base64encode(data);
},
/**
* Decode a Base64 encoded string to character code array
*
* @param {string} string The data being decoded
* @return {Array.<number>} The decoded array
*/
base64Decode: function(string) {
return util.base64decode(string);
},
/**
* Joins a character code array to string
*
* @param {Array.<number>|TypedArray} data The data being joined
* @return {String} The joined string
*/
codeToString: util.codeToString_fast,
/**
* Splits string to an array of character codes
*
* @param {string} string The input string
* @return {Array.<number>} The character code array
*/
stringToCode: util.stringToCode,
/**
* 全角英数記号文字を半角英数記号文字に変換
*
* Convert the ascii symbols and alphanumeric characters to
* the zenkaku symbols and alphanumeric characters
*
* @example
* console.log(Encoding.toHankakuCase(' '));
* // 'Hello World! 12345'
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toHankakuCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c >= 0xFF01 && c <= 0xFF5E) {
c -= 0xFEE0;
}
results[results.length] = c;
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 半角英数記号文字を全角英数記号文字に変換
*
* Convert to the zenkaku symbols and alphanumeric characters
* from the ascii symbols and alphanumeric characters
*
* @example
* console.log(Encoding.toZenkakuCase('Hello World! 12345'));
* // ' '
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toZenkakuCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c >= 0x21 && c <= 0x7E) {
c += 0xFEE0;
}
results[results.length] = c;
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 全角カタカナを全角ひらがなに変換
*
* Convert to the zenkaku hiragana from the zenkaku katakana
*
* @example
* console.log(Encoding.toHiraganaCase('ボポヴァアィイゥウェエォオ'));
* // 'ぼぽう゛ぁあぃいぅうぇえぉお'
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toHiraganaCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c >= 0x30A1 && c <= 0x30F6) {
c -= 0x0060;
// 「ワ゛」 => 「わ」 + 「゛」
} else if (c === 0x30F7) {
results[results.length] = 0x308F;
c = 0x309B;
// 「ヲ゛」 => 「を」 + 「゛」
} else if (c === 0x30FA) {
results[results.length] = 0x3092;
c = 0x309B;
}
results[results.length] = c;
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 全角ひらがなを全角カタカナに変換
*
* Convert to the zenkaku katakana from the zenkaku hiragana
*
* @example
* console.log(Encoding.toKatakanaCase('ぼぽう゛ぁあぃいぅうぇえぉお'));
* // 'ボポヴァアィイゥウェエォオ'
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toKatakanaCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c >= 0x3041 && c <= 0x3096) {
if ((c === 0x308F || // 「わ」 + 「゛」 => 「ワ゛」
c === 0x3092) && // 「を」 + 「゛」 => 「ヲ゛」
i < len && data[i] === 0x309B) {
c = c === 0x308F ? 0x30F7 : 0x30FA;
i++;
} else {
c += 0x0060;
}
}
results[results.length] = c;
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 全角カタカナを半角カタカナに変換
*
* Convert to the hankaku katakana from the zenkaku katakana
*
* @example
* console.log(Encoding.toHankanaCase('ボポヴァアィイゥウェエォオ'));
* // 'ボポヴァアィイゥウェエォオ'
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toHankanaCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c, d, t;
while (i < len) {
c = data[i++];
if (c >= 0x3001 && c <= 0x30FC) {
t = KanaCaseTable.HANKANA_TABLE[c];
if (t !== void 0) {
results[results.length] = t;
continue;
}
}
// 「ヴ」, 「ワ」+「゛」, 「ヲ」+「゛」
if (c === 0x30F4 || c === 0x30F7 || c === 0x30FA) {
results[results.length] = KanaCaseTable.HANKANA_SONANTS[c];
results[results.length] = 0xFF9E;
// 「カ」 - 「ド」
} else if (c >= 0x30AB && c <= 0x30C9) {
results[results.length] = KanaCaseTable.HANKANA_TABLE[c - 1];
results[results.length] = 0xFF9E;
// 「ハ」 - 「ポ」
} else if (c >= 0x30CF && c <= 0x30DD) {
d = c % 3;
results[results.length] = KanaCaseTable.HANKANA_TABLE[c - d];
results[results.length] = KanaCaseTable.HANKANA_MARKS[d - 1];
} else {
results[results.length] = c;
}
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 半角カタカナを全角カタカナに変換 (濁音含む)
*
* Convert to the zenkaku katakana from the hankaku katakana
*
* @example
* console.log(Encoding.toZenkanaCase('ボポヴァアィイゥウェエォオ'));
* // 'ボポヴァアィイゥウェエォオ'
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toZenkanaCase: function(data) {
var asString = false;
if (util.isString(data)) {
asString = true;
data = util.stringToBuffer(data);
}
var results = [];
var len = data && data.length;
var i = 0;
var c, code, next;
for (i = 0; i < len; i++) {
c = data[i];
// Hankaku katakana
if (c > 0xFF60 && c < 0xFFA0) {
code = KanaCaseTable.ZENKANA_TABLE[c - 0xFF61];
if (i + 1 < len) {
next = data[i + 1];
// 「゙」 + 「ヴ」
if (next === 0xFF9E && c === 0xFF73) {
code = 0x30F4;
i++;
// 「゙」 + 「ワ゛」
} else if (next === 0xFF9E && c === 0xFF9C) {
code = 0x30F7;
i++;
// 「゙」 + 「ヲ゛」
} else if (next === 0xFF9E && c === 0xFF66) {
code = 0x30FA;
i++;
// 「゙」 + 「カ」 - 「コ」 or 「ハ」 - 「ホ」
} else if (next === 0xFF9E &&
((c > 0xFF75 && c < 0xFF85) ||
(c > 0xFF89 && c < 0xFF8F))) {
code++;
i++;
// 「゚」 + 「ハ」 - 「ホ」
} else if (next === 0xFF9F &&
(c > 0xFF89 && c < 0xFF8F)) {
code += 2;
i++;
}
}
c = code;
}
results[results.length] = c;
}
return asString ? util.codeToString_fast(results) : results;
},
/**
* 全角スペースを半角スペースに変換
*
* Convert the em space(U+3000) to the single space(U+0020)
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toHankakuSpace: function(data) {
if (util.isString(data)) {
return data.replace(/\u3000/g, ' ');
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c === 0x3000) {
c = 0x20;
}
results[results.length] = c;
}
return results;
},
/**
* 半角スペースを全角スペースに変換
*
* Convert the single space(U+0020) to the em space(U+3000)
*
* @param {Array.<number>|TypedArray|string} data The input unicode data
* @return {Array.<number>|string} The conveted data
*/
toZenkakuSpace: function(data) {
if (util.isString(data)) {
return data.replace(/\u0020/g, '\u3000');
}
var results = [];
var len = data && data.length;
var i = 0;
var c;
while (i < len) {
c = data[i++];
if (c === 0x20) {
c = 0x3000;
}
results[results.length] = c;
}
return results;
}
};
module.exports = Encoding;

View File

@@ -0,0 +1,5 @@
/**
* Encoding conversion table for JIS to UTF-8
*/
var JIS_TO_UTF8_TABLE = null;
module.exports = JIS_TO_UTF8_TABLE;

View File

@@ -0,0 +1,5 @@
/**
* Encoding conversion table for JIS X 0212:1990 (Hojo-Kanji) to UTF-8
*/
var JISX0212_TO_UTF8_TABLE = null;
module.exports = JISX0212_TO_UTF8_TABLE;

View File

@@ -0,0 +1,41 @@
/* eslint-disable key-spacing */
/**
* Katakana table
*/
exports.HANKANA_TABLE = {
0x3001:0xFF64,0x3002:0xFF61,0x300C:0xFF62,0x300D:0xFF63,0x309B:0xFF9E,
0x309C:0xFF9F,0x30A1:0xFF67,0x30A2:0xFF71,0x30A3:0xFF68,0x30A4:0xFF72,
0x30A5:0xFF69,0x30A6:0xFF73,0x30A7:0xFF6A,0x30A8:0xFF74,0x30A9:0xFF6B,
0x30AA:0xFF75,0x30AB:0xFF76,0x30AD:0xFF77,0x30AF:0xFF78,0x30B1:0xFF79,
0x30B3:0xFF7A,0x30B5:0xFF7B,0x30B7:0xFF7C,0x30B9:0xFF7D,0x30BB:0xFF7E,
0x30BD:0xFF7F,0x30BF:0xFF80,0x30C1:0xFF81,0x30C3:0xFF6F,0x30C4:0xFF82,
0x30C6:0xFF83,0x30C8:0xFF84,0x30CA:0xFF85,0x30CB:0xFF86,0x30CC:0xFF87,
0x30CD:0xFF88,0x30CE:0xFF89,0x30CF:0xFF8A,0x30D2:0xFF8B,0x30D5:0xFF8C,
0x30D8:0xFF8D,0x30DB:0xFF8E,0x30DE:0xFF8F,0x30DF:0xFF90,0x30E0:0xFF91,
0x30E1:0xFF92,0x30E2:0xFF93,0x30E3:0xFF6C,0x30E4:0xFF94,0x30E5:0xFF6D,
0x30E6:0xFF95,0x30E7:0xFF6E,0x30E8:0xFF96,0x30E9:0xFF97,0x30EA:0xFF98,
0x30EB:0xFF99,0x30EC:0xFF9A,0x30ED:0xFF9B,0x30EF:0xFF9C,0x30F2:0xFF66,
0x30F3:0xFF9D,0x30FB:0xFF65,0x30FC:0xFF70
};
exports.HANKANA_SONANTS = {
0x30F4:0xFF73,
0x30F7:0xFF9C,
0x30FA:0xFF66
};
exports.HANKANA_MARKS = [0xFF9E, 0xFF9F];
/**
* Zenkaku table [U+FF61] - [U+FF9F]
*/
exports.ZENKANA_TABLE = [
0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1, 0x30A3,
0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3, 0x30FC,
0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, 0x30AF,
0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, 0x30BF,
0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, 0x30CD,
0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE, 0x30DF,
0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, 0x30EA,
0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C
];

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

361
backend/node_modules/encoding-japanese/src/util.js generated vendored Normal file
View File

@@ -0,0 +1,361 @@
var config = require('./config');
var fromCharCode = String.fromCharCode;
var slice = Array.prototype.slice;
var toString = Object.prototype.toString;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var nativeIsArray = Array.isArray;
var nativeObjectKeys = Object.keys;
function isObject(x) {
var type = typeof x;
return type === 'function' || type === 'object' && !!x;
}
exports.isObject = isObject;
function isArray(x) {
return nativeIsArray ? nativeIsArray(x) : toString.call(x) === '[object Array]';
}
exports.isArray = isArray;
function isString(x) {
return typeof x === 'string' || toString.call(x) === '[object String]';
}
exports.isString = isString;
function objectKeys(object) {
if (nativeObjectKeys) {
return nativeObjectKeys(object);
}
var keys = [];
for (var key in object) {
if (hasOwnProperty.call(object, key)) {
keys[keys.length] = key;
}
}
return keys;
}
exports.objectKeys = objectKeys;
function createBuffer(bits, size) {
if (config.HAS_TYPED) {
switch (bits) {
case 8: return new Uint8Array(size);
case 16: return new Uint16Array(size);
}
}
return new Array(size);
}
exports.createBuffer = createBuffer;
function stringToBuffer(string) {
var length = string.length;
var buffer = createBuffer(16, length);
for (var i = 0; i < length; i++) {
buffer[i] = string.charCodeAt(i);
}
return buffer;
}
exports.stringToBuffer = stringToBuffer;
function codeToString_fast(code) {
if (config.CAN_CHARCODE_APPLY && config.CAN_CHARCODE_APPLY_TYPED) {
var len = code && code.length;
if (len < config.APPLY_BUFFER_SIZE && config.APPLY_BUFFER_SIZE_OK) {
return fromCharCode.apply(null, code);
}
if (config.APPLY_BUFFER_SIZE_OK === null) {
try {
var s = fromCharCode.apply(null, code);
if (len > config.APPLY_BUFFER_SIZE) {
config.APPLY_BUFFER_SIZE_OK = true;
}
return s;
} catch (e) {
// Ignore the RangeError "arguments too large"
config.APPLY_BUFFER_SIZE_OK = false;
}
}
}
return codeToString_chunked(code);
}
exports.codeToString_fast = codeToString_fast;
function codeToString_chunked(code) {
var string = '';
var length = code && code.length;
var i = 0;
var sub;
while (i < length) {
if (code.subarray) {
sub = code.subarray(i, i + config.APPLY_BUFFER_SIZE);
} else {
sub = code.slice(i, i + config.APPLY_BUFFER_SIZE);
}
i += config.APPLY_BUFFER_SIZE;
if (config.APPLY_BUFFER_SIZE_OK) {
string += fromCharCode.apply(null, sub);
continue;
}
if (config.APPLY_BUFFER_SIZE_OK === null) {
try {
string += fromCharCode.apply(null, sub);
if (sub.length > config.APPLY_BUFFER_SIZE) {
config.APPLY_BUFFER_SIZE_OK = true;
}
continue;
} catch (e) {
config.APPLY_BUFFER_SIZE_OK = false;
}
}
return codeToString_slow(code);
}
return string;
}
exports.codeToString_chunked = codeToString_chunked;
function codeToString_slow(code) {
var string = '';
var length = code && code.length;
for (var i = 0; i < length; i++) {
string += fromCharCode(code[i]);
}
return string;
}
exports.codeToString_slow = codeToString_slow;
function stringToCode(string) {
var code = [];
var len = string && string.length;
for (var i = 0; i < len; i++) {
code[i] = string.charCodeAt(i);
}
return code;
}
exports.stringToCode = stringToCode;
function codeToBuffer(code) {
if (config.HAS_TYPED) {
// Unicode code point (charCodeAt range) values have a range of 0-0xFFFF, so use Uint16Array
return new Uint16Array(code);
}
if (isArray(code)) {
return code;
}
var length = code && code.length;
var buffer = [];
for (var i = 0; i < length; i++) {
buffer[i] = code[i];
}
return buffer;
}
exports.codeToBuffer = codeToBuffer;
function bufferToCode(buffer) {
if (isArray(buffer)) {
return buffer;
}
return slice.call(buffer);
}
exports.bufferToCode = bufferToCode;
/**
* Canonicalize the passed encoding name to the internal encoding name
*/
function canonicalizeEncodingName(target) {
var name = '';
var expect = ('' + target).toUpperCase().replace(/[^A-Z0-9]+/g, '');
var aliasNames = objectKeys(config.EncodingAliases);
var len = aliasNames.length;
var hit = 0;
var encoding, encodingLen, j;
for (var i = 0; i < len; i++) {
encoding = aliasNames[i];
if (encoding === expect) {
name = encoding;
break;
}
encodingLen = encoding.length;
for (j = hit; j < encodingLen; j++) {
if (encoding.slice(0, j) === expect.slice(0, j) ||
encoding.slice(-j) === expect.slice(-j)) {
name = encoding;
hit = j;
}
}
}
if (hasOwnProperty.call(config.EncodingAliases, name)) {
return config.EncodingAliases[name];
}
return name;
}
exports.canonicalizeEncodingName = canonicalizeEncodingName;
// Base64
/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
// -- Masanao Izumo Copyright 1999 "free"
// Added binary array support for the Encoding.js
var base64EncodeChars = [
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47
];
var base64DecodeChars = [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
];
var base64EncodePadding = '='.charCodeAt(0);
function base64encode(data) {
var out, i, len;
var c1, c2, c3;
len = data && data.length;
i = 0;
out = [];
while (i < len) {
c1 = data[i++];
if (i == len) {
out[out.length] = base64EncodeChars[c1 >> 2];
out[out.length] = base64EncodeChars[(c1 & 0x3) << 4];
out[out.length] = base64EncodePadding;
out[out.length] = base64EncodePadding;
break;
}
c2 = data[i++];
if (i == len) {
out[out.length] = base64EncodeChars[c1 >> 2];
out[out.length] = base64EncodeChars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)];
out[out.length] = base64EncodeChars[(c2 & 0xF) << 2];
out[out.length] = base64EncodePadding;
break;
}
c3 = data[i++];
out[out.length] = base64EncodeChars[c1 >> 2];
out[out.length] = base64EncodeChars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)];
out[out.length] = base64EncodeChars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)];
out[out.length] = base64EncodeChars[c3 & 0x3F];
}
return codeToString_fast(out);
}
exports.base64encode = base64encode;
function base64decode(str) {
var c1, c2, c3, c4;
var i, len, out;
len = str && str.length;
i = 0;
out = [];
while (i < len) {
/* c1 */
do {
c1 = base64DecodeChars[str.charCodeAt(i++) & 0xFF];
} while (i < len && c1 == -1);
if (c1 == -1) {
break;
}
/* c2 */
do {
c2 = base64DecodeChars[str.charCodeAt(i++) & 0xFF];
} while (i < len && c2 == -1);
if (c2 == -1) {
break;
}
out[out.length] = (c1 << 2) | ((c2 & 0x30) >> 4);
/* c3 */
do {
c3 = str.charCodeAt(i++) & 0xFF;
if (c3 == 61) {
return out;
}
c3 = base64DecodeChars[c3];
} while (i < len && c3 == -1);
if (c3 == -1) {
break;
}
out[out.length] = ((c2 & 0xF) << 4) | ((c3 & 0x3C) >> 2);
/* c4 */
do {
c4 = str.charCodeAt(i++) & 0xFF;
if (c4 == 61) {
return out;
}
c4 = base64DecodeChars[c4];
} while (i < len && c4 == -1);
if (c4 == -1) {
break;
}
out[out.length] = ((c3 & 0x03) << 6) | c4;
}
return out;
}
exports.base64decode = base64decode;