Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _matchUrl(expected: string | RegExp | undefined, actual: string): boolean {
if (isString(expected)) {
if (expected === actual) {
return true
}
// expected: /hello/world
// actual: /hello/world?type=1
if (actual.indexOf(expected) === 0 && actual[expected.length] === '?') {
return true
}
if (expected.indexOf('/') === 0) {
return rgx(expected).pattern.test(actual)
}
}
if (isRegExp(expected)) {
return expected.test(actual)
}
return false
}
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('./package');
const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();
mkdir('dist').then(() => {
// Copy as is for ESM
fs.writeFileSync(pkg.module, ESM);
// Mutate (im|ex)ports for CJS
const CJS = regexparam.replace('function ', 'function convert ').concat(
ESM.replace(`import convert from 'regexparam';`, '')
.replace(/export default/, 'module.exports =')
);
fs.writeFileSync(pkg.main, CJS);
// Minify & print gzip-size
const { code } = minify(CJS, { toplevel:true, compress:{ passes:10 } });
console.log(`> gzip size: ${pretty(sizer.sync(code))}`);
path = path.substring(1)
}
}
// Default class name
if (!className) {
className = 'active'
}
// Path must start with '/' or '*'
if (!path || path.length < 1 || (path.charAt(0) != '/' && path.charAt(0) != '*')) {
throw Error('Invalid value for "path" argument')
}
// Get the regular expression
const {pattern} = regexparam(path)
// Add the node to the list
const el = {
node,
className,
pattern
}
nodes.push(el)
// Trigger the action right away
checkActive(el)
return {
// When the element is destroyed, remove it from the list
destroy() {
nodes.splice(nodes.indexOf(el), 1)
const fs = require('fs');
const mkdir = require('mk-dirs');
const pretty = require('pretty-bytes');
const { minify } = require('terser');
const sizer = require('gzip-size');
const pkg = require('../package');
const ESM = fs.readFileSync('src/index.js', 'utf8');
const regexparam = require('regexparam').toString();
mkdir('dist').then(() => {
// Copy as is for ESM
fs.writeFileSync(pkg.module, ESM);
// Mutate (im|ex)ports for CJS
const CJS = ESM.replace(
`import toRegExp from 'regexparam';`,
`var toRegExp = require('regexparam');`
).replace(/export default/, 'module.exports =')
fs.writeFileSync(pkg.main, CJS);
// Mutate again for UMD prep :: inline dependency
const INLINED = regexparam.replace('function ', 'function toRegExp').concat(
CJS.replace(`var toRegExp = require('regexparam');`, '')
export default function (manifest, uri, wCommon) {
var k,
tmp = wCommon && manifest['*'] || [],
headers = tmp.headers || [],
files = tmp.files || tmp;
for (k in manifest) {
if (k != '*' && toRegExp(k).pattern.test(uri)) {
tmp = manifest[k];
files = files.concat(tmp.files || tmp);
headers = headers.concat(tmp.headers || []);
break;
}
}
return {
files: files,
headers: headers,
};
}
import { join as pathJoin } from 'path'
import regexParam from 'regexparam'
import fetch from 'isomorphic-unfetch'
const githubBlobUrl = regexParam('blob/:ref/*')
const isEmpty = obj =>
[Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length
const exec = (path, result) => {
let i = 0
let out = {}
let matches = result.pattern.exec(path) || {}
while (i < result.keys.length) out[result.keys[i]] = matches[++i] || null
return out
}
export default ({ isMarkdownPath, GITHUB_TOKEN, ALTERNATIVE_README_NAMES }) => {
const fetchReadme = ({ owner, repo, path, ref }) => {
return fetch(`https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${ref}`, {
headers: {
REGEX_HTTP_PROTOCOL,
SITE_URL,
REGEX_LOCAL_URL,
REGEX_START_WITH_LETTER_OR_NUMBER
} = require('../constants')
const { URL } = url
const extension = (str = '') => {
const urlObj = url.parse(str)
urlObj.hash = ''
urlObj.search = ''
return fileExtension(url.format(urlObj))
}
const { pattern: githubRegexParam } = regexParam('/:owner/:repo')
const loadHTML = html =>
cheerio.load(html, {
xmlMode: false,
lowerCaseTags: true,
decodeEntities: true,
lowerCaseAttributeNames: true
})
const resolveUrl = (from, to) => {
if (to[0] === '/') to = to.substr(1)
return url.resolve(from, to)
}
const withAnchorLinks = $ => {
$('h1, h2, h3, h4, h5, h6').each(function () {
$.on = function (pat, fn) {
(pat = convert(pat)).fn = fn;
routes.push(pat);
return $;
}
import url from 'url'
import qsm from 'qsm'
import build from '../../build'
import { extension, resolveUrl, resolveAssetUrl } from './util'
const {
REGEX_HTTP_PROTOCOL,
SITE_URL,
REGEX_LOCAL_URL,
REGEX_START_WITH_LETTER_OR_NUMBER
} = require('../../../constants')
const { URL } = url
const { pattern: githubRegexParam } = regexParam('/:owner/:repo')
const loadHTML = html =>
cheerio.load(html, {
xmlMode: false,
lowerCaseTags: true,
decodeEntities: true,
lowerCaseAttributeNames: true
})
const withAnchorLinks = $ => {
$('h1, h2, h3, h4, h5, h6').each(function () {
const el = $(this)
const text = el.text()
const slug = el.attr('id')
el.removeAttr('id')
el.html(