UNPKG

yahoo-finance2

Version:
46 lines (45 loc) 1.45 kB
"use strict"; // Copyright 2018-2025 the Deno authors. MIT license. // This module is browser compatible. Object.defineProperty(exports, "__esModule", { value: true }); exports.stripSuffix = stripSuffix; exports.lastPathSegment = lastPathSegment; exports.assertArgs = assertArgs; const assert_path_js_1 = require("./assert_path.js"); function stripSuffix(name, suffix) { if (suffix.length >= name.length) { return name; } const lenDiff = name.length - suffix.length; for (let i = suffix.length - 1; i >= 0; --i) { if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) { return name; } } return name.slice(0, -suffix.length); } function lastPathSegment(path, isSep, start = 0) { let matchedNonSeparator = false; let end = path.length; for (let i = path.length - 1; i >= start; --i) { if (isSep(path.charCodeAt(i))) { if (matchedNonSeparator) { start = i + 1; break; } } else if (!matchedNonSeparator) { matchedNonSeparator = true; end = i + 1; } } return path.slice(start, end); } function assertArgs(path, suffix) { (0, assert_path_js_1.assertPath)(path); if (path.length === 0) return path; if (typeof suffix !== "string") { throw new TypeError(`Suffix must be a string, received "${JSON.stringify(suffix)}"`); } }