castPath.js 495 B

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