From db9dcf643ae35755fe5e3cba188166b6bdcc7be8 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Wed, 4 Nov 2020 09:53:47 +0000 Subject: [PATCH] Added some missing config files. Added rollup to build distribution js files. --- package-lock.json | 9 +++++++++ package.json | 4 +++- rollup.config.js | 17 +++++++++++++++++ ts-lib/carparc-calc.d.ts | 36 ++++++++++++++++++++++++++++++++++++ tsconfig.json | 12 ++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 rollup.config.js create mode 100644 ts-lib/carparc-calc.d.ts create mode 100644 tsconfig.json diff --git a/package-lock.json b/package-lock.json index e93d11f..5efe013 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3344,6 +3344,15 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "2.33.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.33.1.tgz", + "integrity": "sha512-uY4O/IoL9oNW8MMcbA5hcOaz6tZTMIh7qJHx/tzIJm+n1wLoY38BLn6fuy7DhR57oNFLMbDQtDeJoFURt5933w==", + "dev": true, + "requires": { + "fsevents": "~2.1.2" + } + }, "run-parallel": { "version": "1.1.10", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.10.tgz", diff --git a/package.json b/package.json index 787c33d..0d1fec9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test:js": "mocha test/**/*.js", "test:ts": "mocha -r ts-node/register test/**/*.ts", "lint": "eslint . --ext .ts", - "coverage": "nyc npm run test:js" + "coverage": "nyc npm run test:js", + "build:js": "rollup -c rollup.config.js" }, "keywords": [], "author": "Martin Donnelly", @@ -23,6 +24,7 @@ "expect.js": "^0.3.1", "mocha": "^8.2.1", "nyc": "^15.1.0", + "rollup": "^2.33.1", "ts-node": "^9.0.0", "typings": "^2.1.1" }, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..fe81c59 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,17 @@ +export default { + input: 'lib/carpark.js', + output: [ + { + file: 'dist/carpark.js', + format: 'umd', + name: 'carpark', + sourcemap: true + }, + { + file: 'dist/carpark.mjs', + format: 'es', + sourcemap: true + } + ], + plugins: [] +}; diff --git a/ts-lib/carparc-calc.d.ts b/ts-lib/carparc-calc.d.ts new file mode 100644 index 0000000..6839ee5 --- /dev/null +++ b/ts-lib/carparc-calc.d.ts @@ -0,0 +1,36 @@ +declare class Carpark { + private _startDT; + private _endDT; + private _dayLength; + private _hourLength; + private _validDays; + private _validStart; + private _validEnd; + private _longPrice; + private _shortPrice; + private _secondPrice; + /** + * Check if a specific timestamp is a valid date + * @param workTime + */ + private _isValidTime; + /** + * Calculate short term parking costs + */ + private _calcShortTerm; + /** + * Calculate long term parking costs + * @returns {number} + * @private + */ + private _calcLongTerm; + /** + * The public calculate method + * @param start + * @param end + * @param mode + * @returns {number} + */ + calculate(start: string, end: string, mode?: string): number; +} +export default Carpark; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b4e1750 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "outFile": "./dist/carpark-tsc.js", + "sourceMap": true + }, + "include": ["ts-lib/**/*"], + "exclude": ["node_modules", "test/**/*.ts"] +}