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

Add Type Information for Bidi JS #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yasarsid
Copy link

@yasarsid yasarsid commented Jan 21, 2025

Adding Types for Bidi JS

Overview

In this PR we are adding type information for Bidi JS. This aims to fix the issue #11.
There are a few opinion based choices - would love a review there.

Summary of the changes

  1. Added typescript as a dev dependency and generate the types as part of the build. The types are generated from the bidi.js and bidi.mjs files.
  2. In the rollup.config removed the default function of bidiFactory, added it as a named export in index.js. It is still the top level encapsulation. I felt like the bidi factory should be defined as part of the code instead of the configuration. (This is one of the opinion based decisions)
  3. This might a breaking change - so updated the major version in package.json.
  4. Made changes in the test to consider a named export instead of a default export

Other minor changes

  1. There were a few crashes in the tests, added some additional checks to ensure that the tests run.
  2. In package-lock.json fixed for known vulnerbilities.

Validations

  • Ran the build and tests locally
  • validated the output bidi.js and bidi.d.ts, included them in a local repo to check if the correct types were picked.

Artefacts

Attaching the generate d.ts, since its in the dist/ it is ignored.

export const __esModule: boolean;
export function bidiFactory(): {
    getEmbeddingLevels: (string: string, baseDirection?: "ltr" | "rtl" | "auto") => {
        paragraphs: {
            start: any;
            end: any;
            level: any;
        }[];
        levels: Uint8Array;
    };
    getReorderSegments: (string: string, embeddingLevelsResult: {
        paragraphs: {
            start: any;
            end: any;
            level: any;
        }[];
        levels: Uint8Array;
    }, start?: number, end?: number) => number[][];
    getReorderedIndices: (string: string, embedLevelsResult: {
        paragraphs: {
            start: any;
            end: any;
            level: any;
        }[];
        levels: Uint8Array;
    }, start?: number, end?: number) => number[];
    getReorderedString: (string: string, embedLevelsResult: {
        paragraphs: {
            start: any;
            end: any;
            level: any;
        }[];
        levels: Uint8Array;
    }, start?: number, end?: number) => string;
    getBidiCharType: (char: string) => number;
    getBidiCharTypeName: (char: any) => any;
    getMirroredCharacter: (char: any) => any;
    getMirroredCharactersMap: (string: any, embeddingLevels: any, start?: any, end?: any) => Map<number, string>;
    closingToOpeningBracket: (char: any) => any;
    openingToClosingBracket: (char: any) => any;
    getCanonicalBracket: (char: any) => any;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant