Gathering detailed insights and metrics for miment
Gathering detailed insights and metrics for miment
Gathering detailed insights and metrics for miment
Gathering detailed insights and metrics for miment
npm install miment
Typescript
Module System
Node Version
NPM Version
71.9
Supply Chain
98.3
Quality
75.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
68,186
Last Day
25
Last Week
188
Last Month
919
Last Year
13,124
336 Stars
67 Commits
31 Forks
5 Watching
2 Branches
4 Contributors
Latest Version
0.0.9
Package Id
miment@0.0.9
Unpacked Size
59.96 kB
Size
17.23 kB
File Count
8
NPM Version
5.6.0
Node Version
11.12.0
Cumulative downloads
Total Downloads
Last day
8.7%
25
Compared to previous day
Last week
29.7%
188
Compared to previous week
Last month
-18.6%
919
Compared to previous month
Last year
-4.8%
13,124
Compared to previous year
Miment is an aero-weigh time library (~1KB minified) but get things done efficiently.
Moment is an extraordinary time library that almost covers everything you need, with a massive (200KB+) size. Suppose 90% of its daily usage can be fulfilled within 1% codebase, this tradeoff can be worthwhile. So there comes miment as "mini-moment".
For NPM environment:
npm i miment
Import into codebase and go:
1import miment from 'miment' 2miment().format('YYYY/MM/DD hh-mm-ss SSS') // 2018/04/09 23-49-36 568
For browser usage, simply include ./dist/miment-min.js
:
1<script src="https://unpkg.com/miment/dist/miment-min.js"></script> 2<script> 3 miment().format('YYYY/MM/DD hh-mm-ss SSS') // 2018/04/09 23-49-36 568 4</script>
For most daily usage, format
is what you need:
1miment().format() // 2018-04-09 23:49:36 2miment().format('YYYY/MM/DD hh-mm-ss SSS') // 2018/04/09 23-49-36 568 3miment().format('YYYY年MM月DD日 星期WW') // 2018年04月09日 星期一 4miment().format('YYYY年MM月DD日 星期ww') // 2018年04月09日 星期1 *周日对应星期0*
What if you only what to get a date field?
1miment().format('YYYY') // '2018' 2miment().format('MM') // '04' 3miment().format('DD') // '09' 4// ...
For JSON format, miment().json()
yields:
1{ 2 "year": 2018, 3 "month": 4, 4 "date": 11, 5 "hour": 8, 6 "minute": 57, 7 "second": 41, 8 "day": 3, 9 "millisecond": 87 10}
For other output formats, you can have miment().stamp()
for timestamp, and miment().daysInMonth()
for days count in corresponding month.
What's the date 10 days after? add
is what you need:
1miment().add(1,'DD') // next day 2miment().add(1, 'YYYY').add(2, 'MM').add(-3, 'DD') // chaining 3miment().add(-1,'ww') // date last week 4miment().add(500,SSS) // add 500ms
Remember not to chain
add()
afterformat()
, sinceformat()
returns string instead of miment instance:1miment().add(1, 'DD').format().add(1, 'DD') // Error!
How to count distance between 2 dates? You have distance
:
1miment().distance('2018-04-11 00:00:00') 2// Thu Jan 08 1970 21:04:50 GMT+0800 (CST)
By default the instance returned by distance
is resolved as unix timestamp relative to 1970 "epoch". In this case, use second argument for format
API on formatting:
1miment().distance(1523408529932).format('YYYY/MM/DD') 2// wrong: '1970/01/08' 3 4miment().distance('2018-04-11 00:00:00').format('YYYY/MM/DD', true) 5// correct: '0/00/07'
For other common calculation, see reference.
miment
miment(string?|Date?) => Miment
For miment instance methods, there are basically 3 kinds of methods available:
Miment
instance, e.g., add
and distance
.format
and json
.Date
model.add
add(amount: number, unit: string) => Miment
Get Miment
object with offset date added.
1miment().add(1, 'DD') 2miment().add(1, 'YYYY').add(2, 'MM').add(-3, 'DD') 3miment().add(-1, 'ww') 4miment().add(500,SSS)
distance
distance(dt: Miment|Date|string, dt2: Miment?|Date?|string?) => Miment
Get Miment
object measuring distance between two dates. If only one argument is provided, it returns distance between that time and current time.
To get the formatted result, please format
it with the second true
flag.
1miment().distance('2018-04-10 00:00:00') 2// Mon Dec 29 1969 22:11:51 GMT+0800 (CST) 3 4miment().distance(1523408529932) 5// Wed Dec 31 1969 07:13:47 GMT+0800 (CST) 6 7miment().distance('2018-04-10 00:00:00', new Date()) 8// Mon Dec 29 1969 22:11:13 GMT+0800 (CST) 9 10miment().distance('2018-04-10 00:00:00', '2018-04-11 00:00:00') 11// Mon Dec 29 1969 22:10:46 GMT+0800 (CST)
firstDayOfWeek
firstDayOfWeek() => Miment
Get Miment
object representing first day (Sunday) of the week. For other weekday, simply chaining it with add
.
1miment().firstDayOfWeek() 2// Sun Apr 08 2018 11:27:55 GMT+0800 (CST) 3 4miment().firstDayOfWeek().format() 5// 2018-04-08 11:27:55
firstDay
firstDay() => Miment
Get Miment
object representing first day of the month.
1miment().firstDay() 2// Sun Apr 01 2018 00:00:00 GMT+0800 (CST) 3 4miment().firstDay().format() 5// 2018-04-01 00:00:00
lastDay
firstDay() => Miment
Get Miment
object representing last day of the month.
1miment().lastDay() // Mon Apr 30 2018 00:00:00 GMT+0800 (CST) 2miment().lastDay().format() // 2018-04-30 00:00:00
format
format(formatter: string?, distance: boolean) => string
Format Miment
into string. Support combination of following formats: "YYYY MM DD hh mm ss SSS ww WW". Pass distance
flag as true
if you are formatting results from distance()
.
json
json() => Object
Get JSON object for date fields.
1{ 2 "year": 2018, 3 "month": 4, 4 "date": 11, 5 "hour": 8, 6 "minute": 57, 7 "second": 41, 8 "day": 3, 9 "millisecond": 87 10}
stamp
stamp() => number
Get timestamp of Miment
object.
All Date instance APIs are inherited. For now it's not recommended to use it since they're unchainable.
MIT
Please star this repo if you like, and feel free to submit issues, thanks!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
53 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
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