UNPKG

@httpc/kit

Version:

httpc toolbox for building function-based API with minimal code and end-to-end type safety

53 lines (52 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.equals = exports.match = exports.simplify = void 0; function simplify(token) { if (typeof token === "string") { return token; } else if (token.length === 1) { return token[0]; } else { return token; } } exports.simplify = simplify; function matchSingle(source, target) { return source === target || target === "*"; } function match(source, target) { // simplify first source = simplify(source); target = simplify(target); if (typeof source === "string" && typeof target === "string") { return matchSingle(source, target); } if (Array.isArray(source) && Array.isArray(target)) { if (source.length !== target.length) return false; for (let a = 0; a < source.length; a++) { if (!matchSingle(source[a], target[a])) return false; } return true; } return false; } exports.match = match; function equals(t1, t2) { t1 = simplify(t1); t2 = simplify(t2); if (t1 === t2) return true; if (Array.isArray(t1) && Array.isArray(t2) && t1.length === t2.length) { for (let a = 0; a < t1.length; a++) { if (t1[a] !== t2[a]) return false; } return true; } return false; } exports.equals = equals;