Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 28, 2021
1 parent a5ec13a commit 93eef9d
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 164 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
*.d.ts
*.log
coverage/
node_modules/
link-rel.js
link-rel.min.js
yarn.lock
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
link-rel.js
link-rel.min.js
coverage/
*.md
41 changes: 17 additions & 24 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict'

var fs = require('fs')
var https = require('https')
var concat = require('concat-stream')
var bail = require('bail')
var unified = require('unified')
var html = require('rehype-parse')
var select = require('hast-util-select')
var toString = require('hast-util-to-string')
import fs from 'fs'
import https from 'https'
import concat from 'concat-stream'
import {bail} from 'bail'
import unified from 'unified'
import html from 'rehype-parse'
import select from 'hast-util-select'
import toString from 'hast-util-to-string'

var proc = unified().use(html)

Expand All @@ -25,24 +23,19 @@ function onconcat(buf) {
bail(new Error('Couldn’t find any rels'))
}

fs.writeFile('index.json', JSON.stringify(value.sort(), 0, 2) + '\n', bail)
fs.writeFile(
'index.js',
'export var linkRel = ' + JSON.stringify(value.sort(), null, 2) + '\n',
bail
)

function table(name) {
var node = select.select('h2:has(#' + name + ') ~ table', tree)
var rows = select.selectAll('tr', node).slice(1)

return rows.map(cells).filter(filter).map(pick)
return rows
.map((row) => select.selectAll('td', row).map((d) => toString(d)))
.filter((cells) => !/not allowed/i.test(cells[1].trim()))
.map((cells) => cells[0].trim())
}
}

function cells(row) {
return select.selectAll('td', row).map(toString)
}

function filter(cells) {
return !/not allowed/i.test(cells[1].trim())
}

function pick(cells) {
return cells[0].trim()
}
114 changes: 114 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
export var linkRel = [
'DCTERMS.conformsTo',
'DCTERMS.contributor',
'DCTERMS.creator',
'DCTERMS.description',
'DCTERMS.hasFormat',
'DCTERMS.hasPart',
'DCTERMS.hasVersion',
'DCTERMS.isFormatOf',
'DCTERMS.isPartOf',
'DCTERMS.isReferencedBy',
'DCTERMS.isReplacedBy',
'DCTERMS.isRequiredBy',
'DCTERMS.isVersionOf',
'DCTERMS.license',
'DCTERMS.mediator',
'DCTERMS.publisher',
'DCTERMS.references',
'DCTERMS.relation',
'DCTERMS.replaces',
'DCTERMS.requires',
'DCTERMS.rightsHolder',
'DCTERMS.source',
'DCTERMS.subject',
'EditURI',
'alternate',
'amphtml',
'appendix',
'apple-touch-icon',
'apple-touch-icon-precomposed',
'apple-touch-startup-image',
'archived',
'attachment',
'authorization_endpoint',
'canonical',
'category',
'chapter',
'child',
'chrome-webstore-item',
'code-license',
'code-repository',
'component',
'content-license',
'content-repository',
'contents',
'copyright',
'discussion',
'dns-prefetch',
'edit',
'enclosure',
'first',
'gbfs',
'glossary',
'gtfs-realtime',
'gtfs-static',
'help',
'home',
'http://docs.oasis-open.org/ns/cmis/link/200908/acl',
'hub',
'image_src',
'import',
'in-reply-to',
'index',
'issues',
'its-rules',
'jslicense',
'last',
'license',
'manifest',
'mask-icon',
'me',
'meta',
'micropub',
'next',
'openid.delegate',
'openid.server',
'openid2.local_id',
'openid2.provider',
'p3pv1',
'parent',
'pgpkey',
'pingback',
'preconnect',
'prerender',
'prev',
'previous',
'profile',
'publisher',
'radioepg',
'rendition',
'reply-to',
'root',
'schema.DCTERMS',
'section',
'service',
'shortlink',
'sidebar',
'sitemap',
'start',
'stylesheet',
'stylesheet/less',
'subresource',
'subsection',
'sword',
'syndication',
'timesheet',
'toc',
'token_endpoint',
'transformation',
'webmention',
'widget',
'wlwmanifest',
'yandex-tableau-widget'
]
114 changes: 0 additions & 114 deletions index.json

This file was deleted.

27 changes: 12 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"main": "index.json",
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.json"
"index.js"
],
"devDependencies": {
"bail": "^1.0.0",
"browserify": "^17.0.0",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^2.0.0",
"hast-util-select": "^4.0.0",
"hast-util-to-string": "^1.0.0",
Expand All @@ -36,18 +38,15 @@
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"unified": "^9.0.0",
"xo": "^0.38.0"
},
"scripts": {
"generate": "node build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s linkRel -o link-rel.js",
"build-mangle": "browserify . -s linkRel -p tinyify -o link-rel.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test.js",
"test": "npm run format && npm run build && npm run test-api"
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -59,13 +58,11 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/no-array-callback-reference": "off"
},
"ignores": [
"link-rel.js"
]
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
Loading

0 comments on commit 93eef9d

Please sign in to comment.