Merge branch 'master' into master

This commit is contained in:
Angelos Chalaris
2018-10-01 19:33:44 +03:00
committed by GitHub
276 changed files with 4483 additions and 3470 deletions

View File

@ -0,0 +1,3 @@
const dayOfYear = date =>
Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24);
module.exports = dayOfYear;

View File

@ -0,0 +1,6 @@
const expect = require('expect');
const dayOfYear = require('./dayOfYear.js');
test('dayOfYear is a Function', () => {
expect(dayOfYear).toBeInstanceOf(Function);
});

View File

@ -0,0 +1,2 @@
const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count));
module.exports = indentString;

View File

@ -0,0 +1,12 @@
const expect = require('expect');
const indentString = require('./indentString.js');
test('indentString is a Function', () => {
expect(indentString).toBeInstanceOf(Function);
});
test('indentString is a Function', () => {
expect(indentString('Lorem\nIpsum', 2)).toBe(' Lorem\n Ipsum');
});
test('indentString is a Function', () => {
expect(indentString('Lorem\nIpsum', 2, '_')).toBe('__Lorem\n__Ipsum');
});

View File

@ -0,0 +1,2 @@
const isAfterDate = (dateA, dateB) => dateA > dateB;
module.exports = isAfterDate;

View File

@ -0,0 +1,12 @@
const expect = require('expect');
const isAfterDate = require('./isAfterDate.js');
test('isAfterDate is a Function', () => {
expect(isAfterDate).toBeInstanceOf(Function);
});
test('isAfterDate produces the correct result', () => {
expect(isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeTruthy();
});
test('isBeforeDate produces the correct result', () => {
expect(isAfterDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeFalsy();
});

View File

@ -0,0 +1,2 @@
const isBeforeDate = (dateA, dateB) => dateA < dateB;
module.exports = isBeforeDate;

View File

@ -0,0 +1,13 @@
const expect = require('expect');
const isBeforeDate = require('./isBeforeDate.js');
test('isBeforeDate is a Function', () => {
expect(isBeforeDate).toBeInstanceOf(Function);
});
test('isBeforeDate produces the correct result', () => {
expect(isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeTruthy();
});
test('isBeforeDate produces the correct result', () => {
expect(isBeforeDate(new Date(2010, 10, 21), new Date(2010, 10, 20))).toBeFalsy();
});

View File

@ -0,0 +1,2 @@
const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString();
module.exports = isSameDate;

View File

@ -0,0 +1,12 @@
const expect = require('expect');
const isSameDate = require('./isSameDate.js');
test('isSameDate is a Function', () => {
expect(isSameDate).toBeInstanceOf(Function);
});
test('isSameDate produces the correct result', () => {
expect(isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20))).toBeTruthy();
});
test('isSameDate produces the correct result', () => {
expect(isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 21))).toBeFalsy();
});

View File

@ -1,3 +1,2 @@
const mask = (cc, num = 4, mask = '*') =>
('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num);
const mask = (cc, num = 4, mask = '*') => `${cc}`.slice(-num).padStart(`${cc}`.length, mask);
module.exports = mask;

2
test/maxDate/maxDate.js Normal file
View File

@ -0,0 +1,2 @@
const maxDate = (...dates) => new Date(Math.max.apply(null, ...dates));
module.exports = maxDate;

View File

@ -0,0 +1,15 @@
const expect = require('expect');
const maxDate = require('./maxDate.js');
test('maxDate is a Function', () => {
expect(maxDate).toBeInstanceOf(Function);
});
test('maxDate produces the maximum date', () => {
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9)
];
expect(maxDate(array)).toEqual(new Date(2018, 2, 12));
});

2
test/minDate/minDate.js Normal file
View File

@ -0,0 +1,2 @@
const minDate = (...dates) => new Date(Math.min.apply(null, ...dates));
module.exports = minDate;

View File

@ -0,0 +1,15 @@
const expect = require('expect');
const minDate = require('./minDate.js');
test('minDate is a Function', () => {
expect(minDate).toBeInstanceOf(Function);
});
test('minDate produces the maximum date', () => {
const array = [
new Date(2017, 4, 13),
new Date(2018, 2, 12),
new Date(2016, 0, 10),
new Date(2016, 0, 9)
];
expect(minDate(array)).toEqual(new Date(2016, 0, 9));
});

2
test/pipeLog/pipeLog.js Normal file
View File

@ -0,0 +1,2 @@
const pipeLog = data => console.log(data) || data;
module.exports = pipeLog;

View File

@ -0,0 +1,6 @@
const expect = require('expect');
const pipeLog = require('./pipeLog.js');
test('pipeLog is a Function', () => {
expect(pipeLog).toBeInstanceOf(Function);
});

6
test/shank/shank.js Normal file
View File

@ -0,0 +1,6 @@
const shank = (arr, index = 0, delCount = 0, ...elements) =>
arr
.slice(0, index)
.concat(elements)
.concat(arr.slice(index + delCount));
module.exports = shank;

22
test/shank/shank.test.js Normal file
View File

@ -0,0 +1,22 @@
const expect = require("expect");
const shank = require("./shank.js");
test("shank is a Function", () => {
expect(shank).toBeInstanceOf(Function);
});
const names = ['alpha', 'bravo', 'charlie'];
test("Returns an array with the added elements.", () => {
expect(shank(names, 1, 0, 'delta')).toEqual(['alpha', 'delta', 'bravo', 'charlie']);
});
test("Returns an array with the removed elements.", () => {
expect(shank(names, 1, 1)).toEqual(['alpha', 'charlie']);
});
test("Does not mutate the original array", () => {
shank(names, 1, 0, 'delta');
expect(names).toEqual(['alpha', 'bravo', 'charlie']);
});

File diff suppressed because it is too large Load Diff