-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
521 additions
and
404 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7091,6 +7091,30 @@ THIS SOFTWARE. | |
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
||
This package contains the following license: | ||
|
||
ISC License | ||
|
||
Copyright (c) 2020, Stefan Terdell | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
----------- | ||
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected] | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { jq } from "./jq" | ||
import { describe, test } from "node:test" | ||
import assert from "node:assert/strict" | ||
|
||
describe("jq", () => { | ||
test("returns undefined when input is undefined", () => { | ||
const result = jq(undefined, ".") | ||
assert.strictEqual(result, undefined) | ||
}) | ||
|
||
test("applies JQ transformation to input data", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = ".name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "John") | ||
}) | ||
|
||
test("handles nested objects correctly", () => { | ||
const input = { person: { name: "John", age: 30 } } | ||
const query = ".person.name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "John") | ||
}) | ||
|
||
test("returns null for non-existent keys", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = ".address" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, null) | ||
}) | ||
|
||
test("handles arrays correctly", () => { | ||
const input = { people: [{ name: "John" }, { name: "Jane" }] } | ||
const query = ".people[1].name" | ||
const result = jq(input, query) | ||
assert.strictEqual(result, "Jane") | ||
}) | ||
|
||
test("returns entire input when query is '.'", () => { | ||
const input = { name: "John", age: 30 } | ||
const query = "." | ||
const result = jq(input, query) | ||
assert.deepStrictEqual(result, input) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import _jq from "jqts" | ||
|
||
/** | ||
* Loads and applies JQ transformation to the input data | ||
* @param input | ||
*/ | ||
export function jq(input: any, query: string): any { | ||
if (input === undefined) return input | ||
|
||
const pattern = _jq.compile(query) | ||
const res = pattern.evaluate(input)[0] | ||
return res | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.