### ES Module Installation and Usage of simplycountdown.js Source: https://context7.com/vincentloy/simplycountdown.js/llms.txt Demonstrates how to install and use simplycountdown.js via npm within an ES Module environment. It covers basic import, CSS inclusion, initializing the countdown after the DOM is loaded, and provides specific examples for Vue 3 and React component integration. Includes instructions for installing the package. ```javascript // Install via npm // npm install simplycountdown.js // Basic import and usage import simplyCountdown from "simplycountdown.js"; import "simplycountdown.js/dist/themes/default.css"; // Initialize after DOM load document.addEventListener("DOMContentLoaded", () => { simplyCountdown(".countdown", { year: 2025, month: 12, day: 25 }); }); // Vue 3 component usage import { onMounted, ref } from "vue"; import simplyCountdown from "simplycountdown.js"; export default { setup() { const countdownRef = ref(null); onMounted(() => { const controller = simplyCountdown(countdownRef.value, { year: 2025, month: 6, day: 1, onEnd: () => { console.log("Countdown finished"); } }); }); return { countdownRef }; } }; // React component usage import React, { useEffect, useRef } from "react"; import simplyCountdown from "simplycountdown.js"; function CountdownTimer() { const countdownRef = useRef(null); useEffect(() => { const controller = simplyCountdown(countdownRef.current, { year: 2025, month: 12, day: 31, zeroPad: true }); return () => { controller.stopCountdown(); }; }, []); return
; } ``` -------------------------------- ### Build Documentation Site Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md This command generates the documentation website for the simplycountdown.js project, providing guides, examples, and API references. ```bash npm run build:docs ``` -------------------------------- ### Install Development Dependencies with Bun Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/CONTRIBUTING.md Installs the necessary project dependencies using the Bun package manager. Bun is recommended for its performance and seamless dependency management. ```bash bun install ``` -------------------------------- ### Install SimplyCountdown.js using Package Managers Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Instructions for installing the simplycountdown.js package using npm, yarn, or bun. These commands are used to add the library to your project's dependencies. ```bash npm install simplycountdown.js # or yarn add simplycountdown.js # or bun install simplycountdown.js ``` -------------------------------- ### Start Development Server Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/CONTRIBUTING.md Runs a development server with Vite, which automatically updates sources from `src/core` and allows testing new features in the `docs/src` directory. Changes in the documentation files will refresh the development page. ```bash bun run dev ``` -------------------------------- ### Prepare HTML for SimplyCountdown.js Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Example HTML structure required to initialize SimplyCountdown.js. A target div with a specific class is needed to host the countdown timer. ```html ``` -------------------------------- ### Install simplyCountdown.js with npm, yarn, pnpm, or bun Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/src/index.html This snippet demonstrates how to install the simplyCountdown.js library using various popular JavaScript package managers. It shows the specific commands for npm, yarn, pnpm, and bun. ```bash npm install simplycountdown.js ``` ```bash yarn add simplycountdown.js ``` ```bash pnpm install simplycountdown.js ``` ```bash bun install simplycountdown.js ``` -------------------------------- ### SimplyCountdown.js Configuration Options Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Detailed example of how to configure SimplyCountdown.js with various options. This includes setting the target date, customizing words, display options, styling classes, formatting, and event handlers. ```javascript // .my-super-countdown is an example // you can target any HTML element with any CSS selector simplyCountdown(".my-super-countdown", { // Target date (Required) year: 2025, // Target year [YYYY] month: 12, // Target month [1-12] day: 25, // Target day [1-31] hours: 0, // Target hours [0-23] minutes: 0, // Target minutes [0-59] seconds: 0, // Target seconds [0-59] // Words customization words: { days: { // Function to handle pluralization lambda: (root, count) => (count > 1 ? root + "s" : root), root: "day", // Base word for days }, hours: { lambda: (root, count) => (count > 1 ? root + "s" : root), root: "hour", }, minutes: { lambda: (root, count) => (count > 1 ? root + "s" : root), root: "minute", }, seconds: { lambda: (root, count) => (count > 1 ? root + "s" : root), root: "second", }, }, // Display options plural: true, // Enable/disable pluralization inline: false, // Display inline (true) or in blocks (false) inlineSeparator: ", ", // Separator for inline display enableUtc: false, // Use UTC time instead of local time // Styling classes inlineClass: "simply-countdown-inline", // Class for inline display sectionClass: "simply-section", // Class for each time unit section amountClass: "simply-amount", // Class for number display wordClass: "simply-word", // Class for word display // Formatting options zeroPad: false, // Add leading zeros to numbers (e.g., 05 instead of 5) countUp: false, // Count up from target date instead of down to it removeZeroUnits: false, // Hide time units when they reach zero refresh: 1000, // Update interval in milliseconds (1 second = 1000) // Event handlers onEnd: () => { // Callback function when countdown ends console.log("Countdown finished!"); }, onStop: () => {}, // Callback when countdown is stopped onResume: () => {}, // Callback when countdown is resumed onUpdate: (params) => {}, // Callback when countdown is updated }); ``` -------------------------------- ### Initialize SimplyCountdown.js using CommonJS Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Example of initializing SimplyCountdown.js using CommonJS module syntax. This is typically used in Node.js environments or older JavaScript projects. ```javascript const simplyCountdown = require("simplycountdown"); simplyCountdown(".my-super-countdown", { year: 2025, month: 12, day: 25, }); ``` -------------------------------- ### Initialize SimplyCountdown.js using ES Module Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Basic usage example demonstrating how to initialize SimplyCountdown.js using ES Module syntax. It requires importing the library and calling the simplyCountdown function with a target selector and configuration options. ```javascript import simplyCountdown from "simplycountdown.js"; simplyCountdown(".my-super-countdown", { year: 2025, month: 12, day: 25, }); ``` -------------------------------- ### ES Module Usage (JavaScript) Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/dist/index.html Demonstrates initializing a countdown timer using ES module syntax. This example covers various configuration options, including target date, custom labels, inline formatting, UTC enablement, refresh intervals, and callback functions for different events. ```javascript import simplyCountdown from 'simplycountdown.js'; // This is an example with default parameters simplyCountdown('[CSS-SELECTOR]', { year: 2015, // Target year (required) month: 6, // Target month [1-12] (required) day: 28, // Target day [1-31] (required) hours: 0, // Target hour [0-23], default: 0 minutes: 0, // Target minute [0-59], default: 0 seconds: 0, // Target second [0-59], default: 0 words: { // Custom labels, with lambda for plurals days: { root: 'day', lambda: (root, n) => n > 1 ? root + 's' : root }, hours: { root: 'hour', lambda: (root, n) => n > 1 ? root + 's' : root }, minutes: { root: 'minute', lambda: (root, n) => n > 1 ? root + 's' : root }, seconds: { root: 'second', lambda: (root, n) => n > 1 ? root + 's' : root } }, plural: true, // Use plurals for labels inline: false, // Inline format: e.g., "24 days, 4 hours, 2 minutes" inlineSeparator: ', ', // Separator for inline format, default: ", " inlineClass: 'simply-countdown-inline', // CSS class for inline countdown enableUtc: false, // Use UTC time if true refresh: 1000, // Refresh interval in ms, default: 1000 sectionClass: 'simply-section', // CSS class for each countdown section amountClass: 'simply-amount', // CSS class for numeric values wordClass: 'simply-word', // CSS class for unit labels zeroPad: false, // Pad numbers with leading zero removeZeroUnits: false, // Remove units with zero value countUp: false, // Count up after reaching zero onEnd: () => {}, // Callback when countdown ends onStop: () => {}, // Callback when countdown is stopped onResume: () => {}, // Callback when countdown is resumed onUpdate: (params) => {} // Callback when countdown is updated }); // Also, you can init with already existing Javascript Object. let myElement = document.querySelector('.my-countdown'); simplyCountdown(myElement, { /* options */ }); let multipleElements = document.querySelectorAll('.my-countdown'); simplyCountdown(multipleElements, { /* options */ }); ``` -------------------------------- ### CommonJS Usage (JavaScript) Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/dist/index.html Illustrates how to import and initialize the simplyCountdown library using the CommonJS module system, typically found in Node.js environments or older build setups. It shows a basic initialization with required options. ```javascript const simplyCountdown = require("simplycountdown.js"); simplyCountdown("#mycountdown", { year: 2025, month: 12, day: 25, }); ``` -------------------------------- ### JavaScript - ES Module Usage with Default Parameters Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/src/index.html Shows how to initialize simplyCountdown.js using ES modules. This example uses default parameters for the countdown and demonstrates importing the library. It also includes comments explaining the purpose of various configuration options. ```javascript import simplyCountdown from 'simplycountdown.js'; // This is an example with default parameters simplyCountdown('[CSS-SELECTOR]', { year: 2015, // Target year (required) month: 6, // Target month [1-12] (required) day: 28, // Target day [1-31] (required) hours: 0, // Target hour [0-23], default: 0 minutes: 0, // Target minute [0-59], default: 0 seconds: 0, // Target second [0-59], default: 0 words: { // Custom labels, with lambda for plurals days: { root: 'day', lambda: (root, n) => n > 1 ? root + 's' : root }, hours: { root: 'hour', lambda: (root, n) => n > 1 ? root + 's' : root }, minutes: { root: 'minute', lambda: (root, n) => n > 1 ? root + 's' : root }, seconds: { root: 'second', lambda: (root, n) => n > 1 ? root + 's' : root } }, plural: true, // Use plurals for labels inline: false, // Inline format: e.g., "24 days, 4 hours, 2 minutes" inlineSeparator: ', ', // Separator for inline format, default: ", " inlineClass: 'simply-countdown-inline', // CSS class for inline countdown enableUtc: false, // Use UTC time if true refresh: 1000, // Refresh interval in ms, default: 1000 sectionClass: 'simply-section', // CSS class for each countdown section amountClass: 'simply-amount', // CSS class for numeric values wordClass: 'simply-word', // CSS class for unit labels zeroPad: false, // Pad numbers with leading zero removeZeroUnits: false, // Remove units with zero value countUp: false, // Count up after reaching zero onEnd: () => {}, // Callback when countdown ends onStop: () => {}, // Callback when countdown is stopped onResume: () => {}, // Callback when countdown is resumed onUpdate: (params) => {} // Callback when countdown is updated }); // Also, you can init with already existing Javascript Object. let myElement = document.querySelector('.my-countdown'); simplyCountdown(myElement, { /* options */ }); let multipleElements = document.querySelectorAll('.my-countdown'); simplyCountdown(multipleElements, { /* options */ }); ``` -------------------------------- ### Clone SimplyCountdown.js Repository Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/CONTRIBUTING.md Clones the SimplyCountdown.js repository to your local machine. This is the first step after forking the project to start making contributions. ```bash git clone git@github.com:your-username/simplyCountdown.js.git cd simplyCountdown.js ``` -------------------------------- ### CSS for Customizing Themes Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Provides example CSS selectors for customizing the appearance of SimplyCountdown.js. This allows for creating unique themes by overriding default styles for various countdown components. ```css .custom-countdown-theme { /* Main countdown container */ } .custom-countdown-theme > .simply-section { /* Individual time unit blocks */ } .custom-countdown-theme > .simply-section > div { /* Inner container for amount and word */ } .custom-countdown-theme > .simply-section .simply-amount, .custom-countdown-theme > .simply-section .simply-word { /* Common styles for numbers and labels */ } .custom-countdown-theme > .simply-section .simply-amount { /* Number display */ } .custom-countdown-theme > .simply-section .simply-word { /* Label text */ } ``` -------------------------------- ### Countdown with Controls (JavaScript) Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/dist/index.html This example demonstrates how to initialize a countdown timer with control functionalities like stop, resume, and how to handle updates and state changes. It uses callbacks to update an external state box with the current countdown state. ```javascript // Example 8: With controls const controlDemo = simplyCountdown('.simply-countdown-control', { year: nextYear, month: nextMonth, day: 27, zeroPad: false, enableUtc: true, onUpdate: () => { updateStateBox(controlDemo.getState()); }, onResume: () => { updateStateBox(controlDemo.getState()); }, onStop: () => { updateStateBox(controlDemo.getState()); } }); const updateStateBox = (state) => { let stateBox = document.querySelector('.state-box'); stateBox.innerHTML = JSON.stringify(state, null, 2); } updateStateBox(controlDemo.getState()); // Not a conventional declaration, but it's useful for the demo window.controlDemo = controlDemo; ``` -------------------------------- ### JavaScript - Control Example with Stop/Resume Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/src/index.html Demonstrates how to use controls (stop, resume) with simplyCountdown.js. It initializes a countdown, updates a state box with the current state on various callbacks (update, resume, stop), and exposes the countdown instance globally for manual control. ```javascript const controlDemo = simplyCountdown('.simply-countdown-control', { year: nextYear, month: nextMonth, day: 27, zeroPad: false, enableUtc: true, onUpdate: () => { updateStateBox(controlDemo.getState()); }, onResume: () => { updateStateBox(controlDemo.getState()); }, onStop: () => { updateStateBox(controlDemo.getState()); } }); const updateStateBox = (state) => { let stateBox = document.querySelector('.state-box'); stateBox.innerHTML = JSON.stringify(state, null, 2); } updateStateBox(controlDemo.getState()); // Not a conventional declaration, but it's useful for the demo window.controlDemo = controlDemo; ``` -------------------------------- ### Import SimplyCountdown.js Source Files (TypeScript) Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Example of how to import the TypeScript source files directly if you need to compile them within your project. This approach allows for deeper integration and customization of the library's source code. ```typescript import simplyCountdown from "simplycountdown.js/src/core/simplyCountdown"; ``` -------------------------------- ### Managing Multiple Countdown Instances Source: https://context7.com/vincentloy/simplycountdown.js/llms.txt Illustrates how to manage multiple countdown instances simultaneously using simplycountdown.js. This includes creating and controlling individual timers for different events and a utility to pause or resume all timers. It also shows an example of auto-initializing countdowns based on data attributes. ```javascript import simplyCountdown from "simplycountdown.js"; // Create multiple countdowns const controllers = { christmas: simplyCountdown("#christmas-timer", { year: 2025, month: 12, day: 25, onEnd: () => console.log("Merry Christmas!") }), newyear: simplyCountdown("#newyear-timer", { year: 2026, month: 1, day: 1, onEnd: () => console.log("Happy New Year!") }), birthday: simplyCountdown("#birthday-timer", { year: 2025, month: 6, day: 15, countUp: true }) }; // Control all countdowns function pauseAll() { Object.values(controllers).forEach(c => c.stopCountdown()); } function resumeAll() { Object.values(controllers).forEach(c => c.resumeCountdown()); } // Auto-initialize all countdown elements document.querySelectorAll("[data-countdown]").forEach(element => { const target = element.dataset.countdown; const [year, month, day] = target.split("-").map(Number); simplyCountdown(element, { year, month, day, zeroPad: true }); }); ``` -------------------------------- ### Custom Russian Pluralization for simplyCountdown.js Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/docs/src/index.html This example shows how to configure simplyCountdown.js to use custom Russian pluralization rules for days, hours, minutes, and seconds. It includes a helper function `pluralizeRus` to handle the complex Russian pluralization logic. ```javascript // Example 7: with custom Russian pluralization simplyCountdown('#custom-plural', { // some parameters... words: { days: { lambda: (root, n) => pluralizeRus(n, 'день', 'дня', 'дней'), root: 'день' }, hours: { lambda: (root, n) => pluralizeRus(n, 'час', 'часа', 'часов'), root: 'час' }, minutes: { lambda: (root, n) => pluralizeRus(n, 'минута', 'минуты', 'минут'), root: 'минута' }, seconds: { lambda: (root, n) => pluralizeRus(n, 'секунда', 'секунды', 'секунд'), root: 'секунда' } } }); function pluralizeRus(number, singular, genitiveSingular, genitivePlural) { const lastDigit = number % 10; const lastTwoDigits = number % 100; if (lastTwoDigits >= 11 && lastTwoDigits <= 14) { return `${genitivePlural}`; } if (lastDigit === 1 && lastTwoDigits !== 11) { return `${singular}`; } if (lastDigit >= 2 && lastDigit <= 4 && !(lastTwoDigits >= 12 && lastTwoDigits <= 14)) { return `${genitiveSingular}`; } return `${genitivePlural}`; } ``` -------------------------------- ### Run Tests in Watch Mode Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Starts the test runner in watch mode, which automatically re-runs tests whenever code changes are detected, facilitating rapid development and debugging. ```bash npm run test:watch ``` -------------------------------- ### Count-Up Timer with simplyCountdown.js Source: https://context7.com/vincentloy/simplycountdown.js/llms.txt Illustrates how to configure simplyCountdown.js to count up from a past date using the `countUp: true` option. This is ideal for displaying elapsed time. Examples include tracking project age and event durations, with options for zero-padding and custom unit formatting. ```javascript import simplyCountdown from "simplycountdown.js"; // Count up from project start date simplyCountdown("#project-age", { year: 2023, month: 1, day: 15, countUp: true, zeroPad: true, removeZeroUnits: false }); // Event timer with milestones const eventTimer = simplyCountdown("#event-timer", { year: 2024, month: 6, day: 1, hours: 9, minutes: 0, countUp: true, onEnd: () => { // In count-up mode, onEnd is not called } }); // Track time since account creation simplyCountdown("#member-since", { year: 2022, month: 3, day: 20, countUp: true, inline: true, inlineSeparator: " : ", words: { days: { lambda: (r, n) => "d", root: "" }, hours: { lambda: (r, n) => "h", root: "" }, minutes: { lambda: (r, n) => "m", root: "" }, seconds: { lambda: (r, n) => "s", root: "" } } }); // Output: "1095 d : 12 h : 45 m : 30 s" ``` -------------------------------- ### SimplyCountdown.js Generated HTML Structure (Block Display) Source: https://github.com/vincentloy/simplycountdown.js/blob/develop/README.md Example of the HTML structure generated by SimplyCountdown.js in its default block display mode. This shows how the countdown is broken down into sections for days, hours, minutes, and seconds. ```html