diff --git a/README.md b/README.md index 54a62d2a..1b0723ed 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ is(13).thirteen(); // true is(12.8).roughly.thirteen(); // true is(6).within(10).of.thirteen(); // true is(2008).yearOfBirth(); // true +is(new Date("2020-03-13")).friday13th(); // true // check your math skillz is(4).plus(5).thirteen(); // false diff --git a/consts.js b/consts.js index 365d5ca9..9d2153c3 100644 --- a/consts.js +++ b/consts.js @@ -2,6 +2,7 @@ const THIRTEEN = 13; const THIRTEEN_FUZZ = 0.5; +const FRIDAY = 5; var thirteenStrings = [ "xiii", // Roman numeral 13 @@ -354,5 +355,6 @@ var thirteenStrings = [ module.exports = { THIRTEEN: THIRTEEN, THIRTEEN_FUZZ: THIRTEEN_FUZZ, + FRIDAY: FRIDAY, thirteenStrings: thirteenStrings }; diff --git a/is.js b/is.js index 9877f807..cb0df9c6 100644 --- a/is.js +++ b/is.js @@ -3,6 +3,7 @@ var consts = require('./consts'); const THIRTEEN = consts.THIRTEEN; const THIRTEEN_FUZZ = consts.THIRTEEN_FUZZ; +const FRIDAY = consts.FRIDAY; const thirteenStrings = consts.thirteenStrings; 'use strict'; @@ -107,6 +108,12 @@ var is = function is(x) { } return currYear - parseInt(x) == THIRTEEN }, + friday13th: function() { + if (Object.prototype.toString.call(x) !== '[object Date]') { + return false; + } + return x.getDay() === FRIDAY && x.getDate() === THIRTEEN; + }, plus: function(y) { return is(x + y); }, diff --git a/test.js b/test.js index 851648cf..eebc2034 100644 --- a/test.js +++ b/test.js @@ -36,6 +36,11 @@ tap.equal(is("https://www.imdb.com/title/tt2991516/").thirteen(), true); //year of birth test tap.equal(is("2003").yearOfBirth(), false); +// Friday 13th test +tap.equal(is("not a date").friday13th(), false); +tap.equal(is(new Date("2020-06-13")).friday13th(), false); +tap.equal(is(new Date("2018-07-13")).friday13th(), true); + // Imaginary 13's tests tap.equal(is("13+0i").thirteen(), true); tap.equal(is("13i").thirteen(), true);