25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
840 B

4 년 전
  1. var memoizeCapped = require('./_memoizeCapped');
  2. /** Used to match property names within property paths. */
  3. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  4. /** Used to match backslashes in property paths. */
  5. var reEscapeChar = /\\(\\)?/g;
  6. /**
  7. * Converts `string` to a property path array.
  8. *
  9. * @private
  10. * @param {string} string The string to convert.
  11. * @returns {Array} Returns the property path array.
  12. */
  13. var stringToPath = memoizeCapped(function(string) {
  14. var result = [];
  15. if (string.charCodeAt(0) === 46 /* . */) {
  16. result.push('');
  17. }
  18. string.replace(rePropName, function(match, number, quote, subString) {
  19. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  20. });
  21. return result;
  22. });
  23. module.exports = stringToPath;