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); }
const replacedLines = lines.map((line) => { return indent + line; });
/** * Convert Base58 address to an Array that fits into Sonar contract. * @param {String} ipfsAddress */ addressToArray (ipfsAddress) { const targetLength = 64 // fill the address with 0 at the end to this length const parts = ipfsAddress.match(/.{1,32}/g) // split into 32-chars .map(part => part.split('').map(c => c.charCodeAt(0).toString(16)).join('')) // turn each part into a hexString address .map(part => part.concat('0'.repeat(targetLength - part.length))) // 0 pad at the end .map(part => '0x' + part) // prefix as hex return parts }
parsed.pathname.match(/\/|%[0-9a-fA-F]{2,2}|./g).map(function (i) { if (i === '/') return i; if (i[0] === '%') return i; return encodeURIComponent(i); }).join('')
static parseHex (text) { if (this.HEX_REGEX.test(text)) { const [ , HEX, A ] = this.HEX_REGEX.exec(text) const rgba = HEX.match(/[a-f\d]{2}/gi).map(parseHexValue) // Base hex rgba.push(parseHexAlpha(A || 'ff')) // Alpha return rgba } }
/** * Convert a hex string to an ArrayBuffer. * * @param {string} hexString - hex representation of bytes * @return {ArrayBuffer} - The bytes in an ArrayBuffer. */ export default function hexStringToArrayBuffer(hexString) { // remove the leading 0x hexString = hexString.replace(/^0x/, ''); // split the string into pairs of octets const pairs = hexString.match(/[\dA-F]{2}/gi); // convert the octets to integers const integers = pairs ? pairs.map(s => parseInt(s, 16)) : []; return new Uint8Array(integers).buffer; }
// Decompose value function decomposeValue(val, unit) { var rgx = /-?\d*\.?\d+/g; var value = validateValue((is.pth(val) ? val.totalLength : val), unit) + ''; return { original: value, numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0], strings: (is.str(val) || unit) ? value.split(rgx) : [] } }
/** * Parse a an ordered list of failover addresses without an explicit priority. * @private * @param {string} input - formatted string with a list of addresses (check examples) * @throws {Error} When the host is not valid. * @returns {Address[]} List of addresses. * @example * const addressList = '[[::1]:33060, localhost:33060, 127.0.0.1:33060]' */ function parseAddressListWithoutPriority (input) { const singles = input.trim().match(/[^,]+/g) || []; return singles.length > 1 ? singles.map(parsePlainAddress) : []; }
const npmDependencies = async () => { const lambdaFile = await readFile(`${stagingPath}/${lambdaName}/index.js`, 'utf8'); const dependencies = lambdaFile.split('exports')[0].match(/require\([^)]+\)/g) || []; return dependencies.map(pkg => pkg.slice(9, -2)).filter(pkg => !isNativeModule(pkg)); }
const download_hls_video = async (url, video_name, chapter_path, auth_headers) => { try { const response = await get_request(url, {'User-Agent': 'okhttp/3.11.0', ...auth_headers}); const video_resolutions = response.body.match(/RESOLUTION=(\d+)x(\d+)/g).map(r => r.match(/x(\d+)/)[1]); let video_quality_index = 0; let quality_position = ' '; const auth_header_hls = `-user-agent "okhttp/3.11.0" -headers "Authorization: ${auth_headers.Authorization}"`; if (commander.quality) { video_quality_index = video_resolutions.findIndex(r => r === `${commander.quality}`); if (video_quality_index !== -1) { // -map p:1 // choose second resolution quality_position = ` -map p:${video_quality_index} `; } } await save_video({url, quality_position, video_name, chapter_path, auth_header_hls}); } catch (error) { if (error['statusCode'] === 403) { throw new Error('403'); } handle_error({error}); } }
/** * Extracts the parameter names from the provided path expression. * * @param {string} pathExpression The path expression. * @return {string[]} The names of the parameters defined in the provided * path expression. */ _getParameterNames(pathExpression) { let rawNames = pathExpression.match(PARAMS_REGEXP_UNIVERSAL) || []; return rawNames.map(rawParameterName => { return rawParameterName.substring(1).replace('?', ''); }); }
/** * Check if main parametres have correct order. * It means that required param cannot follow optional one. * * @param {string} clearedPathExpr The cleared URL path (removed first and last slash, ...). * @return {Bool} Returns TRUE if order is correct. */ _checkParametersOrder(clearedPathExpr) { const mainParamsMatches = clearedPathExpr.match(PARAMS_MAIN_REGEXP) || []; const allMainParamsCleared = mainParamsMatches.map(paramExpr => this._getClearParamName(paramExpr) ); const isCorrectParamOrder = this._checkOptionalParamsOrder( allMainParamsCleared ); return isCorrectParamOrder; }
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); }
// Decompose value function decomposeValue(val, unit) { var rgx = /-?\d*\.?\d+/g; var value = validateValue((is.pth(val) ? val.totalLength : val), unit) + ''; return { original: value, numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0], strings: (is.str(val) || unit) ? value.split(rgx) : [] } }