How to use the ow 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 / 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 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 Julien-Broyard / JikanTS / src / person.ts View on Github external
const pictures = async (id: number) => {
  try {
    ow(id, ow.number.positive);

    const { body } = await queue.add(
      async () => await api(`/person/${id}/pictures`, {})
    );

    return body;
  } catch (error) {
    Logger.error(error);
  }
};
github BoostIO / BoostNote.next / src / lib / utils / predicates.ts View on Github external
ow.optional.object.is(value => {
    const predicateEntries = Object.entries(predicateSchema)
    for (const [key, predicate] of predicateEntries) {
      try {
        ow(value[key], predicate)
      } catch (error) {
        return false
      }
    }

    return true
  })
github liaisonjs / liaison / packages / storable / src / storable.js View on Github external
static __extractKey(key) {
      ow(key, ow.object);

      const names = Object.keys(key);

      if (names.length !== 1) {
        throw new Error(
          `A key must be an object composed of one unique field (key: ${JSON.stringify(key)})`
        );
      }

      const name = names[0];

      const isUnique = name === 'id' || this.prototype.$getField(name).$isUnique();

      if (!isUnique) {
        throw new Error(`A key name must correspond to a unique field (name: '${name}')`);
      }
github atomiclabs / hyperdex / app / renderer / api.js View on Github external
async orderBook(baseCurrency, quoteCurrency) {
		ow(baseCurrency, 'baseCurrency', symbolPredicate);
		ow(quoteCurrency, 'quoteCurrency', symbolPredicate);

		const response = await this.request({
			method: 'orderbook',
			base: baseCurrency,
			rel: quoteCurrency,
		});

		const formatOrders = orders => orders
			.map(order => ({
				address: order.address,
				depth: order.depth,
				price: Number(order.price),
				maxVolume: order.maxvolume,
				zCredits: order.zcredits,
			}));

ow

Function argument validation for humans

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis