ryardley / pdsl

The expressive declarative toolkit for composing predicates in TypeScript or JavaScript
https://pdsl.site
MIT License
69 stars 2 forks source link

Dot syntax for accessing deeply nested properties. #125

Open ryardley opened 4 years ago

ryardley commented 4 years ago

It could be useful to have a dot syntax for deeply nested objects:

const isAdmin = p`{ user.roles: [? "admin" ] }`

isAdmin({
  user: {
    roles: [ "editor", "admin" ]
  }
}); // true
ryardley commented 4 years ago

With optional properties no need for optional coalescing as the property is explorative.

const isAdmin = p`{ user.roles?: [? "admin" ] }`