Can Ramda have isString?
Background
I am trying to use ramda and I need a pure function that lets me know if a given input is a string or not, much like lodash _.isString
.
Question
After searching everywhere I couldn't find anything in Ramda for this. So I wonder, is there a way, using any of Ramda's existing functions, that I can create a isString
function?
I find this horribly limiting and is it is not possible i might just use lodash in the end :S
Rather than have isString
, isObject
, isArray
, isFunction
, etc, Ramda simply provides is
, which you can use to create any of these you like:
const isString = R.is(String)
const isRectangle = R.is(Rectangle)
isString('foo') //=> true
isString(42) //=> false
isRectangle(new Rectangle(3, 5)) //=> true
isRectangle(new Square(7)) //=> true (if Rectangle is in the prototype chain of Square)
isRectangle(new Triangle(3, 4, 5)) //=> false
And you don't have to create the intermediate function. You can just use it as is:
R.is(String, 'foo') //=> true
R.is(String, {a: 'foo'}) //=> false
链接地址: http://www.djcxy.com/p/94980.html
上一篇: 更容易的方法使RegExp.test()对于空值返回false?
下一篇: 拉姆达可以有isString吗?