How to use the omit function from ramda

Find comprehensive JavaScript ramda.omit code examples handpicked from public code repositorys.

ramda.omit is a function that creates a new object with all properties of the input object except the ones specified in the second argument.

282
283
284
285
286
287
288
289
290
291
// 1.extract codebase path and runtime
let skillJson = fs.readJSONSync(skillJsonPath, "utf-8");
if (skillJson.skillManifest) {
  // some templates still use "skillManifest" which is the v0 manifest structure
  skillJson.manifest = R.clone(skillJson.skillManifest);
  skillJson = R.omit(["skillManifest"], skillJson);
}
const apisCustom = R.view(R.lensPath(["manifest", "apis", "custom"]), skillJson);
const lambdaResources = R.view(R.lensPath(["deploy_settings", profile, "resources", "lambda"]), v1Config);
const askResourcesJson = _decideAskResourcesJson(apisCustom, lambdaResources, profile);
fork icon50
star icon139
watch icon0

+ 9 other calls in file

738
739
740
741
742
743
744
745
746
747
.then(() => asAlice.post('/v1/projects/1/forms?publish=true')
  .send(testData.forms.simpleEntity.replace(/people/, 'goodone')))
.then(() => asAlice.patch('/v1/projects/1/forms/withAttachments/draft/attachments/goodone.csv')
  .send({ dataset: true })
  .expect(200)
  .then(({ body }) => omit(['updatedAt'], body).should.be.eql({
    name: 'goodone.csv',
    type: 'file',
    exists: true,
    blobExists: false,
fork icon49
star icon43
watch icon0

+ 3 other calls in file

How does ramda.omit work?

ramda.omit is a function that takes an object and an array of property names and returns a new object with all the properties of the original object except for those whose names appear in the array. Internally, it uses Array.prototype.reduce to iterate over the keys of the object and conditionally copy them to a new object, omitting the ones specified in the array. The original object is not modified.

226
227
228
229
230
231
232
233
234
235
      _id: { $in: expectedUpdatedDocuments.map(doc => doc._id) },
    }
  ).toArray()

  for (let i = 0; i < updatedDocs.length; i++) {
    const actual = omit(['_id', 'updaterId', 'updatedAt'], updatedDocs[i])
    const expected = omit(['_id', 'updaterId', 'updatedAt'], expectedUpdatedDocuments[i])
    t.strictSame(actual, expected)
  }
})
fork icon3
star icon33
watch icon13

+ 1235 other calls in file

161
162
163
164
165
166
167
168
169
170
    const actual = { ...responseDocument }
    t.ok(Number.isFinite(new Date(actual.updatedAt).getTime()))
    delete actual.updatedAt
    t.strictSame(actual, expected)
  } else {
    const otherProperties = omit(['_id', 'name'], responseDocument)
    t.strictSame(otherProperties, UPDATES)
  }
  t.end()
})
fork icon2
star icon32
watch icon12

+ 362 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
const R = require("ramda");

const data = {
  name: "John",
  age: 30,
  gender: "male",
};

const result = R.omit(["age"], data);

console.log(result); // Output: { name: 'John', gender: 'male' }

In this example, ramda.omit is used to remove the age property from the data object. The resulting object, result, contains all the properties of data except for age.

378
379
380
381
382
383
384
385
386
387
    }
})

const expectedDocsWithExcludedFields = fixtures.map((doc) => {
  const docCopy = { ...doc }
  return omit(['attachments', 'isbn', 'price'], docCopy)
})

t.test('should return only the right fields', async t => {
  t.plan(1)
fork icon2
star icon32
watch icon12

+ 123 other calls in file

107
108
109
110
111
112
113
114
115
116
})

