npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-timer

v0.4.0

Published

countdown timer,Sms and email sending limit | 定时器,可用于限制短信邮件发送限制。

Downloads

46

Readme

timer

可复用定时器,可用于限制邮件短信发送

Online demo: https://fast-flow.github.io/timer/

Features

  • React
  • DOM function
  • Cache second (localStorage or cookie)
  • DIY
npm install fast-timer --save
.m-btn {
    background-color: #999;border:none;
}
html .m-btn--timing {
    background-color: #eee;
}

fast-timer/react

timer.react

fast-timer/btn

Send

var timerBtn = require('fast-timer/lib/btn')
var btn = document.getElementById('btn')
var btnSendAjax = false
timerBtn(btn, {
    sec: 5,
    // cache: refresh page auto start | 缓存: 刷新页面自动开始计时
    cache: 'some242358',
    timingClass: 'm-btn--timing',
    trigger: function (start) {
        console.log('btn trigger')
        if (btnSendAjax) {
            return
        }
        else {
            btnSendAjax = true
        }
        // mock send ajax timeout
        setTimeout(function () {
            console.log('btn start')
            btnSendAjax = false
            start()
        }, 1000)
    },
    watch: function (date) {
        if (date.sec) {
            return date.sec + 's'
        }
        else {
            return 'Resend'
        }
    }
})

click

DIY | 使用API定制开发

simple

var Timer = require('fast-timer')

var time = new Timer()
var demo = document.getElementById('demo')
// 定时回调
time.watch(function (date) {
    console.log('second:' + date.sec)
    console.log('free:' + time.free)
    if (date.sec === 0) {
        demo.innerHTML = 'done'
    }
    else {
        demo.innerHTML = date.sec
    }
})
demo.onclick = function (){
    if (time.free) {
        time.start(10)
    }
}

cache

cache

var Timer = require('fast-timer')
var time = new Timer({
    cache: 'abc'
})
var cacheBtn = document.getElementById('cacheBtn')
if (time.cacheSec()) {
    time.start(time.cacheSec())
    cacheBtn.innerHTML = time.cacheSec()
}
time.watch(function (date) {
    console.log('second:' + date.sec)
    console.log('free:' + time.free)
    if (date.sec === 0) {
        cacheBtn.innerHTML = 'done'
    }
    else {
        cacheBtn.innerHTML = date.sec
    }
})
cacheBtn.onclick = function () {
    if (time.free) {
        time.start(10)
    }
}

React - simple

var Timer = require('fast-timer')
var React = require('react')
var ReactDOM = require('react-dom')
var App = React.createClass({
    getInitialState: function () {
        return {
            sec: 0
        }
    },
    componentWillMount: function () {
        var self = this
        self.time = new Timer()
        self.time.watch(function (date) {
            self.setState({
                sec: date.sec
            })
        })
    },
    startTimer: function () {
        if (this.time.free) {
            this.time.start(this.props.sec)
        }
    },
    render: function () {
        return (
            <button onClick={this.startTimer}>
            {this.state.sec?this.state.sec:'click'}
            </button>
        )
    }
})
ReactDOM.render(<App sec={10} />, document.getElementById('react1'))

React - cache

var Timer = require('fast-timer')
var React = require('react')
var ReactDOM = require('react-dom')
var App = React.createClass({
    getInitialState: function () {
        return {
            sec: 0
        }
    },
    componentWillMount: function () {
        var self = this
        self.time = new Timer({
            cache: 'abc'
        })
        self.time.watch(function (date) {
            self.setState({
                sec: date.sec
            })
        })
        if (self.time.cacheSec()) {
            self.time.start(self.time.cacheSec())
        }
    },
    startTimer: function () {
        if (this.time.free) {
            this.time.start(this.props.sec)
        }
    },
    render: function () {
        return (
            <button onClick={this.startTimer}>
            {this.state.sec?this.state.sec:'click'}
            </button>
        )
    }
})
ReactDOM.render(<App sec={10} />, document.getElementById('reactCache'))

development | 参与开发

git clone
cd timer
npm run update
npm run dev
npm run s