Example #1
0
function getRoute() {
	const {pathname} = url.parse(window.location.href);
	const compact = require('lodash.compact');
	const pathParams = compact(pathname.split('/'));
	const routeName = pathParams.length > 0 ? pathParams[0] : '';
	return {routeName, pathParams};
}
Example #2
0
export default function Item ({ className, isSelected, item, onSelect }: PropTypes): Element<any> {
  const { icon, key, label } = item;

  const _onClick = (event) => {
    onSelect && onSelect(event, key);
  };

  return (
    <div
      className={
        compact([
          styles.ui, icon && styles.withIcon, isSelected && styles.withSelected, className
        ]).join(' ')
      }
      onMouseDown={ _onClick }
    >
      { label || key }
      {
        icon
          ? (
            <div className={ styles.icon }>
              { icon }
            </div>
          )
          : null
      }
    </div>
  );
}
Example #3
0
export default function Block ({ className }: PropTypes): Element<any> {
  return (
    <div
      className={
        compact([
          styles.ui, className
        ]).join(' ')
      }
    >
      <div className={ [styles.cube, styles.tiny].join(' ') }>
        <div className={ styles.top } />
        <div className={ styles.left } />
        <div className={ styles.right } />
      </div>
      <div className={ [styles.cube, styles.small].join(' ') }>
        <div className={ styles.top } />
        <div className={ styles.left } />
        <div className={ styles.right } />
      </div>
      <div className={ styles.cube }>
        <div className={ styles.top } />
        <div className={ styles.left } />
        <div className={ styles.right } />
      </div>
    </div>
  );
}
Example #4
0
brukere.sampledBy(lagre).onValue(function(brukere) {
  var kommentar = $('#kommentar').val();
  var olPris = $('#ol-pris').val();
  var kryss = map($('#kryss form fieldset > div'), function(elem) {
    var $el = $(elem);
    var navn = $el.find('.navn').val();

    if(!navn) return;

    return {
      'id': find(brukere, {'name': navn})['_id'],
      'ol': $el.find('.ol').val(),
      'penger': $el.find('.penger').val()
    };
  });

  $.post('/lister', {
    'kommentar': kommentar,
    'innskudd': false,
    'olPris': olPris,
    'kryss': JSON.stringify(compact(kryss))
  })
  .done(function(data) {
    window.location.href = '/admin/lister/'+data.insertedIds[0];
  });
});
Example #5
0
 forEach(this._combinedPBs, (paramBuilder, i) => {
   params = paramBuilder.build(preparedTerms, opts);
   if (isFalse(params)) {
     combinedParams = false;
     return false;
   }
   combinedParams = mergeParams(compact([combinedParams, params]), i, n);
   return true;
 });
Example #6
0
 let buildImageUrl = (hex, options) => {
   if (options.host) {
     return compact([options.host, options.path, `${hex}.${options.ext}`]).join('/');
   } else if (options.emojiType === 'twemoji') {
     return `https://twemoji.maxcdn.com/${options.ext}/${hex}.${options.ext}`;
   } else if (options.emojiType === 'emojione') {
     return `http://cdn.jsdelivr.net/emojione/assets/${options.ext}/${hex.toUpperCase()}.${options.ext}`;
   } else {
     throw new Error('Invalid emojiType is passed');
   }
 };
module.exports = function getSvgColors(input, options) {

  if (!isSVG(input)) {
    input = fs.readFileSync(input, 'utf8')
  }

  const $ = cheerio.load(input)

  // Find elements with a `fill` attribute
  var fills = $('[fill]').map(function (i, el) {
    return color($(this).attr('fill'))
  }).get()

  // Find elements with a `stroke` attribute
  var strokes = $('[stroke]').map(function (i, el) {
    return color($(this).attr('stroke'))
  }).get()

  // Find `fill` and `stroke` within inline styles
  $('[style]').each(function (i, el) {
    fills.push(color($(this).css('fill')))
    strokes.push(color($(this).css('stroke')))
  })

  // Find elements with a `stop-color` attribute (gradients)
  var stops = $('[stop-color]').map(function (i, el) {
    return color($(this).attr('stop-color'))
  }).get()

  if (options && options.flat) {
    return compact(uniq(fills.concat(strokes).concat(stops)))
  }

  return {
    fills: compact(uniq(fills)),
    strokes: compact(uniq(strokes)),
    stops: compact(uniq(stops))
  }

}
exports.removeStopwords = function (text, options) {
  var defaults = {
    stopwords: require('./stopwords_en.js').words,
    inputSeparator: /[\\., ]+/
  }
  options = _defaults(options || {}, defaults)
  var tokens = text.split(options.inputSeparator)
  tokens = _compact(tokens.map(function (value) {
    if (options.stopwords.indexOf(value.toLowerCase()) !== -1) return ''
    return value.toLowerCase()
  }))
  return tokens
}
Example #9
0
function createIcon (type: string, { className, onClick, style }: PropTypes): Element<any> {
  return (
    <i
      className={
        compact([
          styles.ui, `fa fa-${type}`, className
        ]).join(' ')
      }
      onClick={ onClick }
      style={ style }
    />
  );
}
Example #10
0
export default function Form ({ children, className }: PropTypes): Element<any> {
  return (
    <div
      className={
        compact([
          styles.ui, className
        ]).join(' ')
      }
    >
      { children }
    </div>
  );
}
Example #11
0
export default function Html ({ className, html }: PropTypes): Element<any> {
  return (
    <div
      className={
        compact([
          styles.ui, className
        ]).join(' ')
      }
      dangerouslySetInnerHTML={ {
        __html: html
      } }
    />
  );
}
  handleSubmit: function(e) {
    this.submitAttempted = true;

    // the field should already be flagged as dirty if its validity has changed
    var invalidField = findWhere(this._fieldViewsArray, {valid: false});
    var changedFields = where(this._fieldViewsArray, {changed: true});
    var dirtyFields = compact(changedFields.concat(invalidField));

    if(dirtyFields.length) {
      invoke(dirtyFields, 'flagStateAsDirty');
    }

    AmpersandFormView.prototype.handleSubmit.call(this, e);
  },
Example #13
0
File: vo.js Project: takaaptech/vo
      fn.call(context, args, function(err, args) {
        if (err) {
          errors[i] = err
          out[i] = err
        } else {
          out[i] = args
        }

        if (!--pending) {
          errors = compact(errors)
          return errors.length
            ? done(error(errors), out)
            : done(null, out)
        }
      })
Example #14
0
export default function InputStatic ({ className, icon, isError, isWarning, value }: PropTypes): Element<any> {
  return (
    <Input
      className={
        compact([
          styles.ui, className
        ]).join(' ')
      }
      icon={ icon }
      isError={ isError }
      isReadOnly
      isWarning={ isWarning }
      value={ value }
    />
  );
}
Example #15
0
	this.formatted = ko.pureComputed(function () {
		var value = this;
		var isUS = this.isUS();
		return removeConsecutive(_compact([
			ko.unwrap(value.name1), "\n",
			ko.unwrap(value.name2), "\n",
			ko.unwrap(value.address1), "\n",
			ko.unwrap(value.address2), "\n",
			ko.unwrap(value.city), " ",
			isUS ? ko.unwrap(value.state) : "", isUS ? " " : "",
			ko.unwrap(value.postalCode),
			isUS ? "" : "\n",
			isUS ? "" : ko.unwrap(value.country)
		]))
		.join("")
		.trim();
	}, this);
Example #16
0
  let parse = co.wrap(function * (args) {
    if (args.length === 0) return []
    let formation = yield heroku.get(`/apps/${app}/formation`)
    if (args.find((a) => a.match(/=/))) {
      return compact(args.map((arg) => {
        let match = arg.match(/^([a-zA-Z0-9_]+)=([\w-]+)$/)
        let type = match[1]
        let size = match[2]
        if (!formation.find((p) => p.type === type)) {
          throw new Error(`Type ${cli.color.red(type)} not found in process formation.
Types: ${cli.color.yellow(formation.map((f) => f.type).join(', '))}`)
        }
        return {type, size}
      }))
    } else {
      return formation.map((p) => ({type: p.type, size: args[0]}))
    }
  })
