Skip to content

Commit

Permalink
build: only pull in iana extensions for common usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jul 15, 2018
1 parent a9feed6 commit d3100a1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/fetch-iana.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var writedb = require('./lib/write-db')

var extensionsRegExp = /^\s*(?:\d\.\s+)?File extension(?:\(s\)|s|)\s?:\s+(?:\*\.|\.|)([0-9a-z_-]+)\s*(?:\(|$)/im
var extensionsQuotedRegExp = /^\s*(?:\d\.\s+)?File extension(?:\(s\)|s|)\s?:(?:[^'"\r\n]+)(?:"\.?([0-9a-z_-]+)"|'\.?([0-9a-z_-]+)')/im
var intendedUsageRegExp = /^\s*(?:(?:\d{1,2}\.|o)\s+)?Intended\s+Usage\s*:\s*(\S+)/im
var leadingSpacesRegExp = /^\s+/
var listColonRegExp = /:(?:\s|$)/m
var nameWithNotesRegExp = /^(\S+)(?: - (.*)$| \((.*)\)$|)/
Expand Down Expand Up @@ -118,7 +119,7 @@ function addTemplateData (data, options) {
data.mime = mime

// use extracted extensions
if (opts.extensions) {
if (opts.extensions && extractIntendedUsage(body) === 'common') {
data.extensions = extractTemplateExtensions(body)
}
}
Expand All @@ -127,6 +128,14 @@ function addTemplateData (data, options) {
}
}

function extractIntendedUsage (body) {
var match = intendedUsageRegExp.exec(body)

return match
? match[1].toLocaleLowerCase()
: undefined
}

function extractTemplateMime (body) {
var type = mimeTypeLineRegExp.exec(body)
var subtype = mimeSubtypeLineRegExp.exec(body)
Expand Down

0 comments on commit d3100a1

Please sign in to comment.