TotalTechGeek / json-logic-engine

Construct complex rules with JSON & process them.
MIT License
43 stars 9 forks source link

Add support for dot-prop syntax to resolve #23 #24

Closed TotalTechGeek closed 7 months ago

TotalTechGeek commented 7 months ago

Add Support for Dot-Prop like Syntax

splitPath('a.b.c') // ['a', 'b', 'c']
splitPath('a\\.b.c') // ['a.b', 'c']
splitPath('a\\\\.b.c') // ['a\\', 'b', 'c']
splitPath('a\\\\\\.b.c') // ['a\\.b', 'c']
splitPath('hello') // ['hello']
splitPath('hello\\') // ['hello\\']
splitPath('hello\\\\') // ['hello\\']
const f = engine.build({
  var: "hello\\.world"
})

f({
  "hello.world": 5 
}) // 5

Based on @tatarysh's recommendation, I've added support for escaping in the path to allow you to reference dots.