UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

60 lines (52 loc) 1.45 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _ramda = require("ramda"); var _searchInArrayWith = _interopRequireDefault(require("./searchInArrayWith")); var _isRegExp = _interopRequireDefault(require("./isRegExp")); var _constructRegExp = _interopRequireDefault(require("./constructRegExp")); var insensitiveReqExp = (0, _constructRegExp.default)(_ramda.__, 'gi'); var testRegexp = (0, _ramda.o)(_ramda.test, (0, _ramda.unless)(_isRegExp.default, 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 = (0, _ramda.useWith)(_searchInArrayWith.default, [testRegexp, _ramda.identity]); var _default = searchInArray; exports.default = _default;