How to use ow - 10 common examples

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 ArkEcosystem / core / packages / core-config / lib / interface.js View on Github external
_validateConfig () {
    try {
      ow(this.network.pubKeyHash, ow.number)
      ow(this.network.nethash, ow.string.length(64))
      ow(this.network.wif, ow.number)
    } catch (error) {
      console.error('Invalid configuration. Shutting down...')
      throw Error(error.message)
      process.exit(1) // eslint-disable-line no-unreachable
    }
  }
}
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 atomiclabs / hyperdex / app / renderer / api.js View on Github external
async request(data) {
		ow(data, 'data', ow.object);

		const body = {
			...data,
			// TODO: When https://github.com/artemii235/SuperNET/issues/298 is fixed, rename `userpass` to `rpc_password` and also reduce the places we pass around `seedPhrase`.
			userpass: this.rpcPassword,
		};

		let result;
		try {
			let requestTime;

			const response = await this.queue.add(() => {
				requestTime = Date.now();

				return fetch(this.endpoint, {
					method: 'post',
github KishanBagaria / padding-oracle-attacker / src / encrypt.ts View on Github external
async function encrypt({
  url, blockSize, logMode = 'full', plaintext: _plaintext, makeFinalRequest = true, lastCiphertextBlock, ...args
}: EncryptOptions) {
  ow(_plaintext, 'plaintext', ow.buffer)
  ow(lastCiphertextBlock, ow.optional.buffer)
  if (lastCiphertextBlock && lastCiphertextBlock.length !== blockSize) throw TypeError('Invalid `lastCiphertextBlock`, should have length equal to `blockSize`')

  const plaintext = addPadding(_plaintext, blockSize)

  const blockCount = (plaintext.length / blockSize) + 1
  const totalSize = blockCount * blockSize

  const foundBytes = Buffer.alloc(totalSize) // ciphertext bytes
  const interBytes = Buffer.alloc(totalSize - blockSize)
  const foundOffsets: Set = new Set()

  if (lastCiphertextBlock) {
    lastCiphertextBlock.copy(foundBytes, foundBytes.length - blockSize)
  }

  if (['full', 'minimal'].includes(logMode)) logStart({ blockCount, totalSize })
github liaisonjs / liaison / packages / mongodb-store / src / mongodb-store.js View on Github external
function buildProjection(fields) {
  ow(fields, ow.optional.object);

  if (fields === undefined) {
    return undefined;
  }

  const projection = {};

  function build(rootFields, rootPath) {
    // Always include '_type' and '_id'
    rootFields = {_type: true, _id: true, ...rootFields};

    for (const [name, fields] of Object.entries(rootFields)) {
      const path = [...rootPath, name];
      if (typeof fields === 'object') {
        build(fields, path);
      } else if (fields) {
github KishanBagaria / padding-oracle-attacker / src / encrypt.ts View on Github external
async function encrypt({
  url, blockSize, logMode = 'full', plaintext: _plaintext, makeFinalRequest = true, lastCiphertextBlock, ...args
}: EncryptOptions) {
  ow(_plaintext, 'plaintext', ow.buffer)
  ow(lastCiphertextBlock, ow.optional.buffer)
  if (lastCiphertextBlock && lastCiphertextBlock.length !== blockSize) throw TypeError('Invalid `lastCiphertextBlock`, should have length equal to `blockSize`')

  const plaintext = addPadding(_plaintext, blockSize)

  const blockCount = (plaintext.length / blockSize) + 1
  const totalSize = blockCount * blockSize

  const foundBytes = Buffer.alloc(totalSize) // ciphertext bytes
  const interBytes = Buffer.alloc(totalSize - blockSize)
  const foundOffsets: Set = new Set()

  if (lastCiphertextBlock) {
    lastCiphertextBlock.copy(foundBytes, foundBytes.length - blockSize)
  }
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',
    '--quality', gifski.quality,
github transitive-bullshit / puppeteer-email / packages / puppeteer-email-provider-outlook / lib / get-emails.js View on Github external
module.exports = async (opts) => {
  const {
    browser,
    query
  } = opts

  ow(query, ow.string.nonEmpty.label('query'))

  let page

  try {
    const page = await browser.newPage()
    await page.goto('https://outlook.live.com/mail/inbox')
    await delay(1000)

    // search for an input query to narrow down email results
    // TODO: don't require a search query
    await page.waitFor('input[aria-label=Search]', { visible: true })
    await delay(2000)

    let attempts = 0
    do {
      await page.focus('input[aria-label=Search]')
github vadimdemedes / reconciled / index.js View on Github external
module.exports = config => {
	ow(config, ow.object.exactShape({
		render: ow.optional.function,
		createNode: ow.function,
		createTextNode: ow.function,
		setTextNodeValue: ow.function,
		appendNode: ow.function,
		insertBeforeNode: ow.optional.function,
		updateNode: ow.optional.function,
		removeNode: ow.optional.function
	}));

	const fullConfig = {
		schedulePassiveEffects: unstable_scheduleCallback, // eslint-disable-line camelcase
		cancelPassiveEffects: unstable_cancelCallback, // eslint-disable-line camelcase
		now: Date.now,
		getRootHostContext: () => NO_CONTEXT,
		prepareForCommit: noop,
		resetAfterCommit: () => {
			if (typeof config.render === 'function') {
				config.render();
			}
		},
		getChildHostContext: () => NO_CONTEXT,
github hegemonic / jsdoc-baseline / lib / ticket.js View on Github external
constructor(opts = {}) {
        ow(opts, ow.object);
        ow(opts.data, ow.optional.object);
        ow(opts.name, ow.optional.string);
        ow(opts.source, ow.optional.string);
        ow(opts.url, ow.optional.string);
        ow(opts.viewName, ow.optional.string);

        this.data = opts.data;
        this.name = opts.name;
        // TODO: Consider renaming `source` and `url` so it's clear that they're sort of paired.
        // (`from` and `to`?)
        this.source = opts.source;
        this.url = opts.url;
        this.viewName = opts.viewName;
    }
};

ow

Function argument validation for humans

MIT
Latest version published 8 months ago

Package Health Score

78 / 100
Full package analysis