Socket
Socket
Sign inDemoInstall

react-filter-search

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-filter-search - npm Package Compare versions

Comparing version 1.0.11 to 1.1.11

10

es/filter.js
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
import pick from 'pick-deep';
function strOp(str) {

@@ -7,4 +9,4 @@ return str.toString().replace(/\s/g, '').toLowerCase();

function objectValues(value) {
return Object.values(value).reduce(function (string, val) {
function objectValues(value, pickAttr) {
return (pickAttr ? Object.values(pick(value, pickAttr)) : Object.values(value)).reduce(function (string, val) {
var test = val !== null && val !== undefined;

@@ -15,6 +17,6 @@ return string + ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val !== null ? strOp(objectValues(val)) : test ? strOp(val) : '');

export function filter(val, data) {
export function filter(val, data, pick) {
return data.filter(function (el) {
return !!val.length ? objectValues(el).includes(strOp(val)) : true;
return !!val.length ? objectValues(el, pick).includes(strOp(val)) : true;
});
}

8

es/index.js

@@ -23,5 +23,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

value = _props.value,
data = _props.data;
data = _props.data,
pick = _props.pick;
return this.props.renderResults(filter(value, data));
return this.props.renderResults(filter(value, data, pick));
};

@@ -38,3 +39,4 @@

data: PropTypes.arrayOf(PropTypes.object).isRequired,
renderResults: PropTypes.func.isRequired
renderResults: PropTypes.func.isRequired,
pick: PropTypes.arrayOf(PropTypes.string)
} : {};

@@ -8,2 +8,9 @@ 'use strict';

exports.filter = filter;
var _pickDeep = require('pick-deep');
var _pickDeep2 = _interopRequireDefault(_pickDeep);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function strOp(str) {

@@ -13,4 +20,4 @@ return str.toString().replace(/\s/g, '').toLowerCase();

function objectValues(value) {
return Object.values(value).reduce(function (string, val) {
function objectValues(value, pickAttr) {
return (pickAttr ? Object.values((0, _pickDeep2.default)(value, pickAttr)) : Object.values(value)).reduce(function (string, val) {
var test = val !== null && val !== undefined;

@@ -21,6 +28,6 @@ return string + ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val !== null ? strOp(objectValues(val)) : test ? strOp(val) : '');

function filter(val, data) {
function filter(val, data, pick) {
return data.filter(function (el) {
return !!val.length ? objectValues(el).includes(strOp(val)) : true;
return !!val.length ? objectValues(el, pick).includes(strOp(val)) : true;
});
}

@@ -34,5 +34,6 @@ 'use strict';

value = _props.value,
data = _props.data;
data = _props.data,
pick = _props.pick;
return this.props.renderResults((0, _filter.filter)(value, data));
return this.props.renderResults((0, _filter.filter)(value, data, pick));
};

@@ -49,4 +50,5 @@

data: _propTypes2.default.arrayOf(_propTypes2.default.object).isRequired,
renderResults: _propTypes2.default.func.isRequired
renderResults: _propTypes2.default.func.isRequired,
pick: _propTypes2.default.arrayOf(_propTypes2.default.string)
} : {};
module.exports = exports['default'];
{
"name": "react-filter-search",
"version": "1.0.11",
"version": "1.1.11",
"description": "React Filter Search is a React component for filtering client-side data rendered to your UI.",

@@ -22,3 +22,5 @@ "main": "lib/index.js",

},
"dependencies": {},
"dependencies": {
"pick-deep": "^1.0.0"
},
"peerDependencies": {

@@ -25,0 +27,0 @@ "react": "16.x"

@@ -88,2 +88,15 @@ # React Filter Search πŸ”

If you wish to filter only using certain attributes then you can use the optional `pick` prop.
```javascript
// if each object is of the form
var obj = { name: "Leanne Graham", username: "Bret", email: "Sincere@april.biz", company: {"name": "Romaguera-Crona"} }
<SearchResults
...
pick={['username', 'company.name']}
...
/>
// your objects will be filtered only with the name and company.name fields
// but you can still render other values like username and email
```
To render your data, simply use .map() to render to the view--the data retains in the same structure. Return some inline JSX, or feed each element into a stateless React component that renders some UI.

@@ -98,6 +111,6 @@

| `reunderResults` | `func` | `true` |
| `pick` | `array` of `string`s | `false` |
## Contributions
Read [`CONTRIBUTING.md`](https://github.com/joehdodd/react-filter-search/blob/master/CONTRIBUTING.md) and join the fun! πŸŽ‰
/*!
* react-filter-search v1.0.11 - https://github.com/joehdodd/react-filter-search
* react-filter-search v1.1.11 - https://github.com/joehdodd/react-filter-search
* MIT Licensed

@@ -98,3 +98,3 @@ */

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })

@@ -116,3 +116,3 @@ /************************************************************************/

// http://fb.me/prop-types-in-prod
module.exports = __webpack_require__(3)();
module.exports = __webpack_require__(4)();
}

@@ -131,5 +131,37 @@

module.exports = __webpack_require__(5);
"use strict";
const get = __webpack_require__(6);
const set = __webpack_require__(7);
const isObject = val => Object.prototype.toString.call(val) === '[object Object]';
const pick = (obj, paths, length, sep) => {
const picked = {};
for (let i = 0; i < length; i++) {
const path = paths[i];
const val = get(obj, path, sep);
if (val === undefined) {
continue; // eslint-disable-line no-continue
}
set(picked, path, val, sep);
}
return picked;
};
module.exports = (obj, paths, sep = '.') => {
if (!isObject(obj) || !paths || !(Array.isArray(paths) || typeof paths === 'string')) {
return {};
}
const { length } = paths;
if (typeof paths === 'string' || length < 2) {
const path = typeof paths === 'string' ? paths : paths[0];
const val = get(obj, path, sep);
return val !== undefined ? set({}, path, val, sep) : {};
}
return pick(obj, paths, length, sep);
};
/***/ }),

@@ -139,2 +171,9 @@ /* 3 */

module.exports = __webpack_require__(8);
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";

@@ -150,3 +189,3 @@ /**

var ReactPropTypesSecret = __webpack_require__(4);
var ReactPropTypesSecret = __webpack_require__(5);

@@ -209,3 +248,3 @@ function emptyFunction() {}

/***/ }),
/* 4 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {

@@ -229,3 +268,85 @@

/***/ }),
/* 5 */
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
const isObject = val => Object.prototype.toString.call(val) === '[object Object]';
const get = (obj, parts, length) => {
for (let i = 0; i < length; i++) {
if (obj === null) {
return;
}
const v = obj[parts[i]];
if (v === undefined) {
return;
}
obj = v;
}
return obj;
};
module.exports = (obj, path, sep = '.') => {
if (!isObject(obj) || !path) {
return obj;
}
const parts = Array.isArray(path) ? path : String(path).split(sep);
const { length } = parts;
return length < 2 ? obj[parts[0]] : get(obj, parts, length);
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* eslint-disable no-continue */
const isObject = (val) => typeof val === 'object' || typeof val === 'function';
const isProto = (val, obj) => val === '__proto__' || (val === 'constructor' && typeof obj.constructor === 'function');
const set = (obj, parts, length, val) => {
let tmp = obj;
let i = 0;
for (; i < length - 1; i++) {
const part = parts[i];
if (isProto(part, tmp)) {
continue;
}
tmp = !isObject(tmp[part]) ? tmp[part] = {} : tmp[part];
}
tmp[parts[i]] = val;
return obj;
};
/**
* Sets nested values on an object using a dot path or custom separator
* @param {Object} obj
* @param {String|Array} path
* @param {Any} val
* @param {String} [sep = '.']
* @returns {Object}
*/
module.exports = (obj, path, val, sep = '.') => {
if (!isObject(obj) || !path || !path.length) {
return obj;
}
const parts = Array.isArray(path) ? path : String(path).split(sep);
if (isProto(parts[0], obj)) {
return obj;
}
const { length } = parts;
if (length === 1) {
obj[parts[0]] = val;
return obj;
}
return set(obj, parts, length, val);
};
/***/ }),
/* 8 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

@@ -243,5 +364,11 @@

// EXTERNAL MODULE: ./node_modules/pick-deep/main.js
var main = __webpack_require__(2);
var main_default = /*#__PURE__*/__webpack_require__.n(main);
// CONCATENATED MODULE: ./src/filter.js
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function strOp(str) {

@@ -251,4 +378,4 @@ return str.toString().replace(/\s/g, '').toLowerCase();

function objectValues(value) {
return Object.values(value).reduce(function (string, val) {
function objectValues(value, pickAttr) {
return (pickAttr ? Object.values(main_default()(value, pickAttr)) : Object.values(value)).reduce(function (string, val) {
var test = val !== null && val !== undefined;

@@ -259,5 +386,5 @@ return string + ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && val !== null ? strOp(objectValues(val)) : test ? strOp(val) : '');

function filter(val, data) {
function filter(val, data, pick) {
return data.filter(function (el) {
return !!val.length ? objectValues(el).includes(strOp(val)) : true;
return !!val.length ? objectValues(el, pick).includes(strOp(val)) : true;
});

@@ -289,5 +416,6 @@ }

value = _props.value,
data = _props.data;
data = _props.data,
pick = _props.pick;
return this.props.renderResults(filter(value, data));
return this.props.renderResults(filter(value, data, pick));
};

@@ -304,3 +432,4 @@

data: prop_types_default.a.arrayOf(prop_types_default.a.object).isRequired,
renderResults: prop_types_default.a.func.isRequired
renderResults: prop_types_default.a.func.isRequired,
pick: prop_types_default.a.arrayOf(prop_types_default.a.string)
};

@@ -307,0 +436,0 @@

/*!
* react-filter-search v1.0.11 - https://github.com/joehdodd/react-filter-search
* react-filter-search v1.1.11 - https://github.com/joehdodd/react-filter-search
* MIT Licensed
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactSearchFilter=t(require("react")):e.ReactSearchFilter=t(e.React)}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(t,n){t.exports=e},function(e,t,n){e.exports=n(2)},function(e,t,n){"use strict";n.r(t);var r=n(0),o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function u(e){return e.toString().replace(/\s/g,"").toLowerCase()}function i(e,t){return t.filter(function(t){return!e.length||function e(t){return Object.values(t).reduce(function(t,n){var r=null!==n&&void 0!==n;return t+("object"===(void 0===n?"undefined":o(n))&&null!==n?u(e(n)):r?u(n):"")},"")}(t).includes(u(e))})}n.d(t,"default",function(){return c});var c=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.render=function(){var e=this.props,t=e.value,n=e.data;return this.props.renderResults(i(t,n))},t}(r.Component)}]).default});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactSearchFilter=e(require("react")):t.ReactSearchFilter=e(t.React)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(e,r){e.exports=t},function(t,e,r){"use strict";const n=r(3),o=r(4);t.exports=((t,e,r=".")=>{if(!(t=>"[object Object]"===Object.prototype.toString.call(t))(t)||!e||!Array.isArray(e)&&"string"!=typeof e)return{};const{length:u}=e;if("string"==typeof e||u<2){const u="string"==typeof e?e:e[0],i=n(t,u,r);return void 0!==i?o({},u,i,r):{}}return((t,e,r,u)=>{const i={};for(let c=0;c<r;c++){const r=e[c],f=n(t,r,u);void 0!==f&&o(i,r,f,u)}return i})(t,e,u,r)})},function(t,e,r){t.exports=r(5)},function(t,e,r){"use strict";t.exports=((t,e,r=".")=>{if(!(t=>"[object Object]"===Object.prototype.toString.call(t))(t)||!e)return t;const n=Array.isArray(e)?e:String(e).split(r),{length:o}=n;return o<2?t[n[0]]:((t,e,r)=>{for(let n=0;n<r;n++){if(null===t)return;const r=t[e[n]];if(void 0===r)return;t=r}return t})(t,n,o)})},function(t,e,r){"use strict";const n=t=>"object"==typeof t||"function"==typeof t,o=(t,e)=>"__proto__"===t||"constructor"===t&&"function"==typeof e.constructor;t.exports=((t,e,r,u=".")=>{if(!n(t)||!e||!e.length)return t;const i=Array.isArray(e)?e:String(e).split(u);if(o(i[0],t))return t;const{length:c}=i;return 1===c?(t[i[0]]=r,t):((t,e,r,u)=>{let i=t,c=0;for(;c<r-1;c++){const t=e[c];o(t,i)||(i=n(i[t])?i[t]:i[t]={})}return i[e[c]]=u,t})(t,i,c,r)})},function(t,e,r){"use strict";r.r(e);var n=r(0),o=r(1),u=r.n(o),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function c(t){return t.toString().replace(/\s/g,"").toLowerCase()}function f(t,e,r){return e.filter(function(e){return!t.length||function t(e,r){return(r?Object.values(u()(e,r)):Object.values(e)).reduce(function(e,r){var n=null!==r&&void 0!==r;return e+("object"===(void 0===r?"undefined":i(r))&&null!==r?c(t(r)):n?c(r):"")},"")}(e,r).includes(c(t))})}r.d(e,"default",function(){return s});var s=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.render=function(){var t=this.props,e=t.value,r=t.data,n=t.pick;return this.props.renderResults(f(e,r,n))},e}(n.Component)}]).default});
//# sourceMappingURL=react-filter-search.min.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc