New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3 to 0.5.1

2

dist/chaining-date.js

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

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}();
var ChainingDate=function(){var t=["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="add"+t,r="get"+t,i="set"+t;n[r]=function(){return this.date[r]()},n[i]=function(t){return this.date[i](t),this},n[e]=function(t){return this[i](this[r]()+t),this}}(t[e]);n.getYear=function(){return this.date.getFullYear()},n.setYear=function(t){return this.date.setFullYear(t),this},n.getMonth=function(){return this.date.getMonth()+1},n.setMonth=function(t){return this.date.setMonth(t-1),this}}(e.prototype),e}();
/**
* @author TroyTae
* @version 0.4.3
* @version 0.5.1
* @name chaining-date

@@ -9,3 +9,2 @@ */

var DateMethods = [
'FullYear',
'Year',

@@ -26,2 +25,3 @@ 'Month',

var
adder = 'add' + method,
getter = 'get' + method,

@@ -37,8 +37,22 @@ setter = 'set' + method

};
prototype[adder] = function (value) {
this[setter](this[getter]() + value);
return this;
};
})(DateMethods[index]);
}
prototype.getYear = function() {
return this.date.getFullYear();
};
prototype.setYear = function(value) {
this.date.setFullYear(value);
return this;
};
prototype.getMonth = function() {
return this.date.getMonth() + 1;
};
// prototype.add;
prototype.setMonth = function(value) {
this.date.setMonth(value - 1);
return this;
};
// prototype.toString;

@@ -45,0 +59,0 @@ }

{
"name": "chaining-date",
"version": "0.4.3",
"version": "0.5.1",
"description": "A tiny module for using Date with chaining ⏱",

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

@@ -13,3 +13,2 @@ var DateFormat = {

var DateMethods = [
'FullYear',
'Year',

@@ -16,0 +15,0 @@ 'Month',

@@ -25,6 +25,17 @@ import {DateMethods} from './constants';

}
prototype.getYear = function() {
return this.date.getFullYear();
};
prototype.setYear = function(value) {
this.date.setFullYear(value);
return this;
};
prototype.getMonth = function() {
return this.date.getMonth() + 1;
};
prototype.setMonth = function(value) {
this.date.setMonth(value - 1);
return this;
};
// prototype.toString;
};
const ChainingDate = require('../dist/index');
const year = 1997;
const month = 7;
const date = 21;
test('getter', () => {
const date = new Date();
const chainingDate = new ChainingDate();
expect(chainingDate.getFullYear()).toBe(date.getFullYear());
expect(chainingDate.getYear()).toBe(date.getYear());
expect(chainingDate.getYear()).toBe(date.getFullYear());
expect(chainingDate.getMonth()).toBe(date.getMonth() + 1);

@@ -17,10 +20,14 @@ expect(chainingDate.getDate()).toBe(date.getDate());

// 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 chainingDate = new ChainingDate();
expect(chainingDate.setYear(year).getYear()).toBe(year);
expect(chainingDate.setMonth(month).getMonth()).toBe(month);
expect(chainingDate.setDate(date).getDate()).toBe(date);
});
test('adder', () => {
const chainingDate = new ChainingDate();
expect(chainingDate.setYear(year).addYear(3).getYear()).toBe(year + 3);
expect(chainingDate.setMonth(month).addMonth(1).getMonth()).toBe(month + 1);
expect(chainingDate.setDate(date).addDate(-11).getDate()).toBe(date - 11);
});
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