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

Could not find a declaration file for module 'tai-password-strength' #19

Closed
s3curitybug opened this issue Feb 22, 2021 · 10 comments
Closed

Comments

@s3curitybug
Copy link

Hello.

I'm using this library in the browser. I installed it with npm i tai-password-strength, and I'm getting this warning:

Could not find a declaration file for module 'tai-password-strength'. 'path/to/project/node_modules/tai-password-strength/lib/node.js' implicitly has an 'any' type. Try npm install @types/tai-password-strength if it exists or add a new declaration (.d.ts) file containing declare module 'tai-password-strength';

Everything works fine, but I don't like having the warning... could you take a look at it?

@fidian
Copy link
Contributor

fidian commented Feb 22, 2021

Do you use TypeScript? If so, we could use a contribution to add typings to the JavaScript library.

@s3curitybug
Copy link
Author

Well I use TypeScript but I've never generated a typings file or uploaded any library to npm.

This page describes the process, it does not seem very complicated:

https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html

@s3curitybug
Copy link
Author

Are you trying this or do you want me to do a pull request?

@fidian
Copy link
Contributor

fidian commented Feb 24, 2021 via email

@s3curitybug
Copy link
Author

All right. I cloned this repository and tried the steps in the link. It failed, showing this error: lib/password-strength.js:6:1 - error TS9005: Declaration emit for this file requires using private name 'PasswordStrength'. An explicit type annotation may unblock declaration emit.

It seems a bug in typescript: microsoft/TypeScript#37832

Apparently it will be fixed in the next version. I'll try again in a couple of weeks.

@fidian
Copy link
Contributor

fidian commented Feb 27, 2021

I had a little time to make this version of index.d.ts, but I don't know if it will work. Would you have time to test it out? If it works, or if it provides a base that would work, it would be stellar if you would include it in a pull request.

export interface PassswordStrengthExports {
    PasswordStrength: PasswordStrength;
    commonPasswords: string[];
    trigraphs: PasswordStrengthTrigraphMap;
}

export class PasswordStrength {
    charsets: PasswordStrengthGroups;
    commonPasswords: null | string[];
    trigraph: null | PasswordStrengthTrigraphMap;

    addCommonPasswords(passwords: string[] | string): this;
    addTrigraphMap(map: PasswordStrengthTrigraphMap): this;
    charsetGroups(password: string): { [key: string]: boolean | string };
    charsetSize(groups: PasswordStrengthGroups): number;
    check(password: string): PasswordStrengthStatistics;
    checkCommonPasswords(password: string): boolean;
    checkTrigraph(password: string, charsetSize: number): number;
    determineStrength(status: PasswordStrengthStatistics): PasswordStrengthCode;
    nistScore(password: string): number;
    otherChars(password: string): string;
    shannonScore(password: string): number;
}

export interface PasswordStrengthGroups {
    [key: string]: string;
}

export interface PasswordStrengthTrigraphMap {
    [key: string]: number;
}

export interface PasswordStrengthStatistics {
    charsetSize: number;
    commonPassword: boolean;
    passwordLength: number;
    shannonEntropyBits: number;
    strength: PasswordStrengthCode;
    trigraphEntropyBits: null | number;
}

export enum PasswordStrengthCode {
    VERY_WEAK = "VERY_WEAK",
    WEAK = "WEAK",
    REASONABLE = "REASONABLE",
    STRONG = "STRONG",
    VERY_STRONG = "VERY_STRONG"
}

@s3curitybug
Copy link
Author

It worked! I just had to paste that code into lib/node.d.ts (not index.d.ts)

@fidian
Copy link
Contributor

fidian commented Mar 2, 2021

Published a new version with updated dependencies and the TypeScript file. Would you please confirm it worked?

@s3curitybug
Copy link
Author

I just tested it. It works. Thank you!

@fidian
Copy link
Contributor

fidian commented Mar 2, 2021

Thanks for the help!

@fidian fidian closed this as completed Mar 2, 2021
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

No branches or pull requests

2 participants