How to use the minimalistic-assert function in minimalistic-assert

To help you get started, we’ve selected a few minimalistic-assert 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 PsychoLlama / mytosis / packages / types / src / Union.js View on Github external
types.forEach(type => {
      const notComposite = !(type instanceof Composite);
      const notUnion = !(type instanceof Union);

      assert(notUnion, `Unions cannot contain other unions.`);
      assert(
        notComposite,
        `Unions cannot contain composite types (given ${type.name}).`
      );

      // Ensure types can always be inferred by value.
      if (type instanceof Derivation) {
        assert(
          !typeSet.has(type.subtype),
          `Union contains ambiguous types (${type.name} & ${
            type.subtype.name
          }).`
        );
      }
    });
github PsychoLlama / mytosis / packages / types / src / Union.js View on Github external
types.forEach(type => {
      const notComposite = !(type instanceof Composite);
      const notUnion = !(type instanceof Union);

      assert(notUnion, `Unions cannot contain other unions.`);
      assert(
        notComposite,
        `Unions cannot contain composite types (given ${type.name}).`
      );

      // Ensure types can always be inferred by value.
      if (type instanceof Derivation) {
        assert(
          !typeSet.has(type.subtype),
          `Union contains ambiguous types (${type.name} & ${
            type.subtype.name
          }).`
        );
      }
    });
github PsychoLlama / mytosis / packages / types / src / Derivation.js View on Github external
constructor(name, primitive, def) {
    assert(nameRegex.test(name), `Invalid derivation name "${name}".`);

    this.name = name;
    this.subtype = primitive;
    Object.defineProperty(this, '_definition', {
      value: def,
    });
  }
github PsychoLlama / mytosis / packages / types / src / Primitive.js View on Github external
constructor(name: string, def: TypeDefinition) {
    assert(nameRegex.test(name), invalidNameMsg(name));

    this.name = name;
    Object.defineProperties(this, {
      _isValid: { value: def.isValid },
      _coerce: { value: def.coerce },
    });
  }
github PsychoLlama / mytosis / packages / types / src / migrations.js View on Github external
migrateType(type) {
    assert(
      type.definition.hasOwnProperty(this.field),
      `Field "${this.field}" doesn't exist in type ${type.name}.`
    );

    return {
      defaultType: type.defaultType,
      definition: {
        ...type.definition,
        [this.field]: this.type,
      },
    };
  }
github PsychoLlama / mytosis / packages / types / src / Derivation.js View on Github external
dehydrate(hydrated) {
    const value = this._definition.dehydrate(hydrated);

    assert(
      this.subtype.isValid(value),
      `Serializer for type "${this.name}" returned an invalid value.`
    );

    return value;
  }
github PsychoLlama / mytosis / packages / types / src / migrations.js View on Github external
migrateType(type) {
    const definition = { ...type.definition };
    const sourceExists = definition.hasOwnProperty(this.from);
    const targetExists = definition.hasOwnProperty(this.to);
    const fail = field =>
      `Field "${field}" isn't defined in type ${type.name}.`;
    assert(sourceExists, fail(this.from));
    assert(targetExists, fail(this.to));

    const target = definition[this.to];
    const source = definition[this.from];

    const targetComparison =
      target instanceof Derivation ? target.subtype : target;
    const sourceComparison =
      source instanceof Derivation ? source.subtype : source;

    const isSameType = targetComparison === sourceComparison;

    assert(
      isSameType,
      `Can't move ${source.name} into ${target.name} ` +
        `(${type.name} "${this.from}" -> "${this.to}").`
    );
github PsychoLlama / mytosis / packages / types / src / migrations.js View on Github external
const fail = field =>
      `Field "${field}" isn't defined in type ${type.name}.`;
    assert(sourceExists, fail(this.from));
    assert(targetExists, fail(this.to));

    const target = definition[this.to];
    const source = definition[this.from];

    const targetComparison =
      target instanceof Derivation ? target.subtype : target;
    const sourceComparison =
      source instanceof Derivation ? source.subtype : source;

    const isSameType = targetComparison === sourceComparison;

    assert(
      isSameType,
      `Can't move ${source.name} into ${target.name} ` +
        `(${type.name} "${this.from}" -> "${this.to}").`
    );

    return {
      defaultType: type.defaultType,
      definition,
    };
  }
github PsychoLlama / mytosis / packages / types / src / migrations.js View on Github external
migrateType(type) {
    assert(
      this.field in type.definition,
      `Can't remove field "${this.field}" from type ${type.name}; ` +
        `No such field exists.`
    );

    const definition = { ...type.definition };
    delete definition[this.field];

    return {
      defaultType: type.defaultType,
      definition,
    };
  }
github PsychoLlama / mytosis / packages / types / src / Literal.js View on Github external
constructor(value: primitive) {
    if (typeof value === 'number') {
      assert(isFinite(value), `Literal(..) given invalid number (${value}).`);
    }

    super('literal', {
      isValid: data => data === value,
      coerce: () => value,
    });
  }
}

minimalistic-assert

minimalistic-assert ===

ISC
Latest version published 6 years ago

Package Health Score

68 / 100
Full package analysis

Popular minimalistic-assert functions

Similar packages