_castPath.js 567 B

123456789101112131415161718192021
  1. import isArray from './isArray.js';
  2. import isKey from './_isKey.js';
  3. import stringToPath from './_stringToPath.js';
  4. import toString from './toString.js';
  5. /**
  6. * Casts `value` to a path array if it's not one.
  7. *
  8. * @private
  9. * @param {*} value The value to inspect.
  10. * @param {Object} [object] The object to query keys on.
  11. * @returns {Array} Returns the cast property path array.
  12. */
  13. function castPath(value, object) {
  14. if (isArray(value)) {
  15. return value;
  16. }
  17. return isKey(value, object) ? [value] : stringToPath(toString(value));
  18. }
  19. export default castPath;