View TargetClosure.swift
//
// TargetClosure is a bridge from closures to objc targets/selectors
// Create a TargetClosure with a closure and pass it as the target, then pass target.selector as the selector.
//
// Example:
//
// let target = TargetClosure { doYourThing() }
// oldSchoolFunction(target: target, action: target.selector)
//
View Queue.swift
public class Queue<T> {
public private(set) var size: Int = 0
private var head: QueueNode<T>? = nil
private var tail: QueueNode<T>? = nil
public func enqueue(_ value: T) {
let newTail = QueueNode(value: value)
if let oldTail = tail {
newTail.prev = oldTail
oldTail.next = newTail
View promise.js
import Queue from './queue';
const STATE_PENDING = 'pending';
const STATE_RESOLVED = 'resolved';
const STATE_REJECTED = 'rejected';
const states = new WeakMap();
const values = new WeakMap();
const queues = new WeakMap();
View rand31.js
export default createFromSeed(randomSeed());
export function createFromSeed(seed) {
if (!Number.isInteger(seed) || seed <= 0) {
throw new TypeError('seed must be an int > 0');
}
let value = seed;
const next = () => {
const hi = 16807 * (value >> 16);
View url-safe-base64.js
const encode_regex = /[\+=\/]/g;
const decode_regex = /[\._\-]/g;
// Buffer -> Base64 String -> Url Safe Base64 String
export function encode(buffer) {
return buffer.toString('base64').replace(encode_regex, encodeChar);
}
// Url Safe Base64 String -> Base64 String -> Buffer
export function decode(string) {
View axial-coordinates.js
/**
Axial coordinates
# convert cube to axial
q = x
r = z
# convert axial to cube
x = q
z = r
View function-proxy.js
exports.proxy = function(length, fn) {
return createProxyFactory(length)(fn);
}
function createProxyFactory(length) {
return Function(
'var fn = arguments[0];' +
'return function(' + argNames(length) + '){' +
' return fn.apply(this, arguments);' +
'}'
View deprecate-property.js
function deprecate(obj, prop) {
Object.defineProperty(obj, prop, {
enumerable: true,
get: function() {
throw new Error('Property ' + prop + ' is deprecated!');
}
});
}
View StringBuilder.js
/* @flow */
export class StringBuilder {
encoding: string;
byte_length: number;
list: Array<Buffer>;
constructor(encoding?: string = 'utf8') {
this.encoding = encoding;
this.byte_length = 0;
View modulo.js
function modulo(a, b) {
var r = a % b;
return (r * b < 0) ? r + b : r;
}
function nthArrayItem(array, n) {
return array[modulo(n, array.length)];
}