Socket
Socket
Sign inDemoInstall

dayjs

Package Overview
Dependencies
0
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.17 to 1.5.18

2

dist/dayjs.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dayjs=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}var t="second",n="minute",s="hour",r="day",i="week",a="month",u="year",c="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),o="January.February.March.April.May.June.July.August.September.October.November.December".split("."),h=/^(\d{4})-?(\d{2})-?(\d{1,2})$/,l=/Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}/g,$=function(e,t,n){var s=String(e);return!e||s.length>=t?e:"".concat(Array(t+1-s.length).join(n)).concat(e)},d=function(e){return e&&String(e).toLowerCase().replace(/s$/,"")},f=function(e){var t;return null===e?new Date(NaN):e?e instanceof Date?e:(t=String(e).match(h))?new Date(t[1],t[2]-1,t[3]):new Date(e):new Date},y=function(){function h(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),this.$d=f(e),this.init()}var y,v,m;return y=h,(v=[{key:"init",value:function(){this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=$(String(-1*this.$zone).replace(/^(.)?(\d)/,"$10$200"),5,"+"),this.$y=this.$d.getFullYear(),this.$M=this.$d.getMonth(),this.$D=this.$d.getDate(),this.$W=this.$d.getDay(),this.$H=this.$d.getHours(),this.$m=this.$d.getMinutes(),this.$s=this.$d.getSeconds(),this.$ms=this.$d.getMilliseconds()}},{key:"isValid",value:function(){return!("Invalid Date"===this.$d.toString())}},{key:"isLeapYear",value:function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}},{key:"isSame",value:function(e){return this.valueOf()===e.valueOf()}},{key:"isBefore",value:function(e){return this.valueOf()<e.valueOf()}},{key:"isAfter",value:function(e){return this.valueOf()>e.valueOf()}},{key:"year",value:function(){return this.$y}},{key:"month",value:function(){return this.$M}},{key:"date",value:function(){return this.$D}},{key:"hour",value:function(){return this.$H}},{key:"minute",value:function(){return this.$m}},{key:"second",value:function(){return this.$s}},{key:"millisecond",value:function(){return this.$ms}},{key:"unix",value:function(){return Math.floor(this.valueOf()/1e3)}},{key:"valueOf",value:function(){return this.$d.getTime()}},{key:"startOf",value:function(e,c){var o=this,l=void 0===c||c,$=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o.$y,s=new h(new Date(n,t,e));return l?s:s.endOf(r)},f=function(e,t){return new h(o.toDate()[e].apply(o.toDate(),l?[0,0,0,0].slice(t):[23,59,59,999].slice(t)))};switch(d(e)){case u:return l?$(1,0):$(31,11,this.$y);case a:return l?$(1,this.$M):$(0,this.$M+1,this.$y);case i:return l?$(this.$D-this.$W,this.$M):$(this.$D+(6-this.$W),this.$M,this.$y);case r:case"date":return f("setHours",0);case s:return f("setMinutes",1);case n:return f("setSeconds",2);case t:return f("setMilliseconds",3);default:return this.clone()}}},{key:"endOf",value:function(e){return this.startOf(e,!1)}},{key:"mSet",value:function(e,r){switch(d(e)){case"date":this.$d.setDate(r);break;case a:this.$d.setMonth(r);break;case u:this.$d.setFullYear(r);break;case s:this.$d.setHours(r);break;case n:this.$d.setMinutes(r);break;case t:this.$d.setSeconds(r);break;case"millisecond":this.$d.setMilliseconds(r)}return this.init(),this}},{key:"set",value:function(e,t){return n=t,Number.isNaN(parseFloat(n))||!Number.isFinite(n)?this:this.clone().mSet(e,t);var n}},{key:"add",value:function(e,t){var c,o=t&&1===t.length?t:d(t);if(["M",a].indexOf(o)>-1){var l=this.set("date",1).set(a,this.$M+e);return l=l.set("date",Math.min(this.$D,l.daysInMonth()))}if(["y",u].indexOf(o)>-1)return this.set(u,this.$y+e);switch(o){case"m":case n:c=6e4;break;case"h":case s:c=36e5;break;case"d":case r:c=864e5;break;case"w":case i:c=6048e5;break;default:c=1e3}return new h(this.valueOf()+e*c)}},{key:"subtract",value:function(e,t){return this.add(-1*e,t)}},{key:"format",value:function(e){var t=this;return(e||"YYYY-MM-DDTHH:mm:ssZ").replace(l,function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return String(t.$y);case"M":return String(t.$M+1);case"MM":return $(t.$M+1,2,"0");case"MMM":return o[t.$M].slice(0,3);case"MMMM":return o[t.$M];case"D":return String(t.$D);case"DD":return $(t.$D,2,"0");case"d":return String(t.$W);case"dddd":return c[t.$W];case"H":return String(t.$H);case"HH":return $(t.$H,2,"0");case"h":case"hh":return 0===t.$H?12:$(t.$H<13?t.$H:t.$H-12,"hh"===e?2:1,"0");case"a":return t.$H<12?"am":"pm";case"A":return t.$H<12?"AM":"PM";case"m":return String(t.$m);case"mm":return $(t.$m,2,"0");case"s":return String(t.$s);case"ss":return $(t.$s,2,"0");case"Z":return"".concat(t.$zoneStr.slice(0,-2),":00");default:return t.$zoneStr}})}},{key:"diff",value:function(e,n,s){var c,o,l,$,f,y,v=d(n),m=e instanceof h?e:new h(e),k=this-m,M=(c=this,$=12*((o=m).year()-c.year())+(o.month()-c.month()),f=c.clone().add($,"months"),l=o-f<0?(o-f)/(f-c.clone().add($-1,"months")):(o-f)/(c.clone().add($+1,"months")-f),Number(-($+l)));switch(v){case u:M/=12;break;case a:break;case"quarter":M/=3;break;case i:M=k/6048e5;break;case r:M=k/864e5;break;case t:M=k/1e3;break;default:M=k}return s?M:(y=M)<0?Math.ceil(y)||0:Math.floor(y)}},{key:"daysInMonth",value:function(){return this.endOf(a).$D}},{key:"clone",value:function(){return new h(this)}},{key:"toDate",value:function(){return new Date(this.$d)}},{key:"toArray",value:function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}},{key:"toJSON",value:function(){return this.toISOString()}},{key:"toISOString",value:function(){return this.toDate().toISOString()}},{key:"toObject",value:function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}},{key:"toString",value:function(){return this.$d.toUTCString()}}])&&e(y.prototype,v),m&&e(y,m),h}();return function(e){return new y(e)}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dayjs=t()}(this,function(){"use strict";function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var t="second",n="minute",r="hour",s="day",i="week",a="month",u="year",c="Sunday.Monday.Tuesday.Wednesday.Thursday.Friday.Saturday".split("."),o="January.February.March.April.May.June.July.August.September.October.November.December".split("."),h=/^(\d{4})-?(\d{2})-?(\d{1,2})$/,l=/Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}/g,$=function(e,t,n){var r=String(e);return!r||r.length>=t?e:"".concat(Array(t+1-r.length).join(n)).concat(e)},d=function(e){return e&&String(e).toLowerCase().replace(/s$/,"")},f=function(e){var t;return null===e?new Date(NaN):e?e instanceof Date?e:(t=String(e).match(h))?new Date(t[1],t[2]-1,t[3]):new Date(e):new Date},y=function(){function h(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),this.$d=f(e),this.init()}var y,v,m;return y=h,(v=[{key:"init",value:function(){var e,t,n;this.$zone=this.$d.getTimezoneOffset()/60,this.$zoneStr=$((e=this.$zone,n="",n=(t=-1*e)>-10&&t<10?"$10$200":"$1$200",String(t).replace(/^(.)?(\d)/,n)),5,"+"),this.$y=this.$d.getFullYear(),this.$M=this.$d.getMonth(),this.$D=this.$d.getDate(),this.$W=this.$d.getDay(),this.$H=this.$d.getHours(),this.$m=this.$d.getMinutes(),this.$s=this.$d.getSeconds(),this.$ms=this.$d.getMilliseconds()}},{key:"isValid",value:function(){return!("Invalid Date"===this.$d.toString())}},{key:"isLeapYear",value:function(){return this.$y%4==0&&this.$y%100!=0||this.$y%400==0}},{key:"isSame",value:function(e){return this.valueOf()===e.valueOf()}},{key:"isBefore",value:function(e){return this.valueOf()<e.valueOf()}},{key:"isAfter",value:function(e){return this.valueOf()>e.valueOf()}},{key:"year",value:function(){return this.$y}},{key:"month",value:function(){return this.$M}},{key:"day",value:function(){return this.$W}},{key:"date",value:function(){return this.$D}},{key:"hour",value:function(){return this.$H}},{key:"minute",value:function(){return this.$m}},{key:"second",value:function(){return this.$s}},{key:"millisecond",value:function(){return this.$ms}},{key:"unix",value:function(){return Math.floor(this.valueOf()/1e3)}},{key:"valueOf",value:function(){return this.$d.getTime()}},{key:"startOf",value:function(e,c){var o=this,l=void 0===c||c,$=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o.$y,r=new h(new Date(n,t,e));return l?r:r.endOf(s)},f=function(e,t){return new h(o.toDate()[e].apply(o.toDate(),l?[0,0,0,0].slice(t):[23,59,59,999].slice(t)))};switch(d(e)){case u:return l?$(1,0):$(31,11,this.$y);case a:return l?$(1,this.$M):$(0,this.$M+1,this.$y);case i:return l?$(this.$D-this.$W,this.$M):$(this.$D+(6-this.$W),this.$M,this.$y);case s:case"date":return f("setHours",0);case r:return f("setMinutes",1);case n:return f("setSeconds",2);case t:return f("setMilliseconds",3);default:return this.clone()}}},{key:"endOf",value:function(e){return this.startOf(e,!1)}},{key:"mSet",value:function(e,s){switch(d(e)){case"date":this.$d.setDate(s);break;case a:this.$d.setMonth(s);break;case u:this.$d.setFullYear(s);break;case r:this.$d.setHours(s);break;case n:this.$d.setMinutes(s);break;case t:this.$d.setSeconds(s);break;case"millisecond":this.$d.setMilliseconds(s)}return this.init(),this}},{key:"set",value:function(e,t){return n=t,Number.isNaN(parseFloat(n))||!Number.isFinite(n)?this:this.clone().mSet(e,t);var n}},{key:"add",value:function(e,t){var c,o=t&&1===t.length?t:d(t);if(["M",a].indexOf(o)>-1){var l=this.set("date",1).set(a,this.$M+e);return l=l.set("date",Math.min(this.$D,l.daysInMonth()))}if(["y",u].indexOf(o)>-1)return this.set(u,this.$y+e);switch(o){case"m":case n:c=6e4;break;case"h":case r:c=36e5;break;case"d":case s:c=864e5;break;case"w":case i:c=6048e5;break;default:c=1e3}return new h(this.valueOf()+e*c)}},{key:"subtract",value:function(e,t){return this.add(-1*e,t)}},{key:"format",value:function(e){var t=this;return(e||"YYYY-MM-DDTHH:mm:ssZ").replace(l,function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return String(t.$y);case"M":return String(t.$M+1);case"MM":return $(t.$M+1,2,"0");case"MMM":return o[t.$M].slice(0,3);case"MMMM":return o[t.$M];case"D":return String(t.$D);case"DD":return $(t.$D,2,"0");case"d":return String(t.$W);case"dddd":return c[t.$W];case"H":return String(t.$H);case"HH":return $(t.$H,2,"0");case"h":case"hh":return 0===t.$H?12:$(t.$H<13?t.$H:t.$H-12,"hh"===e?2:1,"0");case"a":return t.$H<12?"am":"pm";case"A":return t.$H<12?"AM":"PM";case"m":return String(t.$m);case"mm":return $(t.$m,2,"0");case"s":return String(t.$s);case"ss":return $(t.$s,2,"0");case"Z":return"".concat(t.$zoneStr.slice(0,-2),":00");default:return t.$zoneStr}})}},{key:"diff",value:function(e,n,r){var c,o,l,$,f,y,v=d(n),m=e instanceof h?e:new h(e),k=this-m,M=(c=this,$=12*((o=m).year()-c.year())+(o.month()-c.month()),f=c.clone().add($,"months"),l=o-f<0?(o-f)/(f-c.clone().add($-1,"months")):(o-f)/(c.clone().add($+1,"months")-f),Number(-($+l)));switch(v){case u:M/=12;break;case a:break;case"quarter":M/=3;break;case i:M=k/6048e5;break;case s:M=k/864e5;break;case t:M=k/1e3;break;default:M=k}return r?M:(y=M)<0?Math.ceil(y)||0:Math.floor(y)}},{key:"daysInMonth",value:function(){return this.endOf(a).$D}},{key:"clone",value:function(){return new h(this)}},{key:"toDate",value:function(){return new Date(this.$d)}},{key:"toArray",value:function(){return[this.$y,this.$M,this.$D,this.$H,this.$m,this.$s,this.$ms]}},{key:"toJSON",value:function(){return this.toISOString()}},{key:"toISOString",value:function(){return this.toDate().toISOString()}},{key:"toObject",value:function(){return{years:this.$y,months:this.$M,date:this.$D,hours:this.$H,minutes:this.$m,seconds:this.$s,milliseconds:this.$ms}}},{key:"toString",value:function(){return this.$d.toUTCString()}}])&&e(y.prototype,v),m&&e(y,m),h}();return function(e){return new y(e)}});
{
"name": "dayjs",
"version": "1.5.17",
"version": "1.5.18",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/dayjs.min.js",

@@ -25,3 +25,3 @@ import * as C from './constant'

this.$zone = this.$d.getTimezoneOffset() / 60
this.$zoneStr = Utils.padStart(String(this.$zone * -1).replace(/^(.)?(\d)/, '$10$200'), 5, '+')
this.$zoneStr = Utils.padStart(Utils.padZoneStr(this.$zone), 5, '+')
this.$y = this.$d.getFullYear()

@@ -65,2 +65,6 @@ this.$M = this.$d.getMonth()

day() {
return this.$W
}
date() {

@@ -67,0 +71,0 @@ return this.$D

export const padStart = (string, length, pad) => {
const s = String(string)
if (!string || s.length >= length) return string
if (!s || s.length >= length) return string
return `${Array((length + 1) - s.length).join(pad)}${string}`
}
export const padZoneStr = (negHour) => {
const hour = negHour * -1
let replacer = ''
if (hour > -10 && hour < 10) {
replacer = '$10$200'
} else {
replacer = '$1$200'
}
return String(hour).replace(/^(.)?(\d)/, replacer)
}
export const isNumber = n => (!Number.isNaN(parseFloat(n)) && Number.isFinite(n))

@@ -8,0 +19,0 @@

@@ -21,2 +21,6 @@ import moment from 'moment'

it('Day of Week', () => {
expect(dayjs().day()).toBe(moment().day())
})
it('Date', () => {

@@ -23,0 +27,0 @@ expect(dayjs().date()).toBe(moment().date())

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc