How to use the ow.boolean 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 liaisonjs / liaison / packages / model / src / model.js View on Github external
__createFieldMask(rootFieldMask, {filter, includeReferencedEntities, _typeStack}) {
    ow(rootFieldMask, 'fields', ow.any(ow.boolean, ow.object));

    const normalizedFieldMask = {};

    for (const field of this.$getFields({filter})) {
      const type = field.$getScalar().$getType();
      if (_typeStack.has(type)) {
        continue; // Avoid looping indefinitely when a circular type is encountered
      }

      const name = field.$getName();

      const fieldMask = typeof rootFieldMask === 'object' ? rootFieldMask[name] : rootFieldMask;
      if (!fieldMask) {
        continue;
      }
github ridi / react-viewer / src / validators / ComicValidator.ts View on Github external
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,
});

export const SettingState = ow.object.partialShape({
  [ComicSettingProperties.VIEW_TYPE]: ViewTypeOptional,
  [ComicSettingProperties.CONTENT_WIDTH_IN_PERCENT]: notNegativeNumberOptional,
  [ComicSettingProperties.BINDING_TYPE]: BindingTypeOptional,
  [ComicSettingProperties.LAZY_LOAD]: ow.optional.any(ow.boolean, ow.number.not.negative),
});

export const ImageData = ow.object.partialShape({
  fileSize: notNegativeNumber,
  index: notNegativeNumber,
  path: ow.optional.string,
  uri: ow.optional.string,
  width: notNegativeNumberOptional,
  height: notNegativeNumberOptional,
});

export const ComicParsedData = ow.object.partialShape({
  images: ow.optional.array.ofType(ImageData),
  unzipPath: ow.string,
});
github liaisonjs / liaison / packages / layer / src / property.js View on Github external
_normalizeExposition(exposition) {
    const setting = ow.optional.any(ow.boolean, ow.string, ow.array);
    ow(exposition, ow.object.exactShape({get: setting, set: setting, call: setting}));

    let normalizedExposition = {};

    for (const [operation, setting] of Object.entries(exposition)) {
      const normalizedSetting = this._parent.$normalizePropertyOperationSetting(setting);
      if (normalizedSetting !== undefined) {
        normalizedExposition[operation] = normalizedSetting;
      }
    }

    if (isEmpty(normalizedExposition)) {
      normalizedExposition = undefined;
    }

    return normalizedExposition;
github liaisonjs / liaison / packages / mongodb-store / src / mongodb-store.js View on Github external
async save(documents, {throwIfNotFound = true, throwIfAlreadyExists = true} = {}) {
    ow(documents, ow.array);
    ow(throwIfNotFound, ow.boolean);
    ow(throwIfAlreadyExists, ow.boolean);

    const existingDocuments = await this._loadDocuments(documents);

    const {updatedDocuments, acknowledgedDocuments} = this._updateDocuments(
      existingDocuments,
      documents,
      {
        throwIfNotFound,
        throwIfAlreadyExists
      }
    );

    const updatedDocumentsByType = groupBy(updatedDocuments, '_type');
    for (const [type, documents] of Object.entries(updatedDocumentsByType)) {
      const collection = await this._getCollection(type);
      const operations = documents.map(document => ({
github wise-team / steem-wise-cli / src / app.ts View on Github external
this.actionWrapper(async () => {
                    if (file) ow(file, ow_extend.parentDirExists("file"));
                    ow(options.format, ow.string.label("format").oneOf(["yml", "json"]));
                    ow(options.override, ow.any(ow.undefined, ow.boolean.label("override")));
                    if (options.account) ow(options.account, ow.string.minLength(3));
                    ow(options.stdout, ow.any(ow.undefined, ow.boolean.label("override")));

                    return new DownloadRulesAction(this.context).doAction(await this.loadConfig(true), file, options);
                }),
            );
github liaisonjs / liaison / packages / mongodb-store / src / mongodb-store.js View on Github external
async load(documents, {fields, throwIfNotFound = true} = {}) {
    ow(documents, ow.array);
    ow(fields, ow.optional.object);
    ow(throwIfNotFound, ow.boolean);

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

    return documents.map(({_type, _id}) => {
      const loadedDocument = loadedDocuments.find(
        loadedDocument => loadedDocument._type === _type && loadedDocument._id === _id
      );
      if (loadedDocument) {
        return serializeDocument(loadedDocument);
      }
      if (!throwIfNotFound) {
        return {_type, _id, _missed: true};
      }
      throw new Error(`Document not found (type: '${_type}', id: '${_id}')`);
    });
  }
github liaisonjs / liaison / packages / model / src / field.js View on Github external
_createFieldMask(fieldMask, {filter, includeReferencedEntities, _typeStack}) {
    const Model = this.$getModel();
    if (Model) {
      return Model.prototype.__createFieldMask(fieldMask, {
        filter,
        includeReferencedEntities,
        _typeStack
      });
    }

    ow(fieldMask, 'fields', ow.boolean.true);

    return true;
  }
}
github liaisonjs / liaison / packages / model / src / field.js View on Github external
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;

    if (isArray) {
github wise-team / steem-wise-cli / src / app.ts View on Github external
private async initAction() {
        ow(this.commander.debug, ow.any(ow.undefined, ow.boolean.label("debug")));
        ow(this.commander.verbose, ow.any(ow.undefined, ow.boolean.label("verbose")));
        if (this.commander.configFile) ow_extend.fileExists(this.commander.configFile);

        Log.log().initialize(!!this.commander.debug, !!this.commander.verbose);
    }
github atomiclabs / hyperdex / app / renderer / api.js View on Github external
async withdraw(options) {
		ow(options, 'options', ow.object.exactShape({
			symbol: symbolPredicate,
			address: ow.string,
			amount: ow.number.positive.finite,
			max: ow.boolean,
		}));

		const {max = false} = options;

		return this.request({
			method: 'withdraw',
			coin: options.symbol,
			to: options.address,
			amount: String(options.amount),
			max,
		});
	}

ow

Function argument validation for humans

MIT
Latest version published 1 year ago

Package Health Score

73 / 100
Full package analysis