How to use the optional function in optional

To help you get started, we’ve selected a few optional 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 gajus / roarr / src / bin / commands / filter.js View on Github external
export const handler = (argv: ArgvType) => {
  const jq = optional('node-jq');

  if (!jq) {
    throw new Error('Must install `node-jq` dependency to use `roarr filter`.');
  }

  // argv
  process.stdin
    .pipe(split())
    .pipe(through((chunk, encoding, callback) => {
      const line = chunk.toString();

      filterLog(jq.run, argv, line, callback);
    }))
    .pipe(process.stdout);
};
github sebelga / gstore-node / src / dataloader.ts View on Github external
import optional from 'optional';
import arrify from 'arrify';
import datastoreAdapterFactory from 'nsql-cache-datastore';
import { Datastore } from '@google-cloud/datastore';
import DataLoader from 'dataloader'; // eslint-disable-line import/no-extraneous-dependencies

import { EntityKey, EntityData } from './types';

const OptionalDataloader = optional('dataloader');

const dsAdapter = datastoreAdapterFactory();

const { keyToString } = dsAdapter;

/**
 * Create a DataLoader instance
 * @param {Datastore} ds @google-cloud Datastore instance
 */
export const createDataLoader = (
  ds: Datastore,
  options?: { maxBatchSize: number },
): DataLoader => {
  if (!ds) {
    throw new Error('A Datastore instance has to be passed');
  }
github sebelga / gstore-node / src / schema.ts View on Github external
import is from 'is';

import { QUERIES_FORMATS } from './constants';
import VirtualType from './virtualType';
import { ValidationError, ERROR_CODES } from './errors';
import {
  FunctionType,
  FuncReturningPromise,
  CustomEntityFunction,
  GenericObject,
  EntityFormatType,
  JSONFormatType,
} from './types';
import { QueryListOptions } from './query';

const Joi = optional('@hapi/joi') || optional('joi');

const IS_QUERY_METHOD: { [key: string]: boolean } = {
  update: true,
  delete: true,
  findOne: true,
};

const DEFAULT_OPTIONS = {
  validateBeforeSave: true,
  explicitOnly: true,
  excludeLargeProperties: false,
  queries: {
    readAll: false,
    format: QUERIES_FORMATS.JSON,
  },
};

optional

Allows you to optionally include modules without surrounding everything with 'try/catch'

MIT
Latest version published 7 years ago

Package Health Score

50 / 100
Full package analysis

Popular optional functions