ramda-extension
Version:
Helpful functions built on top of the mighty Ramda
46 lines (45 loc) • 1.13 kB
JavaScript
import { identity, useWith, __, o, test, unless } from 'ramda';
import searchInArrayWith from './searchInArrayWith';
import isReqExp from './isRegExp';
import constructReqExp from './constructRegExp';
var insensitiveReqExp = /*#__PURE__*/constructReqExp(__, 'gi');
var testRegexp = /*#__PURE__*/o(test, /*#__PURE__*/unless(isReqExp, insensitiveReqExp));
/**
* Perform fulltext search with given search function.
*
* @func
* @category Array
*
* @param {Array} searchFn
* @param {Array} value
* @return {Array} filtered array of values
*
* @example
*
* R_.searchInArrayWith(R.contains('hi'),[
* 'hi',
* { foo: 'bar' },
* { foo: 'hi' },
* {
* foo: {
* bar: ['cuuus', { foo: 'hi' }],
* },
* },
* ['haha', 'hi'],
* ['haha', { foo: 'hi' }],
* ]);
* // [
* // 'hi',
* // { foo: 'hi' },
* // {
* // foo: {
* // bar: ['cuuus', { foo: 'hi' }],
* // },
* // },
* // ['haha', 'hi'],
* // ['haha', { foo: 'hi' }],
* // ]
*
*/
var searchInArray = /*#__PURE__*/useWith(searchInArrayWith, [testRegexp, identity]);
export default searchInArray;