This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function julian(date) { | |
| date = new Date(date); | |
| let year = date.getFullYear(); | |
| let days = Math.floor((date.valueOf() - new Date(year, 0, 0).valueOf()) / 86400000); | |
| return `${year}${`000${days}`.slice(-3)}`; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Cuts down potentially long or infinite loops to prevent blocking the event loop. | |
| * | |
| * Example: | |
| * snip(10, 500, function*() { | |
| * for (let i = 0; i < 1e100; i++, yield) { | |
| * console.log(i); | |
| * } | |
| * console.log('Done!'); | |
| * }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** @typedef {string|boolean|number|Function|void} nonObject */ | |
| /** | |
| * @typedef {[string, nonObject]} DenestedRow | |
| * @property {string} path The dot/bracket notation of the variable. (Example: `a.b[0].c["d-e"].f`). Same as `this[0]`. | |
| * @property {object} parent The object that holds this variable. | |
| * @property {string} key The key to this variable. (`this.parent[this.key] === this[1]`) | |
| */ | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Copyright (c) 2019 larryc5 <larry.costigan5@gmail.com> | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Clones an object and all sub-objects. | |
| * `into = from;` -> `into = deepClone(from);` | `deepClone(from, into);` | |
| * @param {Object} from Getter object. | |
| * @param {Object} [into = {}] Setter object. | |
| * @param {boolean} [noOverwrite = false] Flag to not overwrite non-null values in `into` if true. | |
| * @return {Object} Returns `into`. | |
| */ | |
| export default function deepClone(from, into = {}, noOverwrite = false) { | |
| let into = this == global ? Object.create(Object.getPrototypeOf(from)) : this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { open, writeFile } from 'fs'; | |
| /** | |
| * Writes and overwrites a file in a continuous loop. | |
| * | |
| * Example: | |
| * loopWriteFile('./date.txt', function*() { | |
| * while (true) { | |
| * yield new Date().toISOString(); | |
| * } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Performs a natural sort based on two variables' string values. | |
| * Example: | |
| * ['C12', 'B', 'c2', 'a', 'c1'].sort(natSort); //=> ['a', 'B', 'c1', 'c2', 'C12'] | |
| * | |
| * [{name: 'Bob'}, {name: 'Zack'}, {name: 'Alex'}].sort(function(a, b) { | |
| * return natSort(a, b, 'name', true); | |
| * }); //=> [{name: 'Alex'}, {name: 'Bob'}, {name: 'Zack'}] | |
| * | |
| * @param {any} a |
NewerOlder