Example #17
0
 var traverseDom = function(node, isValidNode, processingInstructions, index) {
     if (isValidNode(node)) {
         var processingInstruction = find(processingInstructions || [],
                 function (processingInstruction) {
             return processingInstruction.shouldProcessNode(node);
         });
         if (processingInstruction != null) {
             var children = compact(map(node.children, function (child, i) {
                 return traverseDom(child, isValidNode, processingInstructions, i);
             }));
             return processingInstruction.processNode(node, children, index);
         } else {
             return false;
         }
     } else {
       return false;
     }
 };
Example #18
0
function Wallet ({ className, t }: PropTypes): Element<any> {
  return (
    <div
      className={
        compact([
          styles.root, className
        ]).join(' ')
      }
    >
      <Fingerprint />
      <InfoBar>
        <Errors errors={ errorStore.errors } />
        <Transactions />
      </InfoBar>
      <Navigation />
      <Body />
    </div>
  );
}
Example #19
0
function InputPassword ({ className, example, hint, icon, isDisabled, isError, isInteger, isReadOnly, isWarning, label, onChange, t, value, valueDisplay }: PropTypes): Element<any> {
  let text = valueDisplay;

  if (!text) {
    if (!value || !value.length) {
      text = t(`ui:input.password.noPassword`);
    } else {
      text = MASKED.slice(-1 * Math.min(value.length, 15));
    }
  }

  return (
    <Input
      className={
        compact([
          styles.ui, className
        ]).join(' ')
      }
      example={ example }
      hint={ hint }
      icon={ icon }
      iconExtra={
        value
          ? (
            <Tooltip value={ value }>
              <EyeIcon />
            </Tooltip>
          )
          : null
      }
      isDisabled={ isDisabled }
      isError={ isError }
      isReadOnly={ isReadOnly }
      isWarning={ isWarning }
      label={ label }
      onChange={ onChange }
      type='password'
      value={ value }
      valueDisplay={ text }
    />
  );
}
Example #20
0
 let emojifyText = (text, options) => {
   let { delimiter, dict } = options.useEmoticon ? emojiWithEmoticons : emojiWithoutEmoticons;
   return compact(
     text.split(delimiter).map(function(word, index) {
       let match = word.match(delimiter);
       if (!!options.strict && word !== '' && match === null) throw new Error(`Could not find emoji: ${word}.`);
       if (match) {
         let hex = dict[getKey(match[0])];
         if (hex === null) return word;
         return React.createElement(
           'img',
           assign(options.attributes, {
             key: index,
             src: buildImageUrl(hex, options)
           })
         );
       } else {
         return word;
       }
     })
   );
 };