t.test('should insert the doc in the database', async t => {
  t.plan(1)
  const doc = await collection.findOne({ _id: ret._id })
  const docWithoutId = omit(['_id'], doc)

  t.strictSame(docWithoutId, {
    name: 'Strange Book',
    price: 44,
fork icon2
star icon32
watch icon0

+ 3 other calls in file

75
76
77
78
79
80
81
82
83
84
85
}


function tryParseErrorObjectToString (error) {
  try {
    // R.over(R.lensProp('audience_sizes'), R.omit(['fb']), R.omit(['id'], obj))
    // const reducedError = R.omit(['stack', 'originalError'], error)
    const reducedError = R.over(R.lensProp('originalError'), R.omit(['stack']), R.omit(['stack'], error))
    const errorAsString = util.inspect(reducedError, true)
    return `error object:\n${errorAsString}`
  } catch (e) {
fork icon14
star icon12
watch icon0

305
306
307
308
309
310
311
312
313
314
var mergedMessages = mergeKeys.map(function (key) {
  var updateFromDefaults = _this.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);
  var translation = updateFromDefaults ? nextCatalog[key].message : prevCatalog[key].translation;
  return (0, _defineProperty2.default)({}, key, _objectSpread({
    translation: translation
  }, R.omit(["obsolete, translation"], nextCatalog[key])));
}); // Mark all remaining translations as obsolete
// Only if *options.files* is not provided

var obsoleteMessages = obsoleteKeys.map(function (key) {
fork icon1
star icon0
watch icon0

113
114
115
116
117
118
119
120
121
122
123
  const { code, config, name, response = {} } = error;
  const props = R.pickBy(isNotMissing, {
    code,
    config,
    name,
    response: R.omit(['config', 'request'], response),
  });


  return Object.assign(new Error(message), props);
}
fork icon1
star icon0
watch icon0

59
60
61
62
63
64
65
66
67
68
// toString :: Link -> String
const toString = R.compose(
  JSON.stringify,
  R.when(
    R.compose(R.equals(0), R.view(lens.attempts)),
    R.omit(['attempts'])
  ),
  R.filter(isUseful)
)

fork icon0
star icon4
watch icon0

125
126
127
128
129
130
131
132
133
134
nameServices = _yield$makeCall$nameS === void 0 ? {} : _yield$makeCall$nameS;
search = _yield$makeCall.search;
response = _objectWithoutProperties(_yield$makeCall, ["icons", "tabs", "nameServices", "search"]);
isSetCountry = Boolean(Number(country));
countryService = isSetCountry ? search.countryService : response.countryService;
searchGroup = isSetCountry ? R.omit(['countryService'], search) : extractServicesFromResponse(R.omit(['countryService'], response));
return _context.abrupt("return", R.mergeAll([{
  icons: icons,
  tabs: tabs
}, {
fork icon0
star icon3
watch icon3

81
82
83
84
85
86
87
88
89
90
  const contentEditable = !nextProps.viewOnly && nextProps.editable;
  if (!contentEditable) if (nextProps.active | 0) return false;
}

const list = [];
const nProps = omit(list, nextProps);
const cProps = omit(list, this.props);
if (equals(nProps, cProps)) {
  return false;
}
fork icon0
star icon0
watch icon4

+ 255 other calls in file

63
64
65
66
67
68
69
70
71
72
73
74
    });
  });
};


userSchema.methods.hidePassword = function() {
  return R.omit(['password', '_id'], this.toObject({ virtuals: true }));
};


const User = mongoose.model('User', userSchema);

fork icon0
star icon0
watch icon1

5
6
7
8
9
10
11
12
13
14
const userAppList = async (req, res, next) => {
  const { params: { userId } } = req;
  try {
    const userAppKeys = (await UserAppKey.findAll({ where: { userId } }))
      .map(userAppKey => userAppKey.dataValues);
    return res.json({ userAppKeys: userAppKeys.map(userAppKey => omit(['appKey', 'id'], userAppKey)) });
  } catch (err) {
    return next(err);
  }
};
fork icon0
star icon0
watch icon3

8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
 * @param {Object} obj The object to copy from
 * @return {Object} A new object with properties from `names` not on it.
 * @see R.pick
 * @example
 *
 *      R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3}
 */
var omit = _curry2(function omit(names, obj) {
    var result = {};
    for (var prop in obj) {
fork icon0
star icon0
watch icon0

+ 17 other calls in file

44
45
46
47
48
49
50
51
52
53
it('returns FAKE_TENANT_CONNECTION_DATA when creating an tenantConnection with all correct params', done => {
  createTenantConnection(FAKE_TENANT_CONNECTION_DATA)
    .then(res => {
      expect(commonMocks.recursivelyOmitProps(['timestamp', 'created'], res))
        .toEqual(R.compose(
          R.omit(privateFields),
          mergeInsertId,
          R.over(R.lensProp('metaJson'), JSON.parse)
        )(FAKE_TENANT_CONNECTION_DATA));
      done();
fork icon0
star icon0
watch icon0

+ 3 other calls in file

15
16
17
18
19
20
21
22
23
24
25
      FAKE_TENANT_ACCESS_PERMISSION_DATA            = {
        tenantAccessRoleId     : KNOWN_TEST_TENANT_ACCESS_ROLE_ID,
        tenantAccessResourceId : KNOWN_TEST_UNMAPPED_TENANT_ACCESS_RESOURCE_ID,
        status                 : 1
      },
      FAKE_TENANT_ACCESS_PERMISSION_DATA_INCOMPLETE = R.omit(['tenantAccessRoleId'], FAKE_TENANT_ACCESS_PERMISSION_DATA);


let FAKE_TENANT_ACCESS_PERMISSION_DATA_WITH_KNOWN_TEST_TENANT_ACCESS_RESOURCE_ID,
    mergeInsertId;

fork icon0
star icon0
watch icon0

29
30
31
32
33
34
35
36
37
38
39
40
        taxRate   : 0.08,
        subdomain : 'testtenant',
        metaJson  : JSON.stringify({ '1st floor' : [{ foo : 'bar', baz : 'bat' }, { foo : 'bar', baz : 'bat' }] }),
        status    : 1
      },
      FAKE_TENANT_ORGANIZATION_DATA_INCOMPLETE = R.omit(['email'], FAKE_TENANT_ORGANIZATION_DATA);


let mergeInsertId;


describe('tenantOrganizationCtrl.createTenantOrganization', () => {
fork icon0
star icon0
watch icon0

+ 3 other calls in file

32
33
34
35
36
37
38
39
40
41
    KNOWN_TEST_TENANT_DATA                  = R.compose(R.head, commonMocks.transformDbColsToJsProps)(data);
    KNOWN_TEST_EXISTING_DOMAIN              = R.compose(R.prop('domain'), R.last, commonMocks.transformDbColsToJsProps)(data);
    KNOWN_TEST_TENANT_ID                    = R.prop('id', KNOWN_TEST_TENANT_DATA);
    FAKE_TENANT_UPDATE_DATA_EXISTING_DOMAIN = R.objOf('domain', KNOWN_TEST_EXISTING_DOMAIN);

    updatedTenantData = R.omit(privateFields, R.mergeDeepRight(KNOWN_TEST_TENANT_DATA, FAKE_TENANT_UPDATE_DATA));

    done();
  });
});
fork icon0
star icon0
watch icon0

39
40
41
42
43
44
45
46
47
48
it('returns all cloudUsers', done => {
  getAllCloudUsers()
    .then(res => {
      res = R.map(R.compose(
        R.over(birthdayLens, d => d === '0000-00-00' ? d : moment(d).format(CALENDAR_DATE_FORMAT)),
        R.omit(privateFields)
      ))(res);
      expect(commonMocks.recursivelyOmitProps(['timestamp', 'created'], res))
        .toEqual(KNOWN_TEST_CLOUD_USER_DATA);
      done();
fork icon0
star icon0
watch icon0

+ 2 other calls in file

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)