From 5e29994ed933c57edff896eb815b817a33775780 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Sat, 19 Sep 2020 07:58:06 +0700 Subject: [PATCH] updated the tests and package --- __test__/index.ts | 3 +++ dist/index.d.ts | 1 - dist/index.js | 8 ------- dist/useCountdown.d.ts | 12 ---------- dist/useCountdown.js | 54 ------------------------------------------ example/package.json | 2 +- tsconfig.json | 2 +- 7 files changed, 5 insertions(+), 77 deletions(-) create mode 100644 __test__/index.ts delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/useCountdown.d.ts delete mode 100644 dist/useCountdown.js diff --git a/__test__/index.ts b/__test__/index.ts new file mode 100644 index 0000000..dd949e7 --- /dev/null +++ b/__test__/index.ts @@ -0,0 +1,3 @@ +function sumTest () { + console.log(1+2) +} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 0174f99..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as useCountdown } from './useCountdown'; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 03a1634..0000000 --- a/dist/index.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.useCountdown = void 0; -var useCountdown_1 = require("./useCountdown"); -Object.defineProperty(exports, "useCountdown", { enumerable: true, get: function () { return __importDefault(useCountdown_1).default; } }); diff --git a/dist/useCountdown.d.ts b/dist/useCountdown.d.ts deleted file mode 100644 index d1c80e9..0000000 --- a/dist/useCountdown.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -interface useCountdownOptions { - now?: () => Date; - onEnd?: () => void; - onCount?: (timeLeft: number) => void; - step?: number; -} -interface CountdownHookResult { - timeleft: number; - start: (timeLeft: number) => void; -} -declare function useCountdown(options?: useCountdownOptions): CountdownHookResult; -export default useCountdown; diff --git a/dist/useCountdown.js b/dist/useCountdown.js deleted file mode 100644 index e1c8f47..0000000 --- a/dist/useCountdown.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var react_1 = __importDefault(require("react")); -var DEFAULT_OPTIONS = { - step: 1000, -}; -function useCountdown(options) { - var _a = react_1.default.useState(), timeleft = _a[0], setTimeleft = _a[1]; - var _b = react_1.default.useState(), targetDatetime = _b[0], setTargetDatetime = _b[1]; - var _c = __assign(__assign({}, DEFAULT_OPTIONS), options), step = _c.step, onCount = _c.onCount, onEnd = _c.onEnd; - var start = function (countAsM) { - setTimeleft(countAsM); - }; - var varTimeout = null; - react_1.default.useEffect(function () { - return function () { return clearTimeout(varTimeout); }; - }, []); - react_1.default.useEffect(function () { - if (timeleft === undefined) { - return; - } - var newTimeleft = timeleft - step; - if (newTimeleft < 0) { - setTimeleft(0); - onEnd === null || onEnd === void 0 ? void 0 : onEnd(); - } - else { - onCount === null || onCount === void 0 ? void 0 : onCount(timeleft); - varTimeout = setTimeout(function () { - setTimeleft(newTimeleft); - }, step); - } - }, [timeleft]); - var result = { - timeleft: timeleft || 0, - start: start, - }; - return result; -} -exports.default = useCountdown; diff --git a/example/package.json b/example/package.json index 2329462..42d2762 100644 --- a/example/package.json +++ b/example/package.json @@ -6,7 +6,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", "@testing-library/user-event": "^7.1.2", - "cubetiq-react-use-countdown": "link:../", + "@cubetiq/react-use-countdown": "link:../", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.3" diff --git a/tsconfig.json b/tsconfig.json index 9ccd839..09f142e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -64,7 +64,7 @@ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, "include": [ - "src" + "src", "__test__" ], "exclude": ["node_modules", "**/*.spec.ts"]