Skip to content

Instantly share code, notes, and snippets.

@Fintan
Created November 22, 2018 15:01
Show Gist options
  • Select an option

  • Save Fintan/cf7c1b207036f979e66db0cc2153b998 to your computer and use it in GitHub Desktop.

Select an option

Save Fintan/cf7c1b207036f979e66db0cc2153b998 to your computer and use it in GitHub Desktop.
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