Example #21
0
      /**
       * Builds the parameter.
       *
       * @param {Object} terms The terms for being used.
       *
       * @param {Object} options Custom options.
       */
      build(terms, opts) {
        const copiedTerms = mergeWith({}, terms);

        // Preprocesses the terms with `prepare` behavior
        const preparedTerms = (prepare) ? prepare(copiedTerms, opts) : copiedTerms;

        // Validates the terms before building
        if (validate && !validate(preparedTerms, opts)) {
          return false;
        }

        // Merges using the custom behavior.
        const mergeBehavior = (params, i, n) => (
          reduce(params, (accum, param) => merge.call(this, accum, param, i, n))
        );

        // Merges string params.
        const mergeString = (params) => (
          reduce(params, (accum, param) => `${accum}${param}`)
        );

        // Merges array params.
        const mergeArray = (params) => (
          reduce(params, (accum, param) => accum.concat(param))
        );

        // Merges object params.
        const mergeObject = (params, i, n) => (
          // eslint-disable-next-line consistent-return
          mergeWith({}, ...params, (objValue, srcValue) => {
            if (merge) {
              const merged = mergeBehavior([objValue, srcValue], i, n);
              if (merged) {
                return merged;
              }
            }

            if (options.mergeArray && isArray(objValue)) {
              return mergeArray([objValue, srcValue]);
            }

            if (!options.mergeObject &&
              every([objValue, srcValue], isPlainObject)) {
              return srcValue;
            }
          })
        );

        // Merges params of any type.
        const mergeParams = (params, i, n) => {
          if (!params.length) return undefined;

          let merged;
          if (merge) {
            merged = mergeBehavior(params, i, n);
          }

          if (!merged) {
            if (every(params, isString)) {
              merged = mergeString(params);
            } else if (every(params, isArray)) {
              merged = mergeArray(params);
            } else if (every(params, isPlainObject)) {
              merged = mergeObject(params, i, n);
            }
          }

          return merged;
        };

        const n = this._combinedPBs.length - 1;

        const isFalse = (v) => v === false;

        // Builds params from parent and current PB
        const parentParams = (super.build) ? super.build(preparedTerms, opts) : undefined;

        if (isFalse(parentParams)) return false;

        let params = parentParams;
        if (run) {
          params = run.call(this, preparedTerms, opts);
          if (isFalse(params[0])) return false;
          params = mergeParams(compact([parentParams, params]));
        }

        // Gets the params from combined param builders.
        let combinedParams = params;
        forEach(this._combinedPBs, (paramBuilder, i) => {
          params = paramBuilder.build(preparedTerms, opts);
          if (isFalse(params)) {
            combinedParams = false;
            return false;
          }
          combinedParams = mergeParams(compact([combinedParams, params]), i, n);
          return true;
        });

        return combinedParams;
      }
Example #22
0
      EtherscanProvider
    ]
  }
];

const chains: Array<SelectChainType> = compact(flatten(
  CHAINS.map((chain: ChainType) => {
    return chain.providers.filter((Provider, index: number) => index === 0).map((Provider: ProviderType, index: number) => {
      const provider: ProviderStandardInterface = new Provider(chain.chainId, {});

      console.log(`Instantiated provider ${provider.name} for chainId ${chain.chainId}`);

      return {
        api: new Api(provider, true),
        chainId: chain.chainId,
        explorer: chain.explorer,
        hint: provider.name,
        icon: chain.icon,
        key: `${chain.chainId}:${index}`,
        label: chain.name,
        token: chain.token,
        tokenName: chain.tokenName || chain.name
      };
    });
  })
));

const chainDefault: ChainDefaultType = getStorage(LS_DEFAULT);

