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

@danielpiva/countdown.js

v1.1.0

Published

### Como Instalar

Downloads

6

Readme

CountDown.js

Como Instalar

Você pode instalar a biblioteca em seu projeto duas diferentes formas.

1. CDN

A função construtura CountDown estará disponível no escopo global.

// CSS
<head>
  <link rel="stylesheet" type="text/css" href="https://unpkg.com/@danielpiva/countdown.js/dist/index.css">
</head>


// JavaScript
<script src="https://unpkg.com/@danielpiva/countdown.js/dist/index.js"></script>

2. Webpack/Parcel

Primeiro adicione à suas dependências
npm i @danielpiva/countdown.js --save

### ou

yarn add @danielpiva/countdown.js
Em seguida, importe em seu projeto

import CountDown from '@danielpiva/count-down.js/dist';

import '@danielpiva/countdown.js/dist/index.css';

// ou

const CountDown = require('@danielpiva/count-down.js/dist').default;

require('@danielpiva/countdown.js/dist/index.css');

Como Usar

Para instanciar um CountDown, passe uma refêrencia de um elemento DOM ou apenas um seletor, como no snippet abaixo.

É importante ressaltar que para a palavra new antes da chamada é obrigatória, caso contrário você irá obter um erro de runtime.

O count down será inicializado e renderizado somente após a chamada do método start;

É necessário que a data passada para o count down seja maior do que a data atual, nem que um milisegundo, caso contrário você irá obter um erro.

Básico
<html lang="pt-BR">
    <head>
    </head>
    <body>
        <div id="meu-count-down"></div>
    </body>
</html>

const meuCountDown = new CountDown('#meu-count-down', {
    until: new Date(2020, 1, 1)
});

meuCountDown.start();
Opções

const countDown = new CountDown('#meu-count-down', {
    until: new Date(2020, 1, 1),
    // ou 
    date: new Date(2020, 1, 1),

    locale: {
        days: 'Dias',
        hours: 'Hours',
        minutes: 'Minutos',
        seconds: 'Seconds'
    }
});


// Você pode passar a data pelo método start também
countDown.start(new Date(2020, 1, 1));
Métodos

const countDown = new CountDown('#meu-count-down', {
    until: new Date(2020)
});

countDown.start();

countDown.pause();

countDown.resume();

countDown.destroy();
Eventos

Lembre-se de registrar os handlers antes de chamar o método start, caso contrário você poderá perder os eventos.


const countDown = new CountDown('#meu-count-down');

// Escutando a eventos
countDown.on('start', console.log);
countDown.on('pause', console.log);
countDown.on('resume', console.log);
countDown.on('render', console.log);
countDown.on('destroy', console.log);
countDown.on('end', console.log);

// Removendo handlers de eventos
countDown.off('start', console.log);
countDown.off('pause', console.log);
countDown.off('resume', console.log);
countDown.off('render', console.log);
countDown.off('destroy', console.log);
countDown.off('end', console.log);

countDown.start(new Date(2020, 1, 1));

Métodos

| Nome | Descrição | Parâmetros | Retorno | |:------------- |:--------------|:------------- |:--------------------| | start | Inicializa o timer e dispara a primeira renderização. | date: Date | -| | pause | Pausa o Count Down. | - | - | | resume | Dá play no Count Down, caso esteja pausado. | - | -| | on | Registra handler passado para um evento. | event: String handler: Function | handler: Function| | off | Retira o handler de um evento, caso a referência passada seja encontrada na lista de handlers, caso contrário retira todos. | event: String handler: Function | - | | destroy | Destrói o Count Down. Retira todos os elementos criados do DOM. | - | - | | forceUpdate | Força um update e re-render no Count Down. | - | -|

Eventos

| Nome | Descrição | Argumentos | |:------------- |:--------------|:------------- | | start | Inicializa o timer e dispara a primeira renderização. | date | | pause | Pausa o Count Down. | - | - | | resume | Dá play no Count Down, caso esteja pausado. | - | | destroy | Destrói o Count Down. Retira todos os elementos criados do DOM. | - | | end | Força um update e re-render no Count Down. | - |