How to use arrify - 10 common examples

To help you get started, we’ve selected a few arrify 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 sebelga / gstore-node / src / model.ts View on Github external
static __hooksTransaction(transaction: Transaction, postHooks: FuncReturningPromise[]): void {
      const _this = this; // eslint-disable-line @typescript-eslint/no-this-alias
      postHooks = arrify(postHooks);

      if (!{}.hasOwnProperty.call(transaction, 'hooks')) {
        transaction.hooks = {
          post: [],
        };
      }

      transaction.hooks.post = [...transaction.hooks.post, ...postHooks];

      transaction.execPostHooks = function executePostHooks(): Promise {
        if (!this.hooks.post) {
          return Promise.resolve();
        }
        return (this.hooks.post as FuncReturningPromise[]).reduce(
          (promise, hook) => promise.then(hook.bind(_this)),
          Promise.resolve() as Promise,
github javascriptair / site / generate / renderComponentToFile.js View on Github external
function renderComponent(comp, destinations, callback = noop) {
  destinations = arrify(destinations)
  const {html, css} = StyleSheetServer.renderStatic(() => ReactDOMServer.renderToStaticMarkup(comp))
  const string = html.replace('/* aphrodite-content */', css.content)
  async.parallel(
    destinations.map(d => cb => writeFile(d, string, cb)),
    callback,
  )
}
github perrin4869 / gulp-xml-transformer / src / index.js View on Github external
function gulpXmlTransformer(transformations, nsUri) {
  // check options
  switch (typeof transformations) {
    case 'function':
      return transform(transformations, functionTransformer, nsUri);
    case 'object':
      return transform(arrify(transformations), objectTransformer, nsUri);
    case 'undefined':
      throw new PluginError(PLUGIN_NAME, 'transformations option is required');
    default:
      throw new PluginError(PLUGIN_NAME, 'transformations option must be a function or an object');
  }
}
github sebelga / gstore-node / src / model.ts View on Github external
const path = getPath(id);
        let key;

        if (typeof namespace !== 'undefined' && namespace !== null) {
          key = this.gstore.ds.key({
            namespace,
            path,
          });
        } else {
          key = this.gstore.ds.key(path);
        }
        return key;
      };

      if (typeof ids !== 'undefined' && ids !== null) {
        const idsArray = arrify(ids);

        isMultiple = idsArray.length > 1;

        idsArray.forEach(id => {
          const key = getKey(id);
          keys.push(key);
        });
      } else {
        const key = getKey(null);
        keys.push(key);
      }

      return isMultiple ? ((keys as unknown) as R) : ((keys[0] as unknown) as R);
    }
github sebelga / gstore-node / src / model.ts View on Github external
const handler = (keys: EntityKey | EntityKey[]): Promise | EntityData[]> => {
        const keysArray = arrify(keys);
        if (transaction) {
          if (transaction.constructor.name !== 'Transaction') {
            return Promise.reject(new Error('Transaction needs to be a gcloud Transaction'));
          }
          return transaction.get(keysArray).then(([result]) => arrify(result));
        }

        if (dataloader) {
          if (dataloader.constructor.name !== 'DataLoader') {
            return Promise.reject(
              new GstoreError(ERROR_CODES.ERR_GENERIC, 'dataloader must be a "DataLoader" instance'),
            );
          }
          return dataloader.loadMany(keysArray).then((result: EntityData) => arrify(result));
        }
github sanity-io / sanity / src / inputs / Object / Object.js View on Github external
handleFieldChange = (event, fieldName) => {
    const {onChange} = this.props

    const patches = arrify(event.patch).map(patch => {
      return {
        ...patch,
        path: [fieldName, ...(patch.path || [])]
      }
    })
    onChange({patch: patches})
  }
github sezna / nps / src / get-logger.js View on Github external
function getMessage(first, ...rest) {
  if (isPlainObject(first) && first.message && first.ref) {
    return [
      ...arrify(first.message),
      getLink(first.ref),
      first.error,
      ...rest,
    ].filter(i => !!i)
  } else {
    return [first, ...rest]
  }
}
github sebelga / gstore-node / src / model.ts View on Github external
const getScopeForDeleteHooks = (): any => {
        const id =
          is.object(args[0]) && {}.hasOwnProperty.call(args[0], '__override') ? arrify(args[0].__override)[0] : args[0];

        if (is.array(id)) {
          return null;
        }

        let ancestors;
        let namespace;
        let key;

        if (hookType === 'post') {
          ({ key } = args);
          if (is.array(key)) {
            return null;
          }
        } else {
          ({ 1: ancestors, 2: namespace, 4: key } = args);
github segmentio / evergreen / src / select-menu / src / SelectMenu.js View on Github external
title={title}
            hasFilter={hasFilter}
            filterPlaceholder={filterPlaceholder}
            filterIcon={filterIcon}
            hasTitle={hasTitle}
            isMultiSelect={isMultiSelect}
            titleView={titleView}
            listProps={{
              onSelect: item => {
                this.props.onSelect(item)
              },
              onDeselect: item => {
                this.props.onDeselect(item)
              },
              onFilterChange: this.props.onFilterChange,
              selected: arrify(selected)
            }}
            close={close}
            {...this.getDetailView(close, detailView)}
            {...this.getEmptyView(close, emptyView)}
            closeOnSelect={closeOnSelect}
          />
        )}
        {...props}
github laggingreflex / mochista / lib / utils / index.js View on Github external
utils.arrify = i => require('arrify')(i).filter(Boolean);
utils.requireFromCwd = (file, cwd = process.cwd()) => {

arrify

Convert a value to an array

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular arrify functions