UNPKG

taglib-wasm

Version:

TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps

74 lines (73 loc) 2.21 kB
import { ADDITIONAL_PROPERTIES } from "./additional-properties.js"; import { BASIC_PROPERTIES } from "./basic-properties.js"; import { GENERAL_EXTENDED_PROPERTIES } from "./general-extended-properties.js"; import { SPECIALIZED_PROPERTIES } from "./specialized-properties.js"; const PROPERTIES = { ...BASIC_PROPERTIES, ...GENERAL_EXTENDED_PROPERTIES, ...SPECIALIZED_PROPERTIES, ...ADDITIONAL_PROPERTIES }; const _toTagLib = {}; const _fromTagLib = {}; for (const [camelKey, meta] of Object.entries(PROPERTIES)) { const wireKey = meta.key; _toTagLib[camelKey] = wireKey; _fromTagLib[wireKey] = camelKey; } _toTagLib["year"] = "DATE"; _toTagLib["track"] = "TRACKNUMBER"; _fromTagLib["disc"] = "discNumber"; function toTagLibKey(key) { return _toTagLib[key] ?? key; } const _mp4FreeformAtoms = {}; for (const meta of Object.values(PROPERTIES)) { const { key, mappings } = meta; const atom = mappings?.mp4; if (typeof atom !== "string" || !atom.startsWith("----:")) continue; const bare = atom.slice(atom.lastIndexOf(":") + 1); if (bare === bare.toUpperCase()) continue; _mp4FreeformAtoms[key] = atom; const readKey = bare.toUpperCase(); const camel = _fromTagLib[key]; if (camel !== void 0 && _fromTagLib[readKey] === void 0) { _fromTagLib[readKey] = camel; } } const _mp4AtomToWireKey = {}; for (const meta of Object.values(PROPERTIES)) { const { key, mappings } = meta; const atom = mappings?.mp4; if (typeof atom !== "string" || atom.startsWith("----:")) continue; if (_mp4AtomToWireKey[atom] === void 0) _mp4AtomToWireKey[atom] = key; } function mp4AtomWireKey(atom) { return _mp4AtomToWireKey[atom]; } function mp4FreeformAtomNames(wireKeys) { const names = []; for (const key of wireKeys) { const atom = _mp4FreeformAtoms[key]; if (atom !== void 0) names.push(atom); } return names; } function fromTagLibKey(key) { return _fromTagLib[key] ?? key; } function remapKeysFromTagLib(obj) { const result = {}; for (const [key, value] of Object.entries(obj)) { result[fromTagLibKey(key)] = value; } return result; } export { PROPERTIES, fromTagLibKey, mp4AtomWireKey, mp4FreeformAtomNames, remapKeysFromTagLib, toTagLibKey };