How to use the has function from ramda

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

ramda.has is a function in the Ramda library that checks if an object has a property with a given key.

125
126
127
128
129
130
131
132
133
134
    )
  )
);

const coerceColorOption = R.when(
  R.has('c'),
  R.compose(
    R.dissoc('c'),
    R.over(
      R.lens(R.prop('c'), R.assoc('color')),
fork icon303
star icon0
watch icon2

-3
fork icon2
star icon5
watch icon0

+ 2 other calls in file

How does ramda.has work?

ramda.has is a function in the Ramda library that takes a property name and an object and returns true if the specified property is found in the object and false otherwise. It works by using the Object.prototype.hasOwnProperty method to check whether the specified property exists in the object.

153
154
155
156
157
158
159
160
161
162
163
164
    }
    console.log("object keys =", _.keys(obj))
    console.log("object values =", _.values(obj))
    console.log("object add attribute =", _.assoc('height', 1.68, obj))
    console.log("object remove attribute =", _.dissoc('nationality', obj))
    console.log("object check attribute =", _.has('married', obj))


}



fork icon1
star icon2
watch icon0

206
207
208
209
210
211
212
213
214
215
216
217
var withValue = R.curry((value, entity) => R.mergeDeepRight(entity, value));


var withNoValueChange = data => data;


const retriveNestedEntity = (name, object) => {
    const foundProperty = R.has(name, object);
    if (foundProperty) {
        return {
            found: true,
            value: object[name]
fork icon4
star icon0
watch icon0

Ai Example

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

const person = {
  name: "John",
  age: 30,
  address: {
    street: "123 Main St",
    city: "New York",
    state: "NY",
  },
};

console.log(R.has("name", person)); // true
console.log(R.has("gender", person)); // false
console.log(R.has("street", person.address)); // true

In this example, we use ramda.has to check if a property exists in an object. The first console.log call checks if the name property exists in the person object and returns true. The second console.log call checks if the gender property exists in the person object and returns false. The third console.log call checks if the street property exists in the address object inside the person object and returns true.

58
59
60
61
62
63
64
65
66
67
68
    else
        return Promise.resolve(pkg)
}


Promise.map(R.map(merge, newPackages), (pkg) => {
    return R.has("forkOf", pkg) ? Promise.resolve(pkg) : pkgParentPromise(pkg)
}, { concurrency: 3 })
    .then((updatedPackages) => {
        // Overwrites the existing file!
        Fs.writeFileSync("public/tagged-packages.js", "window.packages = \n" + stringify(updatedPackages, { space: 4 }))
fork icon1
star icon0
watch icon0

+ 3 other calls in file

482
483
484
485
486
487
488
489
490
491
// convert it to an array if it is not already an array.  Then, for each
// object in the array (even if a singleton array), we remove the top-level
// of nesting.  This unnesting gives us, for example, an array of objects like
// [{GranuleUR: ...}, ...] instead of [{Granule: {GranuleUR: ...}}, ...]
const extractResults = R.when(
  R.has("results"),
  R.pipe(
    R.pathOr([], ["results", "result"]),  // Grab array or single object
    R.unless(Array.isArray, R.of),        // If single object, make an array
    R.map(R.compose(R.head, R.values)),   // Strip top level nesting on all items
fork icon1
star icon0
watch icon0

2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
* @param {String} prop The name of the property to check for.
* @param {Object} obj The object to query.
* @return {Boolean} Whether the property exists.
* @example
*
*      var hasName = R.has('name');
*      hasName({name: 'alice'});   //=> true
*      hasName({name: 'bob'});     //=> true
*      hasName({});                //=> false
*
fork icon0
star icon0
watch icon0

+ 53 other calls in file

76
77
78
79
80
81
82
83
84
let expected = "hello paul"
let obj = { name: "paul", age: 1 }
let otherObj = { age: 1 }

let greet = obj => `hello ${R.ifElse(
  R.has("name"),
  R.prop("name"),
  R.pipe(R.assoc("name", "paul"), R.prop("name"))
)(obj)}`
fork icon0
star icon0
watch icon0

+ 3 other calls in file

552
553
554
555
556
557
558
559
560
561
562
563
]
log(sortByNameCaseInsensitive(people));
log(sortByAge(people));




var hasName = R.has('name');
log(hasName({name: 'alice'}));
log(hasName({name: 'bob'}));
log(hasName({name2: 'clara', age: 11}));
log(R.has('age')({name2: 'clara', age: 11}));
fork icon0
star icon0
watch icon0

+ 19 other calls in file

39
40
41
42
43
44
45
46
47
48
curryJoinPath: R.curry((p, pathX, pathY) => p.join(pathX, pathY)),
curryResolvePath: R.curry((p, dir, path) => p.resolve(dir, path)),
notEmpty: R.compose(R.not, R.isEmpty),
//Responses endpoints
onRejected: R.curry((res, err) => {
  if (R.has('code', err) && R.has('message', err)) {
    res.status(err.code)
      .send({result: err.message})
  } else {
    console.error(moment().format(), err)
fork icon0
star icon0
watch icon0

48
49
50
51
52
53
54
55
56
57
58
59
);


const isBold = (text) => text.TS[2] === 1;


const parsePages = (pages, options = {}) => {
  const hasName = R.has(R.__, options);
  if (hasName("partition")) {
    FILTERED_VALUES = R.prop("partition", options);
  }

fork icon0
star icon0
watch icon0

+ 3 other calls in file

4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
* @param {String} prop The name of the property to check for.
* @param {Object} obj The object to query.
* @return {Boolean} Whether the property exists.
* @example
*
*      const hasName = R.has('name');
*      hasName({name: 'alice'});   //=> true
*      hasName({name: 'bob'});     //=> true
*      hasName({});                //=> false
*
fork icon0
star icon0
watch icon2

+ 15 other calls in file

40
41
42
43
44
45
46
47
48
49
var cache   = options.cache = {};

var tagKey         = options.tagKey;
var styleTagKey    = options.styleTagKey;
var childrenKey    = options.childrenKey;
var hasChildrenKey = R.has(childrenKey);
var isStyleNode    = R.where(R.objOf(tagKey, R.equals(styleTagKey)));

return function prefixStyleClassId (value) {
    var path        = this.path;
fork icon0
star icon0
watch icon0

1
2
3
4
5
6
7
8
9
10
11
12
var traverse = require('traverse');


module.exports = R.curry(function sanitize (opts, tree) {
    var options    = require('./options')(opts);
    var namekey    = options.namekey;
    var hasNameKey = R.has(namekey);
    var tagkey     = options.tagkey;
    var filters    = options.filters;


    return traverse.map(tree, function (value) {
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

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