How to use the ow.array function in ow

To help you get started, we’ve selected a few ow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomiclabs / hyperdex / app / renderer / fetch-currency-info.js View on Github external
const fetchCurrencyInfo = async symbols => {
	ow(symbols, 'symbols', ow.array.ofType(ow.string.uppercase));

	const filteredSymbols = symbols.filter(symbol => !ignoreExternalPrice.has(symbol));

	const ids = filteredSymbols
		.map(symbol => coinlist.get(symbol, 'id'))
		.filter(symbol => symbol !== undefined); // For example, SUPERNET

	// Docs: https://www.coingecko.com/api/docs/v3#/coins/get_coins_markets
	let data;
	try {
		const response = await fetch(`${baseURL}/coins/markets?vs_currency=usd&ids=${ids.join(',')}`);
		data = await response.json();
	} catch (error) {
		console.error('Failed to fetch from CoinGecko API:', error);
		data = [];
	}
github transitive-bullshit / primitive / lib / context.js View on Github external
export const saveGIF = async (frames, filename, opts) => {
  ow(frames, ow.array.label('frames'))
  ow(filename, ow.string.label('filename').nonEmpty)
  ow(opts, ow.object.label('opts').plain.nonEmpty)

  const {
    // gif output options
    gifski = {
      fps: 10,
      quality: 80,
      fast: false
    }
  } = opts

  const params = [
    '-o', filename,
    '--fps', gifski.fps,
    gifski.fast && '--fast',
github liaisonjs / liaison / packages / layer / src / layer.js View on Github external
async $batch(func) {
    if (!this.$isBatched()) {
      this._setBatchState({count: 1, batchedQueries: []});
    } else {
      const {count} = this._getBatchState();
      this._setBatchState({count: count + 1});
    }

    try {
      const promises = await func(this);

      ow(promises, ow.array);

      for (const promise of promises) {
        if (isPromise(promise)) {
          // Let's ignore rejected promise for now so we can avoid
          // unhandled promise rejection warning.
          // Errors are caught later with `await promise`.
          promise.catch(() => {});
        }
      }

      while (true) {
        await new Promise(resolve => setTimeout(resolve, 0)); // Prioritize microtasks

        const {batchedQueries} = this._getBatchState();

        if (batchedQueries.length === 0) {
github jsdoc / jsdoc / packages / jsdoc-cli / lib / engine.js View on Github external
parseFlags(cliFlags) {
        ow(cliFlags, ow.array);

        let normalizedFlags;
        let parsed;
        let parsedFlags;
        let parsedFlagNames;

        normalizedFlags = Object.keys(flags);
        parsed = yargs.detailed(cliFlags, YARGS_FLAGS);
        if (parsed.error) {
            throw parsed.error;
        }
        parsedFlags = parsed.argv;
        parsedFlagNames = new Set(Object.keys(parsedFlags));

        // Check all parsed flags for unknown flag names.
        for (let flag of parsedFlagNames) {
github KishanBagaria / padding-oracle-attacker / src / oracle-caller.ts View on Github external
const OracleCaller = (options: OracleCallerOptions) => {
  const {
    url: _url,
    requestOptions = {},
    transformPayload,
    isCacheEnabled = true
  } = options
  ow(_url, 'url', ow.string)
  if (transformPayload) ow(transformPayload, ow.function)
  ow(requestOptions, ow.object)
  ow(requestOptions.method, ow.optional.string)
  if (requestOptions.headers) ow(requestOptions.headers, ow.any(ow.object, ow.string, ow.array))
  ow(requestOptions.data, ow.optional.string)

  const { method, headers, data } = requestOptions
  const injectionStringPresent = !_url.includes(POPAYLOAD)
    && !String(typeof headers === 'object' ? JSON.stringify(headers) : headers).includes(POPAYLOAD)
    && !(data || '').includes(POPAYLOAD)
  const networkStats = { count: 0, lastDownloadTime: 0, bytesDown: 0, bytesUp: 0 }

  async function callOracle(payload: Buffer): Promise {
    const payloadString = transformPayload ? transformPayload(payload) : payload.toString('hex')
    const addPayload: AddPayload = str => (str ? str.replace(injectionRegex, payloadString) : str)
    const url = (injectionStringPresent ? _url + payloadString : addPayload(_url)) as string
    const customHeaders = getHeaders(headers, addPayload)
    const body = addPayload(data)
    const cacheKey = [url, JSON.stringify(customHeaders), body].join('|')
    if (isCacheEnabled) {
github liaisonjs / liaison / packages / model / src / field.js View on Github external
getter,
      setter,
      isUnique = false,
      validators = [],
      ...unknownOptions
    } = options;

    super(parent, name, unknownOptions);

    this._options = options;

    ow(type, ow.string.nonEmpty);
    ow(getter, ow.optional.function);
    ow(setter, ow.optional.function);
    ow(isUnique, ow.boolean);
    ow(validators, ow.array);

    validators = validators.map(validator =>
      possiblyMany.map(validator, validator => normalizeValidator(validator, {fieldName: name}))
    );

    this._type = type;

    let scalarType;
    let scalarIsOptional;
    let scalarValidators;

    const isArray = type.endsWith('[]') || type.endsWith('[]?');
    let arrayIsOptional;

    if (isArray) {
      if (type.endsWith('?')) {
github imagemin / imagemin-pngquant / index.js View on Github external
}

	const args = ['-'];

	if (typeof options.speed !== 'undefined') {
		ow(options.speed, ow.number.integer.inRange(1, 11));
		args.push('--speed', options.speed);
	}

	if (typeof options.strip !== 'undefined') {
		ow(options.strip, ow.boolean);
		args.push('--strip');
	}

	if (typeof options.quality !== 'undefined') {
		ow(options.quality, ow.array.length(2).ofType(ow.number.inRange(0, 1)));
		const [min, max] = options.quality;
		args.push('--quality', `${Math.round(min * 100)}-${Math.round(max * 100)}`);
	}

	if (typeof options.dithering !== 'undefined') {
		ow(options.dithering, ow.any(ow.number.inRange(0, 1), ow.boolean.false));

		if (typeof options.dithering === 'number') {
			args.push(`--floyd=${options.dithering}`);
		} else if (options.dithering === false) {
			args.push('--ordered');
		}
	}

	if (typeof options.posterize !== 'undefined') {
		ow(options.posterize, ow.number);
github liaisonjs / liaison / packages / mongodb-store / src / mongodb-store.js View on Github external
async delete(documents, {throwIfNotFound = true} = {}) {
    ow(documents, ow.array);
    ow(throwIfNotFound, ow.boolean);

    const existingDocuments = await this._loadDocuments(documents, {fields: {}});

    const acknowledgedDocuments = documents.map(({_type, _id}) => {
      const acknowledgedDocument = {_type, _id};
      const existingDocument = existingDocuments.find(
        existingDocument => existingDocument._type === _type && existingDocument._id === _id
      );
      if (!existingDocument) {
        if (throwIfNotFound) {
          throw new Error(`Document not found (type: '${_type}', id: '${_id}')`);
        }
        acknowledgedDocument._missed = true;
      }
      return acknowledgedDocument;
github CrystallizeAPI / crystallize-frontend-boilerplate / server / lib / crystallize.js View on Github external
async function validateBasket(crystallizeBasket, _opt) {
  ow(crystallizeBasket, ow.object);

  const { items, coupon } = crystallizeBasket;
  ow(items, ow.array);
  ow(coupon, ow.any(ow.string, ow.null));
  ow(_opt, ow.any(ow.object, ow.undefined));

  const options = Object.assign(
    {
      excludeDiscount: true,
      excludeShipping: true
    },
    _opt
  );

  let discount = null;

  if (items.length === 0) {
    return {
      success: false,