Ramda有没有isString?

Fla*_*nix 5 javascript ramda.js

背景

我正在尝试使用ramda,我需要一个纯函数,让我知道给定的输入是否是一个字符串,就像lodash一样_.isString.

在搜索到处后,我在Ramda找不到任何东西.所以我想知道,有没有一种方法,使用任何Ramda的现有功能,我可以创建一个isString函数?

我发现这可怕的限制,我不可能最后使用lodash:S

Sco*_*yet 15

而不是有isString,isObject,isArray,isFunction,等,Ramda只是提供is,你可以用它来创建任何一种你喜欢:

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
Run Code Online (Sandbox Code Playgroud)

而且您不必创建中间函数.您可以按原样使用它:

R.is(String, 'foo') //=> true
R.is(String, {a: 'foo'}) //=> false
Run Code Online (Sandbox Code Playgroud)