class ChainStore extends SelectStore<SelectChainType> {
  constructor () {
Example #23
0
export default function Input ({ children, className, copyValue, example, hideIcon, hint, icon, iconAction, iconExtra, inputProps = {}, isBusy, isDisabled, isError, isInverted, isLink, isMaxWidth, isMedWidth, isReadOnly, isWarning, label, onBlur, onChange, type = 'text', value, valueDisplay }: PropTypes): Element<any> {
  const _onBlur = (): void => {
    onBlur && onBlur();
  };

  const _onChange = ({ target: { value } }: { target: HTMLInputElement }): void => {
    onChange && onChange(value);
  };

  const text: string = valueDisplay || value || '';

  return (
    <div
      className={
        compact([
          styles.ui, (icon && !hideIcon) && styles.withIcon, isBusy && styles.withBusy, isDisabled && styles.withDisabled, isError && styles.withError, isInverted && styles.withInvert, isLink && styles.withLink, isMaxWidth && styles.withMaxWidth, isMedWidth && styles.withMedWidth, isReadOnly && styles.withReadOnly, isWarning && styles.withWarning, className
        ]).join(' ')
      }
    >
      <div className={ styles.content }>
        <div className={ styles.mask }>
          {
            text
              ? (
                <div className={ styles.value }>
                  { text }
                </div>
              )
              : (
                <div className={ styles.example }>
                  { example }
                </div>
              )
          }
          {
            isDisabled || isLink || isReadOnly
              ? null
              : (
                <div className={ styles.iconAction }>
                  { iconAction || <EditIcon /> }
                </div>
              )
          }
        </div>
        <div className={ styles.inputContainer }>
          {
            (!isReadOnly && !isLink)
              ? (
                children || (
                  <input
                    onBlur={ _onBlur }
                    onChange={ _onChange }
                    type={ type }
                    value={ value }
                    { ...inputProps }
                  />
                )
              )
              : null
          }
          {
            (icon && !hideIcon)
              ? (
                <div className={ styles.icon }>
                  { icon }
                </div>
              )
              : null
          }
          {
            isBusy
              ? (
                <div className={ styles.iconBusy }>
                  <BusyIcon />
                </div>
              )
              : null
          }
        </div>
      </div>
      {
        copyValue || iconExtra
          ? (
            <div className={ styles.extraIcon }>
              { iconExtra || <Clipboard value={ copyValue || '' } /> }
            </div>
          )
          : null
      }
    </div>
  );
}
Example #24
0
function Import ({ className, t }: PropTypes): Element<any> {
  return (
    <main
      className={
        compact([
          styles.root, className
        ]).join(' ')
      }
    >
      <Busy store={ store } />
      <section>
        <Form>
          <div>
            <Field>
              <Interpolate
                parent='div'
                i18nKey='details.text'
              />
              <div>
                <Select store={ store.storeType } />
              </div>
            </Field>
            <Details store={ store } />
            {
              store.shouldShowPath
                ? (
                  <Field>
                    <Interpolate
                      parent='div'
                      i18nKey='path.text'
                    />
                    <div>
                      <Select store={ store.storePath } />
                    </div>
                  </Field>
                )
                : null
            }
            {
              store.shouldShowPassword
                ? (
                  <Field>
                    <Interpolate
                      parent='div'
                      i18nKey='password.text'
                    />
                    <div>
                      <InputPassword
                        isWarning={ store.hasEmptyPassword }
                        onChange={ store.setPassword }
                        value={ store.password }
                      />
                    </div>
                  </Field>
                )
                : null
            }
            <Field>
              <Interpolate
                parent='div'
                i18nKey='storage.text'
              />
              <div>
                <Select store={ store.storeStorage } />
              </div>
            </Field>
          </div>
          <aside>
            {
              store.shouldShowPassword
                ? (
                  <Interpolate
                    parent='div'
                    i18nKey='help.password'
                  />
                )
                : null
            }
            {
              store.isHardware
                ? (
                  <Interpolate
                    parent='div'
                    i18nKey='help.hardware'
                  />
                )
                : null
            }
            <Interpolate
              parent='div'
              i18nKey='help.storage'
            />
          </aside>
        </Form>
      </section>
      <section>
        <Button
          isBusy={ store.isBusy }
          isDisabled={ store.hasError }
          label={
            store.isBusy
              ? t('buttons.create.busy')
              : t('buttons.create.label')
          }
          onClick={ store.create }
        />
      </section>
    </main>
  );
}
 .then(function(data) {
   return Promise.resolve(_compact(M3U.parse(data)));
 });
Example #26
0
    event.preventDefault();

    const $this = this.$element;
    const $amount = $this.find('.js-expense-amount');
    const $note = $this.find('.js-expense-note');
    const $date = $this.find('.js-expense-date');
    const $time = $this.find('.js-expense-time');
    const $location = $this.find('.js-expense-location');
    const date = moment($date.val()).hour($time.val());

    insert.call({
      amount: Math.round($amount.val() * 100),
      note: $note.val(),
      date: date.toDate(),
      location: $location.val(),
      tagNames: compact(uniq(this.$tagsInput.val().split(',').map(utils.slug))),
    });

    Router.go('/');

    return false;
  },
  onClickTag(event) {
    event.preventDefault();

    const $this = $(event.currentTarget);
    const name = utils.slug($this.find('.js-tag-name').text());
    let names = compact(this.$tagsInput.val().split(',').map(utils.slug));
    let value;

    if (names.indexOf(name) > -1) {
function specBrowserSrc({plugins, ...options} = {}) {
  const {plugins: configPlugins, ...config} = require('../config/webpack.config')('test');
  options = {...config, ...options, plugins: compact([...configPlugins, ...plugins])};
  return specSrc().pipe(webpackStream(options));
}