Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timer-hook

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timer-hook - npm Package Compare versions

Comparing version 1.0.4 to 1.0.6

35

lib/useTimer.js

@@ -24,2 +24,8 @@ "use strict";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var TIMER_TYPE = {

@@ -29,16 +35,19 @@ INCREMENT: 'INCREMENT',

};
var defaultConfigs = {
interval: 1000,
initialTime: 0,
step: 1,
endTime: null,
type: TIMER_TYPE.INCREMENT,
onEnd: function onEnd() {}
};
var useTimer = function useTimer(_ref) {
var _ref$interval = _ref.interval,
interval = _ref$interval === void 0 ? 1000 : _ref$interval,
_ref$initialTime = _ref.initialTime,
initialTime = _ref$initialTime === void 0 ? 0 : _ref$initialTime,
_ref$step = _ref.step,
step = _ref$step === void 0 ? 1 : _ref$step,
_ref$endTime = _ref.endTime,
endTime = _ref$endTime === void 0 ? null : _ref$endTime,
_ref$type = _ref.type,
type = _ref$type === void 0 ? TIMER_TYPE.INCREMENT : _ref$type,
_ref$onEnd = _ref.onEnd,
onEnd = _ref$onEnd === void 0 ? function () {} : _ref$onEnd;
var useTimer = function useTimer(config) {
var _defaultConfigs$confi = _objectSpread({}, defaultConfigs, {}, config),
interval = _defaultConfigs$confi.interval,
initialTime = _defaultConfigs$confi.initialTime,
step = _defaultConfigs$confi.step,
endTime = _defaultConfigs$confi.endTime,
type = _defaultConfigs$confi.type;
var isInitialLoad = (0, _react.useRef)(true);

@@ -45,0 +54,0 @@

{
"name": "timer-hook",
"version": "1.0.4",
"version": "1.0.6",
"description": "An easy to use timer hook for React",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -9,10 +9,16 @@ import { useState, useEffect, useRef, useCallback } from 'react';

export const useTimer = ({
interval = 1000,
initialTime = 0,
step = 1,
endTime = null,
type = TIMER_TYPE.INCREMENT,
onEnd = () => { }
}) => {
const defaultConfigs = {
interval: 1000,
initialTime: 0,
step: 1,
endTime: null,
type: TIMER_TYPE.INCREMENT,
onEnd: () => { }
}
export const useTimer = (config) => {
const { interval, initialTime, step, endTime, type } = {
...defaultConfigs,
...config
}
const isInitialLoad = useRef(true);

@@ -19,0 +25,0 @@ const [time, setTime] = useState(initialTime);

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