Skip to content

Modified RFC6901 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add val to the proposal sutie
  • Loading branch information
TotalTechGeek committed Dec 8, 2024
commit 4ec11ff6b35ff0e1132cc08a2ef2b44cc8f47233
14 changes: 14 additions & 0 deletions defaultMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ const defaultMethods = {
}
}
},
// Adding this to spec something out, not to merge it.
val: {
method: (args, context) => {
let result = context
for (let i = 0; i < args.length; i++) {
if (args[i] === null) continue
if (result === null || result === undefined) return null
result = result[args[i]]
}
if (typeof result === 'undefined') return null
return result
},
deterministic: false
},
var: (key, context, above, engine) => {
let b
if (Array.isArray(key)) {
Expand Down
39 changes: 39 additions & 0 deletions suites/val.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
"Test Specification for val",
{
"description": "Fetches a value from an empty key",
"rule": { "val": "" },
"data": { "" : 1 },
"result": 1
},
{
"description": "Fetches a value from a nested empty key",
"rule": { "val": ["", ""] },
"data": { "" : { "": 2 } },
"result": 2
},
{
"description": "Fetches a value from a doubly nested empty key",
"rule": { "val": ["", "", ""] },
"data": { "" : { "": { "": 3 } } },
"result": 3
},
{
"description": "Fetches a value from a key that is purely a dot",
"rule": { "val": "." },
"data": { "." : 20 },
"result": 20
},
{
"description": "Fetches the entire context",
"rule": { "val": null },
"data": { "": 21 },
"result": { "": 21 }
},
{
"description": "Fetches the entire context for a nested key",
"rule": { "val": "" },
"data": { "": { "": 22 } },
"result": { "": 22 }
}
]
Loading