function roman_year(int $year = null): string {
$year = $year ?? date('Y');
$romanNumerals = [
'M' => 1000,
'CM' => 900,
'D' => 500,
This file contains 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
// This file is based on https://github.com/developit/mitt/blob/v1.1.3/src/index.js | |
// It's been edited for the needs of this script | |
// See the LICENSE at the top of the file | |
// Event handler callback function | |
type EventHandler = (...events: any[]) => void | |
// Wild card handler function receiving the first parameter as the event name | |
type WildCardEventHandler = (name: string, ...events: any[]) => void |
This file contains 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
/** | |
* This utility function shortens passed text to desired length | |
* | |
* e.g. wordWrap(str, { maxWidth: 150, moreIndication: '...' }) | |
* | |
* @param {String} str text that requires shortening | |
* @param {Object} opt the wrapping options | |
* {Number} maxWidth the max width of the text | |
* {string} moreIndication indicator to append to the end | |
*/ |
This file contains 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
/** | |
* @license | |
* Copyright Gover Construction LLC. All Rights Reserved. | |
* | |
* Use of this source code is governed by an MIT-style license that can be | |
* found in the LICENSE file at https://gist.github.com/zgover/678d51ffc2477d2e714052d7154f784b | |
*/ | |
/** | |
* Removes stop words (e.g. the, we, you, did, a, etc.) from |
This file contains 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
class Fib implements IterableIterator<number> { | |
protected fn1 = 0; | |
protected fn2 = 1; | |
constructor(protected maxValue?: number) {} | |
public next(): IteratorResult<number> { | |
var current = this.fn1; | |
this.fn1 = this.fn2; |
This file contains 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
/** | |
* Generate a random ID string | |
* | |
* Math.random should be unique because of its seeding algorithm. | |
* Convert it to base 36 (numbers + letters) and grab the first 9 characters | |
* after the decimal. | |
* | |
* @param config {RandomIdConfig} | |
* | |
* @return {string} |
This file contains 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
export default abstract class { | |
toJSON () { | |
const proto = Object.getPrototypeOf(this) | |
const jsonObj: any = Object.assign({}, this) | |
Object.entries(Object.getOwnPropertyDescriptors(proto)) | |
// .filter(([_, descriptor]) => typeof descriptor.get === 'function') | |
.map(([key, descriptor]) => { | |
if (descriptor && key[0] !== '_') { |
This file contains 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
/** | |
* Is literal type 'boolean' | |
* | |
* @export | |
* @param {*} val | |
* @returns {val is boolean} | |
*/ | |
export function _isBool(val: unknown): val is boolean { | |
return typeof val === 'boolean' | |
} |
/**
* Recursion simple
*/
const fibonacciRecursion = (n: number, fibRecusor?: typeof fibonacciRecursion): number => {
const recurse = fibRecusor ?? fibonacciRecursion
return (n < 2) ? n : (recurse.call(null, n - 1) + recurse.call(null, n - 2))
}
console.log('fibonacciRecursion', `${fibonacciRecursion(20)}`) // [LOG]: "fibonacciRecursion", "6765"
class ClearableWeakMap<T = unknown, K extends object = object> {
private _: WeakMap<K,T>;
constructor(init: Iterable<[K,T]>) {
this._ = new WeakMap(init)
}
clear() {
this._ = new WeakMap()
return this
}
OlderNewer