pluck.js 755 B

12345678910111213141516171819202122232425
  1. import { map } from './map';
  2. export function pluck() {
  3. var properties = [];
  4. for (var _i = 0; _i < arguments.length; _i++) {
  5. properties[_i] = arguments[_i];
  6. }
  7. var length = properties.length;
  8. if (length === 0) {
  9. throw new Error('list of properties cannot be empty.');
  10. }
  11. return map(function (x) {
  12. var currentProp = x;
  13. for (var i = 0; i < length; i++) {
  14. var p = currentProp === null || currentProp === void 0 ? void 0 : currentProp[properties[i]];
  15. if (typeof p !== 'undefined') {
  16. currentProp = p;
  17. }
  18. else {
  19. return undefined;
  20. }
  21. }
  22. return currentProp;
  23. });
  24. }
  25. //# sourceMappingURL=pluck.js.map