Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chaining-date

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chaining-date - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

src/prototype.js

2

dist/chaining-date.js

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

var ChainingDate=function(){var t="MM",n={["YYYY"]:"FullYear",[t]:"Month",["DD"]:"Date",["D"]:"Day",["hh"]:"Hours",["mm"]:"Minutes",["ss"]:"Seconds",["sss"]:"Milliseconds"},e=Date;function r(t){this.date="number"==typeof t?new e(t):"string"==typeof t?new e(e.parse(t)):t||new e}var i=r.prototype;return i.add=function(){return this},i.set=function(e,r){return this.date["set"+n[e]](e===t?r-1:r),this},i.get=function(e){var r=this.date["get"+n[e]]();return e===t&&(r+=1),r},i.toString=function(t){var n=this.date;return t?n:n.toString()},r}();
var ChainingDate=function(){var t=["FullYear","Year","Month","Date","Day","Hours","Minutes","Seconds","Milliseconds"];var n=Date;function e(t){this.date="number"==typeof t?new n(t):"string"==typeof t?new n(n.parse(t)):t||new n}return function(n){for(var e=t.length;e--;)!function(t){var e="get"+t,r="set"+t;n[e]=function(){return this.date[e]()},n[r]=function(t){return this.date[r](t),this}}(t[e]);n.getMonth=function(){return this.date.getMonth()+1}}(e.prototype),e}();
/**
* @author TroyTae
* @version 0.4.2
* @version 0.4.3
* @name chaining-date

@@ -8,23 +8,37 @@ */

var DateFormat = {
year: 'YYYY',
month: 'MM',
date: 'DD',
day: 'D',
hour: 'hh',
minute: 'mm',
second: 'ss',
millisecond: 'sss',
};
var DateMethods = [
'FullYear',
'Year',
'Month',
'Date',
'Day',
'Hours',
'Minutes',
'Seconds',
'Milliseconds'
];
var DateFormatMethod = {
[DateFormat.year]: 'FullYear',
[DateFormat.month]: 'Month',
[DateFormat.date]: 'Date',
[DateFormat.day]: 'Day',
[DateFormat.hour]: 'Hours',
[DateFormat.minute]: 'Minutes',
[DateFormat.second]: 'Seconds',
[DateFormat.millisecond]: 'Milliseconds',
};
function initPrototype(prototype) {
var index = DateMethods.length;
while (index--) {
(function(method) {
var
getter = 'get' + method,
setter = 'set' + method
;
prototype[getter] = function () {
return this.date[getter]();
};
prototype[setter] = function (value) {
this.date[setter](value);
return this;
};
})(DateMethods[index]);
}
prototype.getMonth = function() {
return this.date.getMonth() + 1;
};
// prototype.add;
// prototype.toString;
}

@@ -40,26 +54,4 @@ var D = Date;

var P = ChainingDate.prototype;
P.add = function () {
return this;
};
P.set = function (format, value) {
this.date['set' + DateFormatMethod[format]]
(format === DateFormat.month ? value - 1 : value);
return this;
};
P.get = function (format) {
var v = this.date['get' + DateFormatMethod[format]]();
if (format === DateFormat.month) {
v += 1;
}
return v;
};
P.toString = function (pattern) {
var date = this.date;
if (pattern) {
return date;
}
return date.toString();
};
initPrototype(ChainingDate.prototype);
module.exports = ChainingDate;
{
"name": "chaining-date",
"version": "0.4.2",
"version": "0.4.3",
"description": "A tiny module for using Date with chaining ⏱",

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

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

import { DateFormat, DateFormatMethod } from './constants';
import initPrototype from './prototype';

@@ -12,26 +12,4 @@ var D = Date;

var P = ChainingDate.prototype;
P.add = function () {
return this;
};
P.set = function (format, value) {
this.date['set' + DateFormatMethod[format]]
(format === DateFormat.month ? value - 1 : value);
return this;
};
P.get = function (format) {
var v = this.date['get' + DateFormatMethod[format]]();
if (format === DateFormat.month) {
v += 1;
}
return v;
};
P.toString = function (pattern) {
var date = this.date;
if (pattern) {
return date;
}
return date.toString();
};
initPrototype(ChainingDate.prototype);
export default ChainingDate;

@@ -12,16 +12,17 @@ var DateFormat = {

var DateFormatMethod = {
[DateFormat.year]: 'FullYear',
[DateFormat.month]: 'Month',
[DateFormat.date]: 'Date',
[DateFormat.day]: 'Day',
[DateFormat.hour]: 'Hours',
[DateFormat.minute]: 'Minutes',
[DateFormat.second]: 'Seconds',
[DateFormat.millisecond]: 'Milliseconds',
};
var DateMethods = [
'FullYear',
'Year',
'Month',
'Date',
'Day',
'Hours',
'Minutes',
'Seconds',
'Milliseconds'
];
export {
DateFormat,
DateFormatMethod
DateMethods
};

@@ -6,20 +6,21 @@ const ChainingDate = require('../dist/index');

const chainingDate = new ChainingDate();
expect(chainingDate.get('YYYY')).toBe(date.getFullYear());
expect(chainingDate.get('MM')).toBe(date.getMonth() + 1);
expect(chainingDate.get('DD')).toBe(date.getDate());
expect(chainingDate.get('D')).toBe(date.getDay());
expect(chainingDate.get('hh')).toBe(date.getHours());
expect(chainingDate.get('mm')).toBe(date.getMinutes());
expect(chainingDate.get('ss')).toBe(date.getSeconds());
expect(chainingDate.get('sss')).toBe(date.getMilliseconds());
expect(chainingDate.getFullYear()).toBe(date.getFullYear());
expect(chainingDate.getYear()).toBe(date.getYear());
expect(chainingDate.getMonth()).toBe(date.getMonth() + 1);
expect(chainingDate.getDate()).toBe(date.getDate());
expect(chainingDate.getDay()).toBe(date.getDay());
expect(chainingDate.getHours()).toBe(date.getHours());
expect(chainingDate.getMinutes()).toBe(date.getMinutes());
expect(chainingDate.getSeconds()).toBe(date.getSeconds());
expect(chainingDate.getMilliseconds()).toBe(date.getMilliseconds());
});
test('setter', () => {
const year = 1997;
const month = 7;
const date = 21;
const chainingDate = new ChainingDate();
expect(chainingDate.set('YYYY', year).get('YYYY')).toBe(year);
expect(chainingDate.set('MM', month).get('MM')).toBe(month);
expect(chainingDate.set('DD', date).get('DD')).toBe(date);
});
// test('setter', () => {
// const year = 1997;
// const month = 7;
// const date = 21;
// const chainingDate = new ChainingDate();
// expect(chainingDate.set('YYYY', year).get('YYYY')).toBe(year);
// expect(chainingDate.set('MM', month).get('MM')).toBe(month);
// expect(chainingDate.set('DD', date).get('DD')).toBe(date);
// });
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc