Socket
Socket
Sign inDemoInstall

react-compound-timer

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-compound-timer - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

35

build/components/Timer/Timer.js

@@ -0,1 +1,2 @@

"use strict";
var __extends = (this && this.__extends) || (function () {

@@ -25,5 +26,9 @@ var extendStatics = function (d, b) {

};
import React from 'react';
import { TimerModel } from '../../lib/models/TimerModel';
var TimerContext = React.createContext({
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 TimerModel_1 = require("../../lib/models/TimerModel");
var TimerContext = react_1.default.createContext({
ms: 0,

@@ -38,3 +43,3 @@ s: 0,

var unit = _a.unit, formatValue = _a.formatValue;
return (React.createElement(Timer.Consumer, null, function (props) {
return (react_1.default.createElement(Timer.Consumer, null, function (props) {
var format = formatValue || props.formatValue;

@@ -44,7 +49,7 @@ return format(props[unit]) || null;

};
var Milliseconds = function (props) { return (React.createElement(TimerValue, __assign({ unit: "ms" }, props))); };
var Seconds = function (props) { return (React.createElement(TimerValue, __assign({ unit: "s" }, props))); };
var Minutes = function (props) { return (React.createElement(TimerValue, __assign({ unit: "m" }, props))); };
var Hours = function (props) { return (React.createElement(TimerValue, __assign({ unit: "h" }, props))); };
var Days = function (props) { return (React.createElement(TimerValue, __assign({ unit: "d" }, props))); };
var Milliseconds = function (props) { return (react_1.default.createElement(TimerValue, __assign({ unit: "ms" }, props))); };
var Seconds = function (props) { return (react_1.default.createElement(TimerValue, __assign({ unit: "s" }, props))); };
var Minutes = function (props) { return (react_1.default.createElement(TimerValue, __assign({ unit: "m" }, props))); };
var Hours = function (props) { return (react_1.default.createElement(TimerValue, __assign({ unit: "h" }, props))); };
var Days = function (props) { return (react_1.default.createElement(TimerValue, __assign({ unit: "d" }, props))); };
var Timer = /** @class */ (function (_super) {

@@ -55,3 +60,3 @@ __extends(Timer, _super);

var _a = _this.props, initialTime = _a.initialTime, direction = _a.direction, timeToUpdate = _a.timeToUpdate, lastUnit = _a.lastUnit, checkpoints = _a.checkpoints;
_this.timer = new TimerModel({
_this.timer = new TimerModel_1.TimerModel({
initialTime: initialTime,

@@ -81,7 +86,7 @@ direction: direction,

}
if (Array.isArray(children) || React.isValidElement(children)) {
if (Array.isArray(children) || react_1.default.isValidElement(children)) {
return children;
}
if (children.prototype && children.prototype.isReactComponent) {
return React.createElement(children, renderProps);
return react_1.default.createElement(children, renderProps);
}

@@ -104,3 +109,3 @@ if (typeof children === 'function') {

var _c = this.props, formatValue = _c.formatValue, children = _c.children;
return (React.createElement(TimerContext.Provider, { value: { ms: ms, s: s, m: m, h: h, d: d, formatValue: formatValue } }, Timer.getUI(children, {
return (react_1.default.createElement(TimerContext.Provider, { value: { ms: ms, s: s, m: m, h: h, d: d, formatValue: formatValue } }, Timer.getUI(children, {
start: start,

@@ -176,4 +181,4 @@ resume: resume,

return Timer;
}(React.PureComponent));
export default Timer;
}(react_1.default.PureComponent));
exports.default = Timer;
//# sourceMappingURL=Timer.js.map

@@ -1,6 +0,15 @@

import React, { useEffect } from 'react';
import { useTimer } from 'src/hook/useTimer';
export var TimerOnHooks = function () {
var _a = useTimer({ initialTime: 3000 }), value = _a.value, controls = _a.controls;
useEffect(function () {
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var useTimer_1 = require("src/hook/useTimer");
exports.TimerOnHooks = function () {
var _a = useTimer_1.useTimer({ initialTime: 3000 }), value = _a.value, controls = _a.controls;
react_1.useEffect(function () {
controls.setCheckpoints([

@@ -24,3 +33,3 @@ {

}
return (React.createElement("div", null,
return (react_1.default.createElement("div", null,
value.s,

@@ -27,0 +36,0 @@ " s ",

@@ -0,1 +1,2 @@

"use strict";
var __assign = (this && this.__assign) || function () {

@@ -12,10 +13,14 @@ __assign = Object.assign || function(t) {

};
import { useState, useMemo, useCallback, useEffect } from "react";
import { TimerModel } from '../lib/models/TimerModel';
import getTimeParts from "../lib/helpers/getTimeParts";
export function useTimer(_a) {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var TimerModel_1 = require("../lib/models/TimerModel");
var getTimeParts_1 = __importDefault(require("../lib/helpers/getTimeParts"));
function useTimer(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.initialTime, initialTime = _c === void 0 ? 0 : _c, _d = _b.direction, direction = _d === void 0 ? "forward" : _d, _e = _b.timeToUpdate, timeToUpdate = _e === void 0 ? 1000 : _e, _f = _b.startImmediately, startImmediately = _f === void 0 ? true : _f, _g = _b.lastUnit, lastUnit = _g === void 0 ? "d" : _g, _h = _b.checkpoints, checkpoints = _h === void 0 ? [] : _h, onStart = _b.onStart, onResume = _b.onResume, onPause = _b.onPause, onStop = _b.onStop, onReset = _b.onReset;
var _j = useState(__assign({}, getTimeParts(initialTime, lastUnit), { state: 'INITED' })), timerValues = _j[0], setTimerValues = _j[1];
var timer = useMemo(function () {
return new TimerModel({
var _j = react_1.useState(__assign({}, getTimeParts_1.default(initialTime, lastUnit), { state: 'INITED' })), timerValues = _j[0], setTimerValues = _j[1];
var timer = react_1.useMemo(function () {
return new TimerModel_1.TimerModel({
initialTime: initialTime,

@@ -31,13 +36,13 @@ direction: direction,

}, []);
var setTime = useCallback(function (time) { return timer.setTime(time); }, [timer]);
var getTime = useCallback(function () { return timer.getTime(); }, [timer]);
var getTimerState = useCallback(function () { return timer.state; }, [timer]);
var setDirection = useCallback(function (direction) { return timer.setDirection(direction); }, [timer]);
var setCheckpoints = useCallback(function (checkpoints) { return timer.setCheckpoints(checkpoints); }, [timer]);
var start = useCallback(function () { timer.start(); onStart && onStart(); }, [timer, onStart]);
var stop = useCallback(function () { timer.stop(); onStop && onStop(); }, [timer, onStop]);
var pause = useCallback(function () { timer.pause(); onPause && onPause(); }, [timer, onPause]);
var reset = useCallback(function () { timer.reset(); onReset && onReset(); }, [timer, onReset]);
var resume = useCallback(function () { timer.reset(); onResume && onResume(); }, [timer, onResume]);
var controls = useMemo(function () { return ({
var setTime = react_1.useCallback(function (time) { return timer.setTime(time); }, [timer]);
var getTime = react_1.useCallback(function () { return timer.getTime(); }, [timer]);
var getTimerState = react_1.useCallback(function () { return timer.state; }, [timer]);
var setDirection = react_1.useCallback(function (direction) { return timer.setDirection(direction); }, [timer]);
var setCheckpoints = react_1.useCallback(function (checkpoints) { return timer.setCheckpoints(checkpoints); }, [timer]);
var start = react_1.useCallback(function () { timer.start(); onStart && onStart(); }, [timer, onStart]);
var stop = react_1.useCallback(function () { timer.stop(); onStop && onStop(); }, [timer, onStop]);
var pause = react_1.useCallback(function () { timer.pause(); onPause && onPause(); }, [timer, onPause]);
var reset = react_1.useCallback(function () { timer.reset(); onReset && onReset(); }, [timer, onReset]);
var resume = react_1.useCallback(function () { timer.reset(); onResume && onResume(); }, [timer, onResume]);
var controls = react_1.useMemo(function () { return ({
start: start,

@@ -57,3 +62,3 @@ stop: stop,

]);
useEffect(function () {
react_1.useEffect(function () {
if (startImmediately) {

@@ -71,2 +76,3 @@ start();

}
exports.useTimer = useTimer;
//# sourceMappingURL=useTimer.js.map

@@ -1,5 +0,10 @@

import Timer from './components/Timer/Timer';
import { useTimer } from './hook/useTimer';
export { useTimer, };
export default Timer;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var Timer_1 = __importDefault(require("./components/Timer/Timer"));
var useTimer_1 = require("./hook/useTimer");
exports.useTimer = useTimer_1.useTimer;
exports.default = Timer_1.default;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,4 @@

export default function getTimeParts(time, lastUnit) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getTimeParts(time, lastUnit) {
var units = ['ms', 's', 'm', 'h', 'd'];

@@ -27,2 +29,3 @@ var lastUnitIndex = units.findIndex(function (unit) { return unit === lastUnit; });

}
exports.default = getTimeParts;
//# sourceMappingURL=getTimeParts.js.map

@@ -1,3 +0,8 @@

import getTimeParts from '../helpers/getTimeParts';
import TimerState from './TimerState';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var getTimeParts_1 = __importDefault(require("../helpers/getTimeParts"));
var TimerState_1 = __importDefault(require("./TimerState"));
var TimerModel = /** @class */ (function () {

@@ -12,3 +17,3 @@ function TimerModel(_a) {

this.checkpoints = checkpoints;
this.innerState = new TimerState(onChange);
this.innerState = new TimerState_1.default(onChange);
this.onChange = onChange;

@@ -32,3 +37,3 @@ this.timerId = null;

TimerModel.prototype.getTimeParts = function (time) {
return getTimeParts(time, this.lastUnit);
return getTimeParts_1.default(time, this.lastUnit);
};

@@ -115,3 +120,3 @@ TimerModel.prototype.setTime = function (time) {

}());
export { TimerModel };
exports.TimerModel = TimerModel;
//# sourceMappingURL=TimerModel.js.map

@@ -1,5 +0,7 @@

export var INITED = 'INITED';
export var PLAYING = 'PLAYING';
export var PAUSED = 'PAUSED';
export var STOPPED = 'STOPPED';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.INITED = 'INITED';
exports.PLAYING = 'PLAYING';
exports.PAUSED = 'PAUSED';
exports.STOPPED = 'STOPPED';
var TimerState = /** @class */ (function () {

@@ -9,5 +11,5 @@ function TimerState(onChangeStatus) {

if (onChangeStatus === void 0) { onChangeStatus = function (obj) { }; }
this.state = INITED;
this.state = exports.INITED;
this.onChange = function () { return onChangeStatus({ state: _this.state }); };
this.state = INITED;
this.state = exports.INITED;
}

@@ -18,6 +20,6 @@ TimerState.prototype.getState = function () {

TimerState.prototype.setInited = function () {
if (this.state === INITED) {
if (this.state === exports.INITED) {
return false;
}
this.state = INITED;
this.state = exports.INITED;
this.onChange();

@@ -27,9 +29,9 @@ return true;

TimerState.prototype.isInited = function () {
return this.state === INITED;
return this.state === exports.INITED;
};
TimerState.prototype.setPlaying = function () {
if (this.state === PLAYING) {
if (this.state === exports.PLAYING) {
return false;
}
this.state = PLAYING;
this.state = exports.PLAYING;
this.onChange();

@@ -39,9 +41,9 @@ return true;

TimerState.prototype.isPlaying = function () {
return this.state === PLAYING;
return this.state === exports.PLAYING;
};
TimerState.prototype.setPaused = function () {
if (this.state !== PLAYING) {
if (this.state !== exports.PLAYING) {
return false;
}
this.state = PAUSED;
this.state = exports.PAUSED;
this.onChange();

@@ -51,9 +53,9 @@ return true;

TimerState.prototype.isPaused = function () {
return this.state === PAUSED;
return this.state === exports.PAUSED;
};
TimerState.prototype.setStopped = function () {
if (this.state === INITED) {
if (this.state === exports.INITED) {
return false;
}
this.state = STOPPED;
this.state = exports.STOPPED;
this.onChange();

@@ -63,7 +65,7 @@ return true;

TimerState.prototype.isStopped = function () {
return this.state === STOPPED;
return this.state === exports.STOPPED;
};
return TimerState;
}());
export default TimerState;
exports.default = TimerState;
//# sourceMappingURL=TimerState.js.map

@@ -1,2 +0,4 @@

export default {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
ms: 'ms',

@@ -3,0 +5,0 @@ s: 's',

@@ -0,1 +1,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=index.js.map
{
"name": "react-compound-timer",
"version": "1.1.3",
"version": "1.1.4",
"description": "Timer compound react component",

@@ -5,0 +5,0 @@ "main": "build",

{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"module": "commonjs",
"esModuleInterop": true,
"moduleResolution": "node",

@@ -6,0 +7,0 @@ "allowSyntheticDefaultImports": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc