@ou-imdt/utils
Version:
Utility library for interactive media development
9 lines (8 loc) • 586 B
JavaScript
/**
* a regex for identifying the keys within a property path, captured via the named group 'key'
* additional named groups capture notation before/after key, e.g. ['someProp'] would capture [' and '] (before/after)
* and the final named group 'type' captures any characters bewteen 'key' and 'after', e.g. .someProp[] would capture []
* @todo look at limiting keys to valid identifier characters when unquoted
*/
const propertyPathRegex = /(?<before>\[["']?|\.)?(?<key>[\w-]+)(?<type>(?:(?!(?:\[["']?|\.)\w|(?<=\w)["']?]).)*)?(?<after>["']?])?/;
export default propertyPathRegex;