Gathering detailed insights and metrics for counting-day
Gathering detailed insights and metrics for counting-day
Gathering detailed insights and metrics for counting-day
Gathering detailed insights and metrics for counting-day
npm install counting-day
Typescript
Module System
Node Version
NPM Version
JavaScript (99.95%)
HTML (0.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
6 Stars
22 Commits
2 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Sep 04, 2018
Latest Version
0.0.9
Package Id
counting-day@0.0.9
Size
7.56 kB
NPM Version
3.10.9
Node Version
6.9.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Mini library to count your day. sometime we just need to add some day to define a date like today, yesterday, last week, last 7 days, last 30 days, etc. But you feel too expensive to include a popular library with a big size of file. Now, you can do it with 5kB library. So, let's count your day!
You can import counting-day.min.js to your js file like this and process it with your preprocessor.
You can install it via NPM
1npm install counting-day
1import CountingDay from 'counting-day' 2// Or 3var CountingDay = require('counting-day');
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2 3let info = counting.addDay(31).get() 4console.log(info); 5/** Will return object with full date info 6{ 7 day: index of day (number: 0 - 6), 8 date: the date (number: 1 - 31), 9 month: index of month (number: 1 - 12), 10 maxDay: the max day of the month (number: 28 - 31), 11 year: current year, 12} 13*/ 14 15// will mutate the state of the instance 16let last7Days = couting.addDay(-7).get() // date: 25, month: 12, year: 2016 17 18// will directly return the object wihtout get() method and doesn't mutate the instance state 19let last30Days = counting.addDay(-7, 1, 2, 2017) // date: 25, month: 1, year: 2017 20 21// Will mutate instance state 22let addMonth = counting.addMonth(2).get() // date: 25, month: 2, year: 2017 23 24// Will not mutate the instance state since it has a initial date manually 25let addMonthWithManualInit = counting.addMonth(2, 1, 2, 2017).get() // date: 1, month: 4, year: 2017 26 27// Will mutate instance state 28let addYear = counting.addYear(2).get() // date: 25, month: 2, year: 2020 29 30// Will not mutate the instance state 31let addYearWithInit = counting.addYear(2, 1, 1, 2017) // date: 1, month: 1, year: 2017 32 33// Produce SQL format 34let SQLFormat = counting.getSQLDate() // 2020-02-25 35 36// return Date instance with current state as its arguments 37let DateInstance = counting.getDate() 38 39// then() function will return a new instance of CountingDay, so it will never mutate the last `counting` instance 40let differentCounting = addYearWithInit.then() 41 .addDay(5) 42 .addMonth(1) 43 .addYear(10) 44 .getSQLDate() 45// Will Return 2027-02-06 46 47console.log(counting === differentCounting); // false
Constructor
(Object: { date, month, year }) => (Instance)First of all we need to init our Constructor.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2console.log(counting.get());
fromDate
(Date: date) => (Instance)Another way to create a new instance from the new Date()
Object
1const now = new Date() 2const couting = CountingDay.fromDate(now) 3console.log(counting.get());
isLeap
(Number: year) => (Boolean)It cares about the leap.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2console.log(counting.isLeap()); // false 3counting.addYear(3) // year: 2020 4console.log(counting.isLeap()); // true 5 6const withManualInit = counting.isLeap(2040) 7console.log(withManualInit); // true
maxDayCount
(Number: month, Number: year) => (Number)It can also count the max day of the month.
1const couting = new CountingDay({ date: 1, month: 2, year: 2017 }) 2const maxDayOfFebruary = counting.maxDayCount() 3console.log(maxDayOfFebruary); // 28 4 5const anotherFebruary = counting.maxDayCount(2, 2020) 6console.log(anotherFebruary); // 29
addDay
(Number: count, [Number: date, [Number: month, [Number: year]]]) => (Object)It can add your day with positive or negative value of count
argument. Other arguments next to count
is custom initial and it is optional, you can pass all of them or one of them. When you pass the custom initial arguments you will get a new CountingDay in the then()
function.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2// Will mutate the state 3counting.addDay(6) 4console.log(couting.get()); // date: 7, month: 1, year: 2017 5 6// Will not mutate the state 7const customInit = counting.addDay(-2, 5) // start from date: 5 8console.log(customInit); // date: 3, month: 1, year: 2017 9 10const anotherCustomInit = customInit.then().addDay(-5, 15, 2, 2020) 11console.log(anotherCustomInit) // date: 10, month: 2, year: 2020
addMonth
(Number: count, [Number: date, [Number: month, [Number: year]]]) => (Object)Just like addDay
method, but it will add your month instead your date.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2// Will mutate the state 3counting.addMonth(6) 4console.log(couting.get()); // date: 1, month: 7, year: 2017 5 6// Will not mutate the state 7const customInit = counting.addMonth(-6, 1, 12) // start from date: 1, month: 12 8console.log(customInit); // date: 1, month: 6, year: 2017 9 10const anotherCustomInit = customInit.then().addMonth(12, 1, 1, 2020) 11console.log(anotherCustomInit) // date: 1, month: 1, year: 2021
addYear
(Number: count, [Number: date, [Number: month, [Number: year]]]) => (Object)Has some behaviout with addDay
and addMonth
method. It will add your Year.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2// Will mutate the state 3counting.addYear(6) 4console.log(couting.get()); // date: 1, month: 1, year: 2023 5 6// Will not mutate the state 7const customInit = counting.addYear(-10, 1, 2, 2000) // start from date: 1, month: 2, year: 2000 8console.log(customInit); // date: 1, month: 2, year: 1990 9 10const anotherCustomInit = customInit.then().addYear(12, 1, 1, 2020) 11console.log(anotherCustomInit) // date: 1, month: 1, year: 2022
then
() => (Object)then()
method is not a instance method, it is a function returned by addDay
, addMonth
, or addYear
method that run with custom initial argument.
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2 3// Will not mutate the state 4const customInit = counting.addMonth(6, 1, 2) // start from date: 1, month: 2 5console.log(customInit); // date: 1, month: 8, year: 2017 6 7const anotherCustomInit = customInit.then().addMonth(12, 1, 1, 2020) 8console.log(anotherCustomInit) // date: 1, month: 1, year: 2021
get
() => (Object)Will return current state instance as an Object.
1const now = new Date() 2const couting = CountingDay.fromDate(now) 3console.log(counting.get()); 4/* 5 => { 6 day: index of day (number: 0 - 6), 7 date: the date (number: 1 - 31), 8 month: index of month (number: 1 - 12), 9 maxDay: the max day of the month (number: 28 - 31), 10 year: current year, 11 } 12*/
getDate
() => (Object)This method will create Date instance from the current state
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2counting.getDate() // => new Date(2017, 1, 1)
getSQLDate
() => (Object)This method will return SQL date format from current state
1const couting = new CountingDay({ date: 1, month: 1, year: 2017 }) 2counting.getSQLDate() // => 2017-01-01
Just Contact Me At:
MIT Copyright (c) 2016 - forever Naufal Rabbani
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More