Skip to content

Commit

Permalink
Fix minimizing of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 9, 2021
1 parent 63f8688 commit 0ad994e
Show file tree
Hide file tree
Showing 9 changed files with 2,292 additions and 523 deletions.
48 changes: 29 additions & 19 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ import {normal} from 'bcp-47/lib/normal.js'

var own = {}.hasOwnProperty

/** @type {{supplemental: {likelySubtags: Object.<string, string>}}} */
var data = JSON.parse(
String(
fs.readFileSync(
path.join(
'node_modules',
'cldr-core',
'supplemental',
'likelySubtags.json'
)
)
)
)

var likelySubtags = data.supplemental.likelySubtags

/** @type {Object.<string, string>} */
var likely = {}
/** @type {string} */
var key

for (key in likelySubtags) {
if (own.call(likelySubtags, key)) {
likely[key.toLowerCase()] = likelySubtags[key].toLowerCase()
}
}

write('likely', likely)

var endpoint =
'https://raw.githubusercontent.com/unicode-org/cldr/HEAD/common/supplemental/supplementalMetadata.xml'

Expand All @@ -28,8 +57,6 @@ fetch(endpoint)
function onbody(doc) {
/** @type {Array.<Field>} */
var fields = []
/** @type {Array.<string>} */
var defaults = []
/** @type {Object.<string, Object.<string, Array.<string>>>} */
var many = {}
/** @type {Array.<Match>} */
Expand All @@ -45,10 +72,6 @@ function onbody(doc) {

visit(fromXml(doc), 'element', onelement)

// Sort by length first, then alphabetical.
defaults.sort(sort)

write('defaults', defaults)
write('fields', fields)
write('many', many)
write('matches', match)
Expand All @@ -67,10 +90,6 @@ function onbody(doc) {
/** @type {string} */
var to

if (name === 'defaultContent') {
defaults = defaults.concat(clean(node.attributes.locales))
}

if (pos === -1) {
return
}
Expand Down Expand Up @@ -190,12 +209,3 @@ function write(name, values) {
'export const ' + name + ' = ' + JSON.stringify(values, null, 2) + '\n'
)
}

/**
* @param {string} a
* @param {string} b
* @returns {number}
*/
function sort(a, b) {
return b.length - a.length || a.localeCompare(b)
}
311 changes: 0 additions & 311 deletions lib/defaults.js

This file was deleted.

Loading

0 comments on commit 0ad994e

Please sign in to comment.