Created
November 22, 2018 15:01
-
-
Save Fintan/cf7c1b207036f979e66db0cc2153b998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pathTypes = { | |
| SIMPLE: 'ends_with_simple_attribute', | |
| ARRAY: 'ends_with_array', | |
| ARRAY_ITEM: 'ends_with_array_item', | |
| ATTR_ON_ARRAY_ITEM: 'ends_with_attribute_on_array_item' | |
| }; | |
| function getPathType(path) { | |
| let type; | |
| if(/[[0-9]].[\w]*$/.test(path)) { | |
| type = pathTypes.ATTR_ON_ARRAY_ITEM; | |
| }else if(/[[]]$/.test(path) || /[[*]]$/.test(path)) { | |
| type = pathTypes.ARRAY; | |
| }else if(/[[0-9]]$/.test(path)) { | |
| type = pathTypes.ARRAY_ITEM; | |
| }else if(/(?<!])\.[\w]*$/.test(path)) { | |
| type = pathTypes.SIMPLE; | |
| } | |
| return type; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment