-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
29 additions
and
35 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
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 |
---|---|---|
@@ -1,17 +1,30 @@ | ||
import { listExistingEntries, normalizeEntry } from './entries.js' | ||
import { listEntries, normalizeEntry } from './entries.js' | ||
import { parse } from './parsing/parse.js' | ||
|
||
// Retrieve all properties in `target` matching a query string. | ||
export const list = function (target, queryOrPath) { | ||
const path = parse(queryOrPath) | ||
const entries = listExistingEntries(target, path) | ||
const entries = listExistingEntries(target, queryOrPath) | ||
return entries.map(normalizeEntry) | ||
} | ||
|
||
// Retrieve a single property's value in `target` matching a query string. | ||
// Wildcards can be used, but only the first value is returned. | ||
export const get = function (target, queryOrPath) { | ||
const entries = listExistingEntries(target, queryOrPath) | ||
return entries.length === 0 ? undefined : entries[0].value | ||
} | ||
|
||
// Check if a property is defined according to a query | ||
export const has = function (target, queryOrPath) { | ||
const entries = listExistingEntries(target, queryOrPath) | ||
return entries.length !== 0 | ||
} | ||
|
||
const listExistingEntries = function (target, queryOrPath) { | ||
const path = parse(queryOrPath) | ||
const [entry] = listExistingEntries(target, path) | ||
return entry === undefined ? undefined : entry.value | ||
return listEntries(target, path).filter(isDefined) | ||
} | ||
|
||
const isDefined = function ({ defined }) { | ||
return defined | ||
} |
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
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