UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

26 lines (25 loc) 958 B
import { parseLanguageTag } from "@phensley/language-tag"; /** * A language-tagged string which corresponds to the `rdf:langString` type. */ export class LanguageString extends String { language; /** * Constructs a new `LanguageString`. * @param value A string value written in the given language. * @param language The language of the string. If a string is given, it will * be parsed as a `LanguageTag`. */ constructor(value, language) { super(value); this.language = typeof language === "string" ? parseLanguageTag(language) : language; } [Symbol.for("Deno.customInspect")](inspect, options) { return `<${this.language.compact()}> ${inspect(this.toString(), options)}`; } [Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) { return `<${this.language.compact()}> ${inspect(this.toString(), options)}`; } }