From: Ardis Lu Date: Sat, 9 Sep 2023 03:30:04 +0000 (-0700) Subject: Add *.d.ts files X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=71eeb033a7e6dc27e5b8a82cf9f4188621254b0e;p=static-encrypt Add *.d.ts files --- diff --git a/README.md b/README.md index 310b7b4..bc2d0f8 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,13 @@ You can also import the function dynamically (useful for lazy-loading or testing ```javascript const { decrypt } = await import('https://cdn.statically.io/gh/ardislu/static-encrypt/master/decrypt.js'); ``` + +### TypeScript + +`*.d.ts` files are generated from the [JSDoc](https://jsdoc.app/) comments using `tsc`: + +``` +tsc --declaration --emitDeclarationOnly --allowJs .\decrypt.js .\encrypt.js +``` + +These `*.d.ts` files allow `encrypt` and `decrypt` to be imported in `.ts` files with typing. diff --git a/decrypt.d.ts b/decrypt.d.ts new file mode 100644 index 0000000..1ca1795 --- /dev/null +++ b/decrypt.d.ts @@ -0,0 +1,7 @@ +/** + * Decrypt an encrypted string. + * @param {string} content - The ciphertext to decrypt. + * @param {string} password - The password used to encrypt the string. + * @returns {Promise} A promise that resolves to the plaintext. + */ +export function decrypt(content: string, password: string): Promise; diff --git a/encrypt.d.ts b/encrypt.d.ts new file mode 100644 index 0000000..158def8 --- /dev/null +++ b/encrypt.d.ts @@ -0,0 +1,7 @@ +/** + * Encrypt a string. + * @param {string} plaintext - The string to encrypt. + * @param {string} password - The password used to encrypt the string. + * @returns {Promise} A promise that resolves to the ciphertext. + */ +export function encrypt(plaintext: string, password: string): Promise;