How to use map-obj - 8 common examples

To help you get started, we’ve selected a few map-obj 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 flow-typed / flow-typed / definitions / npm / map-obj_v1.x.x / test_map-obj_v1.x.x.js View on Github external
import mapObj from 'map-obj';

const newObject: Object = mapObj({ foo: 'bar' }, function(key: string, value: any, object: Object) {
  // first element is the new key and second is the new value
  // here we reverse the order
  return [value, key];
});

// $ExpectError
mapObj({a: 1}, (key, value, obj) => { obj.b; });

// $ExpectError
mapObj({a: 1}, (key, value, obj) => { obj.a = 'asdf'; });

// $ExpectError
(mapObj({a: 1}, (key, value, obj) => { return {b: 'asdf'}; }): {[key: string]: number});
github gajus / headless-crawler / test / headless-crawler / factories / createHeadlessCrawler / crawl.js View on Github external
const omitPath = (path) => {
  return deepMap(path, (key, value) => {
    if (key === 'path') {
      return [
        key,
        null
      ];
    }

    return [
      key,
      value
    ];
  }, {
    deep: true
  });
};
github gajus / headless-crawler / test / headless-crawler / factories / createHeadlessCrawler / crawl.js View on Github external
const overrideLastAttemptedAt = (path) => {
  return deepMap(path, (key, value) => {
    if (key === 'lastAttemptedAt' && typeof value === 'number') {
      return [
        key,
        '[OVERRIDDEN]'
      ];
    }

    return [
      key,
      value
    ];
  }, {
    deep: true
  });
};
github victorporof / Sublime-HTMLPrettify / src / js / utils / configSanitizers.js View on Github external
export const translateEditorConfigToJsbeautifyConfig = editorConfig => ({
  custom: mapObj(pickBy(editorConfig, (v, k) => isGlob(k) && isObject(v)), (globString, globConfig) => [
    globString, mapObj(globConfig, (prefName, prefValue) => {
      switch (prefName) {
        case 'indent_style':
          return [
            'indent_char', sanitizeCharishValues(prefValue),
          ];
        case 'insert_final_newline':
          return [
            'end_with_newline', prefValue,
          ];
        default:
          return [
            prefName, prefValue,
          ];
      }
    }),
github export-mike / camelcase-keys-recursive / src / index.js View on Github external
function camelCaseRecursive(obj) {

  const transform = obj == null ? obj : mapObj(obj, (key, val) => {
    const newArray = [];

    if (Array.isArray(val)) {
      val.forEach((value) => {
        if (isObject(value) && !Array.isArray(value)) {
          newArray.push(camelCaseRecursive(value));
        } else {
          newArray.push(value);
        }
      });

      return [camelCase(key), newArray];
    } else if (!val) {
      return [camelCase(key), val];
    } else if (val instanceof Date) {
      return [camelCase(key), val];
github victorporof / Sublime-HTMLPrettify / src / js / utils / configSanitizers.js View on Github external
custom: mapObj(pickBy(editorConfig, (v, k) => isGlob(k) && isObject(v)), (globString, globConfig) => [
    globString, mapObj(globConfig, (prefName, prefValue) => {
      switch (prefName) {
        case 'indent_style':
          return [
            'indent_char', sanitizeCharishValues(prefValue),
          ];
        case 'insert_final_newline':
          return [
            'end_with_newline', prefValue,
          ];
        default:
          return [
            prefName, prefValue,
          ];
      }
    }),
  ]),
github tinajs / wxio / src / index.js View on Github external
function mapPatterns (original, rules) {
  return map(rules, (name, { pattern, moduleName }) => {
    switch (pattern) {
      case PATTERN.SYNC:
      case PATTERN.EVENT:
        return [name, original[name]]

      case PATTERN.ASYNC:
        return [name, promisify(original[name])]

      case PATTERN.MODULE:
        return [name, function () {
          const instance = original[name].apply(this, arguments)
          return mapPatterns(instance, APIS[moduleName])
        }]

      default:
        throw new Error('Invalid pattern.')
github gajus / format-graphql / src / utilities / formatSdl.js View on Github external
export default (schemaSdl: string): string => {
  return print(mapObject(parse(schemaSdl), (key, value) => {
    if ((key === 'fields' || key === 'definitions') && Array.isArray(value)) {
      return [
        key,
        value.slice().sort((a, b) => {
          return a.name.value.localeCompare(b.name.value);
        }),
      ];
    }

    return [
      key,
      value,
    ];
  }, {
    deep: true,
  }));

map-obj

Map object keys and values into a new object

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis

Popular map-obj functions