From 7a52ddeba2a68388b544f529d2d92104420f77b0 Mon Sep 17 00:00:00 2001 From: Shipwreckt Date: Fri, 31 Oct 2025 20:02:14 +0000 Subject: Changed from static to 11ty! --- node_modules/bcp-47/lib/stringify.js | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 node_modules/bcp-47/lib/stringify.js (limited to 'node_modules/bcp-47/lib/stringify.js') diff --git a/node_modules/bcp-47/lib/stringify.js b/node_modules/bcp-47/lib/stringify.js new file mode 100644 index 0000000..e5b367a --- /dev/null +++ b/node_modules/bcp-47/lib/stringify.js @@ -0,0 +1,50 @@ +/** + * @typedef {Partial} Schema + * @typedef {Partial} Extension + */ + +/** + * Compile a language schema to a BCP 47 language tag. + * + * @param {Schema} schema + * @returns {string} + */ +export function stringify(schema = {}) { + /** @type {Array} */ + let result = [] + + if (schema.irregular) { + return schema.irregular + } + + if (schema.regular) { + return schema.regular + } + + if (schema.language) { + result = result.concat( + schema.language, + schema.extendedLanguageSubtags || [], + schema.script || [], + schema.region || [], + schema.variants || [] + ) + + const values = schema.extensions || [] + let index = -1 + + while (++index < values.length) { + const value = values[index] + + if (value.singleton && value.extensions && value.extensions.length > 0) { + result.push(value.singleton, ...value.extensions) + } + } + } + + if (schema.privateuse && schema.privateuse.length > 0) { + result.push('x', ...schema.privateuse) + } + + return result.join('-') +} -- cgit v1.2.3