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
/** | |
* Observables can contain multiple values over time. In order to retrieve | |
* the values as a single promise, one must promisify the observable by | |
* reducing each subsequent value into a new array. This shows the order | |
* of the items as they are returned. Secondly, the promises resolve method | |
* must be fired from the subscribe() function of the observable. | |
* | |
* @param {Observable} o the observable instance to work with | |
* @return {Promise} a promise that can be used with async/await | |
*/ |
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
export class DeferredPromise { | |
// A definition of this.resolve. If null, this object is uninitialized | |
resolve = null; | |
// A definition of this.reject. If null, this object is uninitialized | |
reject = null; | |
// A definition of this.promise. If null, this object is uninitialized | |
promise = null; | |
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
#!/usr/bin/env node | |
const FS = require('fs') | |
const { inspect } = require('util') | |
const { EOL } = require('os') | |
const { dirname, basename } = require('path') | |
const version = { | |
major: 1, | |
minor: 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
const version = { | |
major: 1, | |
minor: 2, | |
patch: 0, | |
toString() { return `${this.major}.${this.minor}.${this.patch}` }, | |
compare(to) { | |
if (this.major < to.major) return -1 | |
if (this.major > to.major) return 1 | |
if (this.minor < to.minor) return -1 | |
if (this.minor > to.minor) return 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
type DeferredResult<DT> = { | |
promise: Promise<DT>; | |
resolve: (value?: DT | PromiseLike<DT>) => void; | |
reject: (reason?: any) => void; | |
}; | |
type DeferredOptionalResult<DT> = { | |
promise?: Promise<DT>; | |
resolve?: (value?: DT | PromiseLike<DT>) => void; | |
reject?: (reason?: any) => void; |
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
/// Grab the underlying type of a value. This will return the true type of | |
/// a value, whereas typeof will return 'object' for arrays, null, and | |
/// other non-primitive types. | |
/// | |
/// @param {any} o - The value to get the type of | |
/// @returns {string} - The type of the value | |
const typeOf = o => /\[object (\w+)\]/.exec(Object.prototype.toString.call(o))[1]; | |
/// Determines if the supplied function is actually an ES6+ class or just | |
/// a regular function by checking its toString() values. |
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
// Priavte database for applied extensions | |
const extensionDB = new Map() | |
// A constant defining the default set name | |
export const kDefaultSet = "Default JavaScript Extension Set" | |
// A constant defining the keys of a descriptor object used with | |
// Object.defineProperties and Object.defineProperty | |
export const kDescriptorKeys = [ | |
'value', 'writable', 'get', 'set', 'enumerable', 'configurable', |
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 os | |
import sys | |
def modify_indentation(code): | |
new_code_lines = [] | |
for line in code.splitlines(): | |
leading_spaces = 0 | |
# Count the leading spaces in increments of 4 | |
while leading_spaces + 4 <= len(line) and line[leading_spaces:leading_spaces + 4] == ' ': |
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
#!/usr/bin/env zsh | |
json() { | |
usage() { | |
echo "Usage: json [property] [file]" | |
echo " property: (optional) The property of the JSON object to retrieve." | |
echo " file: (optional) The file containing the JSON object. Defaults to 'package.json'." | |
echo "" | |
echo "Special values for property:" | |
echo " *: Retrieve the whole object." |
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
export class Type { | |
/** | |
* Creates an instance of the Type class. | |
* | |
* @param {string} typeName - The name of the type. | |
* @param {Object} format - An object representing the format for the type. | |
* @param {Function} constructor - The constructor function for the type. | |
*/ | |
constructor(typeName, format, constructor = null) { | |
this.typeName = typeName |