Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS bugfix, export top-level indexer #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
56 changes: 30 additions & 26 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
/* codepage.js (C) 2013-present SheetJS -- http://sheetjs.com */
// TypeScript Version: 2.2

/** Codepage index type (integer or string representation) */
export type CP$Index = number | string;
declare namespace cptable {
/** Codepage index type (integer or string representation) */
export type CP$Index = number | string;

/* Individual codepage converter */
export interface CP$Conv {
enc: {[n: string]: number; };
dec: {[n: number]: string; };
}

/** Encode input type (string, array of characters, Buffer) */
export type CP$String = string | string[] | Uint8Array;

/** Encode output / decode input type */
export type CP$Data = string | number[] | Uint8Array;

/** General utilities */
export interface CP$Utils {
decode(cp: CP$Index, data: CP$Data): string;
encode(cp: CP$Index, data: CP$String, opts?: any): CP$Data;
hascp(n: number): boolean;
magic: {[cp: string]: string};
}

/* Individual codepage converter */
export interface CP$Conv {
enc: {[n: string]: number; };
dec: {[n: number]: string; };
}

/** Encode input type (string, array of characters, Buffer) */
export type CP$String = string | string[] | Uint8Array;

/** Encode output / decode input type */
export type CP$Data = string | number[] | Uint8Array;

/** General utilities */
export interface CP$Utils {
decode(cp: CP$Index, data: CP$Data): string;
encode(cp: CP$Index, data: CP$String, opts?: any): CP$Data;
hascp(n: number): boolean;
magic: {[cp: string]: string};
}

/* note: TS cannot export top-level indexer, hence default workaround */
export interface CP$Module {
interface CP$Module {
/** Version string */
version: string;

/** Utility Functions */
utils: CP$Utils;
utils: cptable.CP$Utils;

/** Codepage Converters */
[cp: number]: CP$Conv;
[cp: number]: cptable.CP$Conv;
}
export const cptable: CP$Module;
export default cptable;

declare const cptable:CP$Module;

export = cptable;