UNPKG

tstosc

Version:

A transpiler that convert TypeScript to SuperCollider's SCLang.

59 lines (55 loc) 1.88 kB
'use strict'; var crypto = require('crypto'); function bin(n) { return `0b${n.toString(2)}`; } var ZipOption = /* @__PURE__ */ ((ZipOption2) => { ZipOption2["minimal_zip"] = "minimal_zip"; ZipOption2["accepting_side_length"] = "accepting_side_length"; ZipOption2["donating_side_length"] = "donating_side_length"; return ZipOption2; })(ZipOption || {}); function zip(a1, a2, option = "accepting_side_length" /* accepting_side_length */) { const counter_limit = option == "accepting_side_length" /* accepting_side_length */ ? a1.length : option == "donating_side_length" /* donating_side_length */ ? a2.length : Math.min(a1.length, a2.length); let result = new Array(counter_limit); for (let i = 0; i < counter_limit; i++) { result[i] = [a1[i], a2[i]]; } return result; } function bifilter(arr, predicate) { let quals = []; let fails = []; for (let i = 0; i < arr.length; i++) { const e = arr[i]; if (predicate(e, i, arr)) { quals.push(e); } else { fails.push(e); } } return [quals, fails]; } function memorised(f, makeKey = (...a) => a) { let cache = /* @__PURE__ */ new Map(); return function(...args) { const key = makeKey(...args); if (!cache.has(key)) { cache.set(key, f(...args)); } return cache.get(key); }; } function hash(e) { return crypto.createHash("md5").update(`${e.getSourceFile()?.fileName ?? ""}${e.kind}${e.pos}${e.end}`).digest("hex").toString(); } function isArrayLike(obj) { return Array.isArray(obj) || obj != null && obj != void 0 && typeof obj == "object" && "length" in obj && typeof obj.length == "number" && (obj.length == 0 || obj.length > 0 && obj.length - 1 in obj); } exports.ZipOption = ZipOption; exports.bifilter = bifilter; exports.bin = bin; exports.hash = hash; exports.isArrayLike = isArrayLike; exports.memorised = memorised; exports.zip = zip;