pluck.js 643 B

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