From d67207101362c7ea83eea215cf88a59fcd66dc51 Mon Sep 17 00:00:00 2001 From: Leonardo Jr Date: Wed, 21 Feb 2024 10:19:55 -0300 Subject: [PATCH 1/3] Adding types --- package.json | 4 +++- tsconfig.json | 11 +++++++++++ yarn.lock | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index dcffb947..c757f553 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "node": ">=0.3.1" }, "main": "./lib/index.js", + "types": "./lib/index.d.js", "module": "./lib/index.es6.js", "browser": "./dist/diff.js", "unpkg": "./dist/diff.js", @@ -43,7 +44,7 @@ }, "scripts": { "clean": "rm -rf lib/ dist/", - "build:node": "yarn babel --out-dir lib --source-maps=inline src", + "build:node": "tsc && yarn babel --out-dir lib --source-maps=inline src", "test": "grunt" }, "devDependencies": { @@ -82,6 +83,7 @@ "rollup": "^1.0.2", "rollup-plugin-babel": "^4.2.0", "semver": "^7.3.2", + "typescript": "^5.3.3", "webpack": "^4.28.3", "webpack-dev-server": "^3.1.14" }, diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..fd769a69 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "include": ["src/**/*"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "lib", + "declarationMap": true + } +} + diff --git a/yarn.lock b/yarn.lock index c0e781df..1d026613 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8268,6 +8268,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +typescript@^5.3.3: + version "5.3.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== + ua-parser-js@^0.7.21, ua-parser-js@^0.7.30: version "0.7.37" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.37.tgz#e464e66dac2d33a7a1251d7d7a99d6157ec27832" From 1489fe9f75b198d480d514a10f045c7247ed2894 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Tue, 12 Mar 2024 14:59:02 +0000 Subject: [PATCH 2/3] Begin dabbling with adding JSDoc types. (Still some things to figure out, plus most of the work to do...) --- src/diff/character.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/diff/character.js b/src/diff/character.js index e9f17b11..881d8c76 100644 --- a/src/diff/character.js +++ b/src/diff/character.js @@ -1,4 +1,22 @@ import Diff from './base'; export const characterDiff = new Diff(); + +// TODO: Add more common options +// TODO: Move to base.js and import +/** + * @typedef BaseDiffOptions + * @property {number} [timeout] + */ + +/** + * @typedef DiffCharsOptions + * @property {boolean} [ignoreCase] + */ + +/** + * @param {string} oldStr + * @param {string} newStr + * @param {DiffCharsOptions & BaseDiffOptions} [options] + */ export function diffChars(oldStr, newStr, options) { return characterDiff.diff(oldStr, newStr, options); } From 021a7d8ae52306c07dfacd8fe4d7ada7e405dc7e Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Tue, 12 Mar 2024 15:24:18 +0000 Subject: [PATCH 3/3] Maybe improve things? --- src/diff/character.js | 10 ++-------- src/typedefs.js | 9 +++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 src/typedefs.js diff --git a/src/diff/character.js b/src/diff/character.js index 881d8c76..b113e60c 100644 --- a/src/diff/character.js +++ b/src/diff/character.js @@ -1,14 +1,8 @@ import Diff from './base'; +const typedefs = require('../typedefs'); export const characterDiff = new Diff(); -// TODO: Add more common options -// TODO: Move to base.js and import -/** - * @typedef BaseDiffOptions - * @property {number} [timeout] - */ - /** * @typedef DiffCharsOptions * @property {boolean} [ignoreCase] @@ -17,6 +11,6 @@ export const characterDiff = new Diff(); /** * @param {string} oldStr * @param {string} newStr - * @param {DiffCharsOptions & BaseDiffOptions} [options] + * @param {DiffCharsOptions & typedefs.BaseDiffOptions} [options] */ export function diffChars(oldStr, newStr, options) { return characterDiff.diff(oldStr, newStr, options); } diff --git a/src/typedefs.js b/src/typedefs.js new file mode 100644 index 00000000..ef8c78cc --- /dev/null +++ b/src/typedefs.js @@ -0,0 +1,9 @@ +// TODO: Add callback +/** + * @typedef BaseDiffOptions + * @property {number} [maxEditLength] + * @property {number} [timeout] + * @property {boolean} [oneChangePerToken] + */ + +export {};