How to use the ow.optional 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 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;
    }
};
github KishanBagaria / padding-oracle-attacker / src / decrypt.ts View on Github external
async function decrypt({
  url, blockSize, logMode = 'full', ciphertext, isDecryptionSuccess, makeInitialRequest = true, alreadyFound, startFromFirstBlock, initFirstPayloadBlockWithOrigBytes, ...args
}: DecryptOptions) {
  ow(ciphertext, ow.buffer)
  ow(alreadyFound, ow.optional.buffer)
  if (ciphertext.length % blockSize !== 0) throw TypeError('Invalid `ciphertext`, should be evenly divisble by `blockSize`')

  const totalSize = ciphertext.length
  const blockCount = totalSize / blockSize

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

  if (alreadyFound && alreadyFound.length) {
    const startIndex = foundBytes.length - alreadyFound.length
    const lastBytes = ciphertext.slice(startIndex)
    const interFound = xor(alreadyFound, lastBytes)
    alreadyFound.copy(foundBytes, startIndex)
    interFound.copy(interBytes, startIndex)
    for (const offset of range(startIndex, foundBytes.length)) foundOffsets.add(offset)
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;
    }
};
github hegemonic / jsdoc-baseline / lib / db.js View on Github external
exports.db = ({ config, mixins = exports.mixins, values }) => {
    ow(config, ow.optional.object);
    if (config) {
        ow(config.opts, ow.object);
        ow(config.opts.access, ow.optional.array.ofType(ow.string));
    }
    ow(mixins, ow.object.valuesOfType(ow.function));
    ow(values, ow.array);

    const _ = lodash.runInContext();
    const boundMixins = {};

    Object.keys(mixins).forEach(key => {
        boundMixins[key] = (...args) => mixins[key](_, config, ...args);
    });

    _.mixin(boundMixins);
github ridi / react-viewer / src / validators / ComicValidator.ts View on Github external
import ow from 'ow';
import { BindingTypeOptional, ViewTypeOptional } from './CommonValidator';
import { ComicCalculationProperties } from '../contexts/comic/ComicCalculationContext';
import { ComicCurrentProperties } from '../contexts/comic/ComicCurrentContext';
import { ComicSettingProperties } from '../contexts/comic/ComicSettingContext';

const notNegativeNumber = ow.number.not.negative;
const notNegativeNumberOptional = ow.optional.number.not.negative;

export const ImageCalculationContext = ow.object.partialShape({
  imageIndex: notNegativeNumber,
  ratio: notNegativeNumber,
});

export const CalculationState = ow.object.partialShape({
  [ComicCalculationProperties.TOTAL_PAGE]: notNegativeNumberOptional,
  [ComicCalculationProperties.PAGE_UNIT]: notNegativeNumberOptional,
  [ComicCalculationProperties.IMAGES]: ow.optional.array.ofType(ImageCalculationContext),
});

export const CurrentState = ow.object.partialShape({
  [ComicCurrentProperties.CURRENT_PAGE]: notNegativeNumberOptional,
  [ComicCurrentProperties.READY_TO_READ]: ow.optional.boolean,
});
github liaisonjs / liaison / packages / model / src / field.js View on Github external
let {
      type,
      default: defaultValue,
      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;
github BoostIO / BoostNote.next / src / lib / utils / predicates.ts View on Github external
export const optional = (
  predicateSchema: T
): BasePredicate> =>
  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 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) {
      const cached = await cacheStore.get(cacheKey) as OracleResult
github liaisonjs / liaison / packages / model / src / field.js View on Github external
type,
      default: defaultValue,
      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;

ow

Function argument validation for humans

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis