argsArgArrayOrObject.js 687 B

12345678910111213141516171819202122
  1. const { isArray } = Array;
  2. const { getPrototypeOf, prototype: objectProto, keys: getKeys } = Object;
  3. export function argsArgArrayOrObject(args) {
  4. if (args.length === 1) {
  5. const first = args[0];
  6. if (isArray(first)) {
  7. return { args: first, keys: null };
  8. }
  9. if (isPOJO(first)) {
  10. const keys = getKeys(first);
  11. return {
  12. args: keys.map((key) => first[key]),
  13. keys,
  14. };
  15. }
  16. }
  17. return { args: args, keys: null };
  18. }
  19. function isPOJO(obj) {
  20. return obj && typeof obj === 'object' && getPrototypeOf(obj) === objectProto;
  21. }
  22. //# sourceMappingURL=argsArgArrayOrObject.js.map