How to use the ramda.always function in ramda

To help you get started, we’ve selected a few ramda 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 puavo-org / puavo-web / import-tool / reducers.js View on Github external
case ADD_COLUMN:
        return R.evolve({
            autoOpenColumnEditor: R.always(state.columns.length),
            columns: R.append(AllColumnTypes[action.columnType]),
        }, state);
    case CLEAR_AUTO_OPEN_COLUMN_EDITOR:
        return R.assoc("autoOpenColumnEditor", null, state);
    case DROP_ROW:
        return R.evolve({
            rows: removeByIndex(action.rowIndex),
            rowStatus: R.omit([String(action.rowIndex)]),
        }, state);
    case DROP_COLUMN:
        return R.evolve({columns: removeByIndex(action.columnIndex)}, state);
    case CHANGE_COLUMN_TYPE:
        return updateIn(["columns", action.columnIndex], R.always(AllColumnTypes[action.typeId]), state);
    case SET_ROW_STATUS:
        return updateIn(["rowStatus", action.rowIndex], R.merge(R.__, R.omit(["type"], action)), state);
    case SET_DEFAULT_SCHOOL:
        return R.assoc("defaultSchool", action.school, state);
    case SET_LEGACY_ROLES:
        return R.assoc("legacyRoles", action.legacyRoles, state);
    case SET_GROUPS:
        return R.assoc("groups", action.groups, state);
    case FILL_COLUMN:
        return R.evolve({rows: R.addIndex(R.map)((row, rowIndex) => {
            if (R.path(["rowStatus", rowIndex, "status"], state) === "ok") {
                return row;
            }
            if (!action.override && getCellValue(row[action.columnIndex])) {
                return row;
            }
github mitodl / micromasters / static / js / lib / validation / profile.js View on Github external
export const checkRomanizedNames: Validator = R.ifElse(
  shouldRenderRomanizedFields,
  mergeValidations(
    checkLatin("romanized_first_name", "Latin given name"),
    checkInvalidNameChars("romanized_first_name", "Latin given name"),
    checkMaxLength("romanized_first_name", "Latin given name", 30),
    checkIsNotNilOrEmpty(
      "romanized_first_name",
      "Latin given name is required"
    ),
    checkLatin("romanized_last_name", "Latin family name"),
    checkInvalidNameChars("romanized_last_name", "Latin family name"),
    checkMaxLength("romanized_last_name", "Latin family name", 50),
    checkIsNotNilOrEmpty("romanized_last_name", "Latin family name is required")
  ),
  R.always({})
)

export const checkPostalCode: Validator = profile => {
  if (["US", "CA"].includes(profile.country)) {
    if (isNilOrEmptyString(profile.postal_code)) {
      return { postal_code: "Postal code is required" }
    }
    if (!CP1252_REGEX.test(profile.postal_code)) {
      return { postal_code: "Postal code must be in Latin characters" }
    }
    if (
      profile.country === "US" &&
      !R.test(/^\d{5}(-\d{4})?$/, profile.postal_code)
    ) {
      return { postal_code: "Postal code must be a valid US postal code" }
    }
github ai-labs-team / casium / src / message.ts View on Github external
public static mapEvent = curry((extra: object & { preventDefault?: boolean }, event: Event) => {
    const target = event.target as HTMLInputElement;
    const isDomEvent = event && (event as any).nativeEvent && is(Object, target);
    const isCheckbox = isDomEvent && target.type && target.type.toLowerCase() === 'checkbox';
    const value = isDomEvent && (isCheckbox ? target.checked : target.value);
    const eventVal = isDomEvent ? { value, ...pickBy(not(is(Object)), event) } : event;

    if (isDomEvent && !isCheckbox && extra.preventDefault !== false) {
      suppressEvent(event);
    }
    return mergeAll([{ event: always(event) }, eventVal, extra]);
  });
}
github diegomura / react-pdf / src / node / setAlign.js View on Github external
R.tap(node => {
    const yogaNode = node._yogaNode;

    if (yogaNode) {
      const yogaValue = R.cond([
        [R.equals('flex-start'), R.always(Yoga.ALIGN_FLEX_START)],
        [R.equals('center'), R.always(Yoga.ALIGN_CENTER)],
        [R.equals('flex-end'), R.always(Yoga.ALIGN_FLEX_END)],
        [R.equals('stretch'), R.always(Yoga.ALIGN_STRETCH)],
        [R.equals('baseline'), R.always(Yoga.ALIGN_BASELINE)],
        [R.equals('space-between'), R.always(Yoga.ALIGN_SPACE_BETWEEN)],
        [R.equals('space-around'), R.always(Yoga.ALIGN_SPACE_AROUND)],
        [R.T, R.always(Yoga.ALIGN_AUTO)],
      ])(value);

      yogaNode[`setAlign${upperFirst(attr)}`](yogaValue);
    }
  });
github goodjoblife / GoodJobShare / src / components / TimeAndSalary / common / validators.js View on Github external
import { compose, when, always } from 'ramda';

export const validateSearchKeyword = when(
  keyword => typeof keyword !== 'string',
  always(''),
);

export const validatePage = compose(
  when(Number.isNaN, always(1)),
  p => parseInt(p, 10),
);
github FractalBlocks / Fractal.js / examples / mailboxNoRouter / mailbox.js View on Github external
    ChangeTab: [[String], (tabName, m) => R.evolve({tabName: R.always(tabName)}, m)],
    ChildAction: [[String, Array], (tabName, action, m) => R.evolve({[tabName]: childs[tabName].update(action)}, m)],
github vvgomes / bravent-todo / lib / command.handlers / add.todo.js View on Github external
const addTodo = (state, command, uuidGen = uuid.v4, clock = utcClock) =>
  pipe(
    validate(validations(state)),
    map(always([{
      type: "todoAdded",
      id: uuidGen(),
      text: command.text,
      timestamp: clock()
    }]))
  )(command);
github amazeeio / lagoon / cli / src / commands / customer.js View on Github external
const { errors } = result;
  if (errors != null) {
    return printGraphQLErrors(cerr, ...errors);
  }

  const customer = R.path(['data', 'projectByName', 'customer'], result);

  if (customer == null) {
    clog(red(`No customer found for project '${project}'!`));
    return 0;
  }

  const formatDeployPrivateKey = R.ifElse(
    R.identity,
    R.always('\u221A'),
    R.always('\u2717'),
  );
  const formatSshKeys: (Array) => Array = R.map(R.prop('name'));

  clog(`Customer details for project '${project}':`);
  clog(
    table([
      ['Name', R.prop('name', customer)],
      ['Comment', R.prop('comment', customer)],
      [
        'Deploy Private Key',
        formatDeployPrivateKey(R.prop('private_key', customer)),
      ],
      [
        'SSH Keys',
        R.join(', ', formatSshKeys(R.propOr([], 'sshKeys')(customer))),