How to use the optimal function in optimal

To help you get started, we’ve selected a few optimal 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 milesj / boost / src / ConsoleOLD.js View on Github external
constructor(reporter: Tr, options: Partial = {}) {
    super();

    this.reporter = reporter;
    this.options = optimal(options, {
      footer: string().empty(),
      header: string().empty(),
      silent: bool(),
    });

    // Avoid binding listeners while testing
    if (process.env.NODE_ENV === 'test') {
      return;
    }

    // Start early so we may capture uncaught/unhandled
    this.start();
  }
github milesj / shapeshifter / packages / core / src / definitions / Enum.ts View on Github external
constructor(options: Options, attribute: string, config: Partial = {}) {
    super(options, attribute, config, false);

    this.config = optimal(
      this.config,
      {
        constant: bool(),
        nullable: bool(),
        optional: bool(),
        type: string('enum').notEmpty(),
        valueType: this.createUnionType(),
        // `valueType` must be validated before values
        values: array(custom(this.validateValue, ''))
          .notEmpty()
          .required(),
      },
      {
        name: 'EnumDefinition',
        unknown: true,
      },
github milesj / boost / packages / core / src / ConfigLoader.ts View on Github external
loadPackageJSON(): PackageConfig {
    const { root } = this.tool.options;
    const filePath = path.join(root, 'package.json');

    this.debug('Locating package.json in %s', chalk.cyan(root));

    if (!fs.existsSync(filePath)) {
      throw new Error(this.tool.msg('errors:packageJsonNotFound'));
    }

    this.package = optimal(
      this.parseFile(filePath),
      {
        name: string().notEmpty(),
        version: string('0.0.0'),
      },
      {
        file: 'package.json',
        name: 'ConfigLoader',
        unknown: true,
      },
    );

    return this.package;
  }
github beemojs / beemo / packages / core / src / Driver.ts View on Github external
setMetadata(metadata: Partial): this {
    this.metadata = optimal(
      metadata,
      {
        bin: string()
          .match(/^[a-z]{1}[a-zA-Z0-9-]+$/u)
          .required(),
        configName: string().required(),
        configOption: string('--config'),
        configStrategy: string(STRATEGY_CREATE).oneOf([
          STRATEGY_CREATE,
          STRATEGY_REFERENCE,
          STRATEGY_COPY,
        ]),
        dependencies: array(string()),
        description: string(),
        filterOptions: bool(true),
        helpOption: string('--help'),
github milesj / shapeshifter / packages / core / src / definitions / Union.ts View on Github external
constructor(options: Options, attribute: string, config: Partial = {}) {
    super(options, attribute, config, false);

    this.config = optimal(
      this.config,
      {
        nullable: bool(),
        optional: bool(),
        type: string('union').notEmpty(),
        valueTypes: array(this.createUnionType())
          .notEmpty()
          .required(),
      },
      {
        name: 'UnionDefinition',
        unknown: true,
      },
    );

    this.valueTypes = this.config.valueTypes.map((type, i) => {
github milesj / shapeshifter / packages / core / src / Definition.ts View on Github external
validateConfig() {
    const { name } = this.constructor;

    this.config = optimal(
      this.config,
      {
        nullable: bool(),
        optional: bool(),
        type: string(
          normalizeType(name.replace('Definition', '').toLowerCase() || 'unknown'),
        ).notEmpty(),
      },
      {
        name: name || 'Definition',
        unknown: true,
      },
    ) as T;
  }
}
github milesj / boost / packages / core / src / ConfigLoader.ts View on Github external
loadPackageJSON(): PackageConfig {
    const rootPath = new Path(this.tool.options.root);
    const filePath = rootPath.append('package.json');

    this.debug('Locating package.json in %s', color.filePath(rootPath.path()));

    if (!filePath.exists()) {
      throw new Error(this.tool.msg('errors:packageJsonNotFound'));
    }

    this.package = optimal(
      this.parseFile(filePath),
      {
        name: string().notEmpty(),
        version: string('0.0.0'),
      },
      {
        file: 'package.json',
        name: 'ConfigLoader',
        unknown: true,
      },
    );

    return this.package;
  }
github milesj / boost / packages / core / src / executors / Pool.ts View on Github external
constructor(tool: Tool, context: Ctx, options?: PoolExecutorOptions) {
    super(tool, context, options);

    this.options = optimal(
      { ...options },
      {
        concurrency: number(os.cpus().length).gte(1),
        fifo: bool(true),
        timeout: number(0).gte(0),
      },
      {
        name: 'PoolExecutor',
      },
    );
  }
github milesj / boost / packages / core / src / Routine.ts View on Github external
constructor(key: string, title: string, options?: Options) {
    super(title, (context, value) => this.execute(context, value));

    if (!key || typeof key !== 'string') {
      throw new Error('Routine key must be a valid unique string.');
    }

    this.key = key;
    this.options = optimal({ ...options }, this.blueprint(predicates), {
      name: this.constructor.name,
    });

    this.debug = createDebugger(['routine', this.key]);
    this.onCommand = new Event('command');
    this.onCommandData = new Event('command.data');
  }
github beemojs / beemo / packages / core / src / SyncDotfilesRoutine.ts View on Github external
bootstrap() {
    this.options = optimal(
      this.options,
      {
        filter: string().empty(),
      },
      {
        name: 'SyncDotfilesRoutine',
      },
    );
  }

optimal

Build, validate, and transform values with immutable typed schemas.

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis