Skip to content

Other functions

All of these are exported from trackparse. The Python package has the same functions in snake_case:

JavaScript Python
parse parse
parseArtists parse_artists
format format_track
normalize normalize
allArtists all_artists
createParser create_parser
SPEC_VERSION SPEC_VERSION
parseTracklist, applyEdits (from trackparse/tracklist) parse_tracklist, apply_edits (from trackparse.tracklist)

Options are keyword arguments in Python, and fields are snake_case attributes (full_title, unknown_artist). Every function raises TypeError if the input isn't a str; anything else, including bad options, falls back to defaults.

(Python: parse_artists)

Splits a bare artist string, with no title, into credits.

parseArtists("Sub Focus, Wilkinson & Dimension feat. Kojo").map((a) => `${a.name}:${a.role}`);
// [ 'Sub Focus:primary', 'Wilkinson:primary', 'Dimension:primary', 'Kojo:featured' ]

Takes knownArtists, splitAnd and keywords (known_artists, split_and, keywords). Useful for the artist field of ID3 tags or a streaming API, where the title is already separate.

(Python: format_track)

Renders a ParsedTrack back to a string. The options are feat, featMarker (feat_marker), joiners, versions, producers and position. Formatting has examples of each.

The Unicode cleanup every function runs first. It applies NFC, removes invisible characters (zero-width spaces, BOMs, soft hyphens), turns dash, bracket and quote variants into their plain ASCII forms, and collapses whitespace.

normalize("Noisia​ — “Stigma”"); // 'Noisia - "Stigma"'

You don't need to call it before parse. It's exported because it's handy for building lookup keys.

(Python: all_artists)

Every credit of a track in one list: the artists, then every remixer, with duplicates removed.

allArtists(parse("Wilkinson ft. Becky Hill - Afterglow (Sub Focus Remix)")).map((a) => `${a.name}:${a.role}`);
// [ 'Wilkinson:primary', 'Becky Hill:featured', 'Sub Focus:remixer' ]

(Python: create_parser)

Compiles options and keywords once and returns an object with parse and parseArtists (parse_artists). Per-call options are merged over the compiled ones. Use it when you parse many strings with the same knownArtists or keywords.

import { createParser } from "trackparse";
const parser = createParser({
knownArtists: ["Chase & Status", "Camo & Krooked"],
keywords: { versionHeads: { rerub: "rework" } },
});
parser.parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)").versions[0].type;
// 'rework'

The version of the spec the package implements, as a string. The packages and the spec are released together, so it's the same as the package version.