export default function dehumanizeTime(input) { if (typeof input !== 'string') { return NaN; } const parts = input.replace(/ /g, '').match(ALPHA_NUMERIC_DOT); const sets = parts.map(part => part.split(ALPHA_NUMERIC_DOT).filter(o => o)); return sets.reduce((accum, [number, unit]) => { return accum + parseFloat(number) * TIMES[unit]; }, 0); }
dP(FProto, NAME, { configurable: true, get: function () { try { return ('' + this).match(nameRE)[1]; } catch (e) { return ''; } } })
test('parses and outputs chindings', async ({ is, isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'child.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h2/), null) isNot(strip(actual).match(/a: 1/), null) isNot(strip(actual).match(/b: 2/), null) is(strip(actual).match(/a: 1/g).length, 3) })
function clearAllCookie() { var keys = document.cookie.match(/[^ =;]+(?=\=)/g); if(keys) { for(var i = 0;i<keys.length;i++) { delCookie(keys[i]); } } }
// Helpers functions to convert the RSA certs to PEM (from jwks-rsa) function rsaPublicKeyToPEM(modulusB64, exponentB64) { const modulus = new Buffer(modulusB64, 'base64'); const exponent = new Buffer(exponentB64, 'base64'); const modulusHex = prepadSigned(modulus.toString('hex')); const exponentHex = prepadSigned(exponent.toString('hex')); const modlen = modulusHex.length / 2; const explen = exponentHex.length / 2; const encodedModlen = encodeLengthHex(modlen); const encodedExplen = encodeLengthHex(explen); const encodedPubkey = '30' + encodeLengthHex(modlen + explen + encodedModlen.length / 2 + encodedExplen.length / 2 + 2) + '02' + encodedModlen + modulusHex + '02' + encodedExplen + exponentHex; const der = new Buffer(encodedPubkey, 'hex').toString('base64'); let pem = '-----BEGIN RSA PUBLIC KEY-----\n'; pem += `${der.match(/.{1,64}/g).join('\n')}`; pem += '\n-----END RSA PUBLIC KEY-----\n'; return pem; }
forEachLine(lineMetadata(), function (line, lineIndex, inCode) { var match = null; // eslint-disable-next-line no-unmodified-loop-condition while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { var tag = match[0], content = match[1], element = match[2]; if (!allowedElements.includes(element.toLowerCase()) && !tag.endsWith("\\>") && !emailAddressRe.test(content)) { var prefix = line.substring(0, match.index); if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) { var unescaped = unescapeMarkdown(prefix + "<", "_"); if (!unescaped.endsWith("_") && ((unescaped + "`").match(/`/g).length % 2)) { addError(onError, lineIndex + 1, "Element: " + element, null, [match.index + 1, tag.length]); } } } } });
// Retrieve Google Signin Keys (with cache control) function getGoogleKeyByKeyId(keyId) { if (cache[keyId] && cache.expiresAt > new Date()) { return cache[keyId]; } return new Promise((resolve, reject) => { https.get(`https://www.googleapis.com/oauth2/v3/certs`, res => { let data = ''; res.on('data', chunk => { data += chunk.toString('utf8'); }); res.on('end', () => { const {keys} = JSON.parse(data); const pems = keys.reduce((pems, {n: modulus, e: exposant, kid}) => Object.assign(pems, {[kid]: rsaPublicKeyToPEM(modulus, exposant)}), {}); if (res.headers['cache-control']) { var expire = res.headers['cache-control'].match(/max-age=([0-9]+)/); if (expire) { cache = Object.assign({}, pems, {expiresAt: new Date((new Date()).getTime() + Number(expire[1]) * 1000)}); } } resolve(pems[keyId]); }); }).on('error', reject); }); }
function parseDuration(duration, defaultDuration) { if (typeof duration === 'number') return duration if (typeof duration === 'string') { var split = duration.match(/^([\d\.,]+)\s?(\w+)$/) if (split.length === 3) { var len = parseFloat(split[1]) var unit = split[2].replace(/s$/i, '').toLowerCase() if (unit === 'm') { unit = 'ms' } return (len || 1) * (t[unit] || 0) } } return defaultDuration }
/** * Remove front matter (if present at beginning of content). * * @param {string} content Markdown content. * @param {RegExp} frontMatter Regular expression to match front matter. * @returns {Object} Trimmed content and front matter lines. */ function removeFrontMatter(content, frontMatter) { var frontMatterLines = []; if (frontMatter) { var frontMatterMatch = content.match(frontMatter); if (frontMatterMatch && !frontMatterMatch.index) { var contentMatched = frontMatterMatch[0]; content = content.slice(contentMatched.length); frontMatterLines = contentMatched.split(helpers.newLineRe); if (frontMatterLines.length && (frontMatterLines[frontMatterLines.length - 1] === "")) { frontMatterLines.length--; } } } return { "content": content, "frontMatterLines": frontMatterLines }; }
/** * Pull out keys from a regexp. * * @param {RegExp} path * @param {Array} keys * @return {RegExp} */ function regexpToRegexp (path, keys) { // Use a negative lookahead to match only capturing groups. var groups = path.source.match(/\((?!\?)/g); if (groups) { for (var i = 0; i < groups.length; i++) { keys.push({ name: i, delimiter: null, optional: false, repeat: false }); } } return attachKeys(path, keys); }
test('parses and outputs chindings with serializer', async ({ is, isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'child-with-serializer.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h2/), null) isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h3/), null) isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h4/), null) isNot(strip(actual).match(/a: 2/), null) isNot(strip(actual).match(/a: 16/), null) isNot(strip(actual).match(/a: 42/), null) is(strip(actual).match(/a: /g).length, 4) })
function getCookieObj() { var obj={}; var keys = document.cookie.match(/[^ =;]+(?=\=)/g); if(keys) { for(var i = 0;i<keys.length;i++) { obj[keys[i]]=getCookie(keys[i]); } } return obj; }
export default function dehumanizeTime(input) { if (typeof input !== 'string') { return NaN; } const parts = input.replace(/ /g, '').match(ALPHA_NUMERIC_DOT); const sets = parts.map(part => part.split(ALPHA_NUMERIC_DOT).filter(o => o)); return sets.reduce((accum, [number, unit]) => { return accum + parseFloat(number) * TIMES[unit]; }, 0); }
// Helpers functions to convert the RSA certs to PEM (from jwks-rsa) function rsaPublicKeyToPEM(modulusB64, exponentB64) { const modulus = new Buffer(modulusB64, 'base64'); const exponent = new Buffer(exponentB64, 'base64'); const modulusHex = prepadSigned(modulus.toString('hex')); const exponentHex = prepadSigned(exponent.toString('hex')); const modlen = modulusHex.length / 2; const explen = exponentHex.length / 2; const encodedModlen = encodeLengthHex(modlen); const encodedExplen = encodeLengthHex(explen); const encodedPubkey = '30' + encodeLengthHex(modlen + explen + encodedModlen.length / 2 + encodedExplen.length / 2 + 2) + '02' + encodedModlen + modulusHex + '02' + encodedExplen + exponentHex; const der = new Buffer(encodedPubkey, 'hex') .toString('base64'); let pem = '-----BEGIN RSA PUBLIC KEY-----\n'; pem += `${der.match(/.{1,64}/g).join('\n')}`; pem += '\n-----END RSA PUBLIC KEY-----\n'; return pem; }
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { let match = null; // eslint-disable-next-line no-unmodified-loop-condition while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) { const [ tag, content, element ] = match; if (!allowedElements.includes(element.toLowerCase()) && !tag.endsWith("\\>") && !emailAddressRe.test(content)) { const prefix = line.substring(0, match.index); if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) { const unescaped = unescapeMarkdown(prefix + "<", "_"); if (!unescaped.endsWith("_") && ((unescaped + "`").match(/`/g).length % 2)) { addError(onError, lineIndex + 1, "Element: " + element, null, [ match.index + 1, tag.length ]); } } } } });