Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion types/encoding-japanese/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for encoding-japanese 1.0
// Type definitions for encoding-japanese 2.0
// Project: https://github.com/polygonplanet/encoding.js
// Definitions by: rhysd <https://github.com/rhysd>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
Expand Down Expand Up @@ -40,26 +40,30 @@ export interface ConvertStringOptions {
to: Encoding;
from?: Encoding | undefined;
type: 'string';
fallback?: 'html-entity' | 'html-entity-hex';
bom?: boolean | string | undefined;
}

export interface ConvertArrayBufferOptions {
to: Encoding;
from?: Encoding | undefined;
type: 'arraybuffer';
fallback?: 'html-entity' | 'html-entity-hex';
bom?: boolean | string | undefined;
}

export interface ConvertArrayOptions {
to: Encoding;
from?: Encoding | undefined;
type: 'array';
fallback?: 'html-entity' | 'html-entity-hex';
bom?: boolean | string | undefined;
}

export interface ConvertUnknownOptions {
to: Encoding;
from?: Encoding | undefined;
fallback?: 'html-entity' | 'html-entity-hex';
bom?: boolean | string | undefined;
}

Expand Down Expand Up @@ -94,6 +98,7 @@ export function toHankakuSpace(data: string): string;
export function toZenkakuSpace(data: ReadonlyArray<number>): number[];
export function toZenkakuSpace(data: string): string;

export const version: string;
export const orders: string[];

export {};
41 changes: 15 additions & 26 deletions types/encoding-japanese/test/encoding-japanese-tests.cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const sjisArray3 = Encoding.convert(utf8Array, {
});
sjisArray3; // $ExpectType number[]

const sjisArray4 = Encoding.convert('🐙', {
to: 'SJIS', // to_encoding
from: 'UTF8', // from_encoding
type: 'string',
fallback: 'html-entity',
});
sjisArray4; // $ExpectType string
// fallback: '&#128025;'

const utf8String = 'ã\u0081\u0093ã\u0082\u0093ã\u0081«ã\u0081¡ã\u0081¯';
const unicodeString = Encoding.convert(utf8String, {
to: 'UNICODE',
Expand Down Expand Up @@ -107,32 +116,11 @@ if (isSJIS) {
// Encoding is SJIS'
}

const sjisArray4 = [
130,
177,
130,
241,
130,
201,
130,
191,
130,
205,
129,
65,
130,
217,
130,
176,
129,
153,
130,
210,
130,
230,
const sjisArray5 = [
130, 177, 130, 241, 130, 201, 130, 191, 130, 205, 129, 65, 130, 217, 130, 176, 129, 153, 130, 210, 130, 230,
];

const encoded = Encoding.urlEncode(sjisArray4); // $ExpectType string
const encoded = Encoding.urlEncode(sjisArray5); // $ExpectType string
// encoded: '%82%B1%82%F1%82%C9%82%BF%82%CD%81A%82%D9%82%B0%81%99%82%D2%82%E6'

const decoded = Encoding.urlDecode(encoded); // $ExpectType number[]
Expand All @@ -141,11 +129,12 @@ const decoded = Encoding.urlDecode(encoded); // $ExpectType number[]
// 65, 130, 217, 130, 176, 129, 153, 130, 210, 130, 230
// ]

const sjisArray5 = [130, 177, 130, 241, 130, 201, 130, 191, 130, 205];
const encoded2 = Encoding.base64Encode(sjisArray5); // $ExpectType string
const sjisArray6 = [130, 177, 130, 241, 130, 201, 130, 191, 130, 205];
const encoded2 = Encoding.base64Encode(sjisArray6); // $ExpectType string
// encoded2: 'grGC8YLJgr+CzQ=='

const decoded2 = Encoding.base64Decode(encoded2); // $ExpectType number[]
// decoded2: [130, 177, 130, 241, 130, 201, 130, 191, 130, 205]

Encoding.version; // $ExpectType string
Encoding.orders; // $ExpectType string[]