describe('randos', () => { test('should return an array of finite random weights', () => { const temp = randos(10); const tempCheck = temp.filter((el) => Number.isFinite(el)); expect(temp.length).toBe(tempCheck.length); }); });
addToMongooseSchema(schema) { const schemaOptions = { type: Number, validate: { validator: this.buildValidator(a => typeof a === 'number' && Number.isInteger(a)), message: '{VALUE} is not an integer value', }, }; schema.add({ [this.path]: this.mergeSchemaOptions(schemaOptions, this.config) }); }
function sum (arr) { var result = 0 for (var i = 0; i < arr.length; i += 1) { result += Number.parseFloat(arr[i].time) } return result }
function val(value) { if (Number.isNaN(value)) return "-"; if (value > 1000 * 1000) return Number(value / 1000 / 1000).toFixed(0) + "M"; if (value > 1000) return Number(value / 1000).toFixed(0) + "K"; return Number(value).toFixed(0); }
const naryFunction = fn => ({ minArgs: 1, maxArgs: Number.MAX_SAFE_INTEGER, build: (ctx, args) => { let txt = `${fn}(` for (let i = 0; i < args.length; ++i) { if (i !== 0) txt += `, ` txt += build(ctx, args[i]) } return txt + ')' } })
const stackedBarChartData = (resultSet) => { const data = resultSet.pivot().map( ({ xValues, yValuesArray }) => yValuesArray.map(([yValues, m]) => ({ x: resultSet.axisValuesString(xValues, ', '), color: resultSet.axisValuesString([yValues[0]], ', '), [yValues[1]]: m && Number.parseFloat(m) })) ).reduce((a, b) => a.concat(b)); return data; }
function validateBodyLimitOption (bodyLimit) { if (bodyLimit === undefined) return if (!Number.isInteger(bodyLimit) || bodyLimit <= 0) { throw new TypeError(`'bodyLimit' option must be an integer > 0. Got '${bodyLimit}'`) } }
const isPositiveInteger = value => { if (value === null || value === '') return false; const number = parseInt(value, 10); return !Number.isNaN(number) && number > 0; }
/** * The FETCH request can block up to maxWaitTime, which can be bigger than the configured * request timeout. It's safer to always use the maxWaitTime **/ const requestTimeout = timeout => Number.isSafeInteger(timeout + NETWORK_DELAY) ? timeout + NETWORK_DELAY : timeout
getSource(value) { if (this.origin === 'constants') { if (Number.isInteger(value)) { return `const float ${this.id} = ${value}.0;\n`; } return `const float ${this.id} = ${value};\n`; } return `uniform float ${this.id};\n`; }
/** * Checks to see if the value is NaN, null, undefined, * an empty string, or an empty array/object. */ function isEmpty(val: any) { return ( val == null || Number.isNaN(val) || isEmptyObject(val) || isEmptyString(val) ) }
export function setItem(key, value, duration = Number.MAX_SAFE_INTEGER) { storeStorage[key] = { value, duration, time: Date.now() }; store(); }
const parseIntValue = value => { if (typeof value === 'string') { const int = Number(value); if (Number.isInteger(int)) { return int; } } throw new TypeValidationError(value, 'Int'); }
humanReadableBytes(bytes) { if (bytes == null || Number.isNaN(bytes)) return "-"; if (bytes >= 1000 * 1000) return `${(bytes / 1000 / 1000).toFixed(0)} MB`; if (bytes >= 1000) return `${(bytes / 1000).toFixed(0)} kB`; else return `${bytes.toFixed(0)} B`; }
humanReadableBps(bpm) { if (bpm == null || Number.isNaN(bpm)) return "-"; const bps = (bpm * 8) / 60; if (bps >= 1000 * 1000) return `${(bps / 1000 / 1000).toFixed(0)} Mbps`; if (bps >= 1000) return `${(bps / 1000).toFixed(0)} kbps`; else return `${bps.toFixed(0)} bps`; }