Skip to content

Commit f7beaa4

Browse files
committed
Auto-generated commit
1 parent c32cefa commit f7beaa4

11 files changed

Lines changed: 936 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`a6aa6d9`](https://github.com/stdlib-js/stdlib/commit/a6aa6d97df92d15c0262526367502ebd9d367036) - add `utils/json-pointer/has` [(#16246)](https://github.com/stdlib-js/stdlib/pull/16246)
1314
- [`6514036`](https://github.com/stdlib-js/stdlib/commit/6514036b042522b853e8c77111fc8b7c2eaf42cc) - add `utils/json-pointer/get` [(#16245)](https://github.com/stdlib-js/stdlib/pull/16245)
1415
- [`14e0c0a`](https://github.com/stdlib-js/stdlib/commit/14e0c0a39ad89aa89893c929bb24675fd6047e13) - add `utils/json-pointer/format` [(#15925)](https://github.com/stdlib-js/stdlib/pull/15925)
1516
- [`a5f29ac`](https://github.com/stdlib-js/stdlib/commit/a5f29acf8a9479c642edd3a59a8ba8ca10b77b26) - add `utils/json-pointer/resolve` [(#15854)](https://github.com/stdlib-js/stdlib/pull/15854)
@@ -50,6 +51,7 @@ A total of 10 issues were closed in this release:
5051

5152
<details>
5253

54+
- [`a6aa6d9`](https://github.com/stdlib-js/stdlib/commit/a6aa6d97df92d15c0262526367502ebd9d367036) - **feat:** add `utils/json-pointer/has` [(#16246)](https://github.com/stdlib-js/stdlib/pull/16246) _(by Gururaj Gurram, Athan Reines)_
5355
- [`6514036`](https://github.com/stdlib-js/stdlib/commit/6514036b042522b853e8c77111fc8b7c2eaf42cc) - **feat:** add `utils/json-pointer/get` [(#16245)](https://github.com/stdlib-js/stdlib/pull/16245) _(by Gururaj Gurram, Athan Reines)_
5456
- [`14e0c0a`](https://github.com/stdlib-js/stdlib/commit/14e0c0a39ad89aa89893c929bb24675fd6047e13) - **feat:** add `utils/json-pointer/format` [(#15925)](https://github.com/stdlib-js/stdlib/pull/15925) _(by Gururaj Gurram, Athan Reines)_
5557
- [`a5f29ac`](https://github.com/stdlib-js/stdlib/commit/a5f29acf8a9479c642edd3a59a8ba8ca10b77b26) - **feat:** add `utils/json-pointer/resolve` [(#15854)](https://github.com/stdlib-js/stdlib/pull/15854) _(by Gururaj Gurram, Athan Reines)_

‎json-pointer/has/README.md‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# has
22+
23+
> Test if a [JSON Pointer][json-pointer] ([RFC 6901][rfc-6901]) resolves to a value in a document.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var has = require( '@stdlib/utils/json-pointer/has' );
31+
```
32+
33+
#### has( document, pointer )
34+
35+
Tests if a [JSON Pointer][json-pointer] resolves to a value in a document.
36+
37+
```javascript
38+
var obj = {
39+
'foo': [ 'bar', 'baz' ]
40+
};
41+
var bool = has( obj, '/foo/0' );
42+
// returns true
43+
44+
obj = {
45+
'foo': 'bar'
46+
};
47+
bool = has( obj, '/foo' );
48+
// returns true
49+
50+
bool = has( obj, '/missing' );
51+
// returns false
52+
53+
bool = has( obj, '' );
54+
// returns true
55+
```
56+
57+
</section>
58+
59+
<!-- /.usage -->
60+
61+
<section class="notes">
62+
63+
## Notes
64+
65+
- Per [RFC 6901][rfc-6901], an empty string refers to the root of the document, and the function returns `true` for any valid object or array.
66+
- The `-` token on an array references the position after the last element (i.e., a nonexistent element), and, thus, the function returns `false`.
67+
68+
</section>
69+
70+
<!-- /.notes -->
71+
72+
<section class="examples">
73+
74+
<!-- eslint no-undef: "error" -->
75+
76+
## Examples
77+
78+
```javascript
79+
var has = require( '@stdlib/utils/json-pointer/has' );
80+
81+
var doc = {
82+
'foo': [ 'bar', 'baz' ],
83+
'': 0,
84+
'a/b': 1,
85+
'm~n': 8
86+
};
87+
88+
var bool = has( doc, '/foo' );
89+
// returns true
90+
91+
bool = has( doc, '/foo/0' );
92+
// returns true
93+
94+
bool = has( doc, '/foo/99' );
95+
// returns false
96+
97+
bool = has( doc, '/foo/-' );
98+
// returns false
99+
100+
bool = has( doc, '/' );
101+
// returns true
102+
103+
bool = has( doc, '/a~1b' );
104+
// returns true
105+
106+
bool = has( doc, '/m~0n' );
107+
// returns true
108+
109+
bool = has( doc, '/nonexistent' );
110+
// returns false
111+
112+
bool = has( doc, '' );
113+
// returns true
114+
```
115+
116+
</section>
117+
118+
<!-- /.examples -->
119+
120+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="references">
123+
124+
## References
125+
126+
- [RFC 6901 - JavaScript Object Notation (JSON) Pointer][rfc-6901]
127+
128+
</section>
129+
130+
<!-- /.references -->
131+
132+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
133+
134+
<section class="related">
135+
136+
</section>
137+
138+
<!-- /.related -->
139+
140+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
141+
142+
<section class="links">
143+
144+
[json-pointer]: https://datatracker.ietf.org/doc/html/rfc6901
145+
146+
[rfc-6901]: https://datatracker.ietf.org/doc/html/rfc6901
147+
148+
</section>
149+
150+
<!-- /.links -->
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var format = require( '@stdlib/string/format' );
25+
var pkg = require( './../package.json' ).name;
26+
var has = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( format( '%s::shallow', pkg ), function benchmark( b ) {
32+
var doc;
33+
var out;
34+
var i;
35+
36+
doc = {
37+
'foo': 'bar',
38+
'baz': 'qux'
39+
};
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
out = has( doc, '/foo' );
44+
if ( typeof out !== 'boolean' ) {
45+
b.fail( 'should return a boolean' );
46+
}
47+
}
48+
b.toc();
49+
if ( out !== true ) {
50+
b.fail( 'should return expected value' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
55+
56+
bench( format( '%s::deep', pkg ), function benchmark( b ) {
57+
var doc;
58+
var out;
59+
var i;
60+
61+
doc = {
62+
'a': {
63+
'b': {
64+
'c': {
65+
'd': {
66+
'e': {
67+
'f': 42
68+
}
69+
}
70+
}
71+
}
72+
}
73+
};
74+
75+
b.tic();
76+
for ( i = 0; i < b.iterations; i++ ) {
77+
out = has( doc, '/a/b/c/d/e/f' );
78+
if ( typeof out !== 'boolean' ) {
79+
b.fail( 'should return a boolean' );
80+
}
81+
}
82+
b.toc();
83+
if ( out !== true ) {
84+
b.fail( 'should return expected value' );
85+
}
86+
b.pass( 'benchmark finished' );
87+
b.end();
88+
});
89+
90+
bench( format( '%s::array', pkg ), function benchmark( b ) {
91+
var doc;
92+
var out;
93+
var i;
94+
95+
doc = {
96+
'arr': [
97+
[ 10, 20 ],
98+
[ 30, 40 ]
99+
]
100+
};
101+
102+
b.tic();
103+
for ( i = 0; i < b.iterations; i++ ) {
104+
out = has( doc, '/arr/0/1' );
105+
if ( typeof out !== 'boolean' ) {
106+
b.fail( 'should return a boolean' );
107+
}
108+
}
109+
b.toc();
110+
if ( out !== true ) {
111+
b.fail( 'should return expected value' );
112+
}
113+
b.pass( 'benchmark finished' );
114+
b.end();
115+
});
116+
117+
bench( format( '%s::missing', pkg ), function benchmark( b ) {
118+
var doc;
119+
var out;
120+
var i;
121+
122+
doc = {
123+
'foo': 'bar'
124+
};
125+
126+
b.tic();
127+
for ( i = 0; i < b.iterations; i++ ) {
128+
out = has( doc, '/missing' );
129+
if ( typeof out !== 'boolean' ) {
130+
b.fail( 'should return a boolean' );
131+
}
132+
}
133+
b.toc();
134+
if ( out !== false ) {
135+
b.fail( 'should return expected value' );
136+
}
137+
b.pass( 'benchmark finished' );
138+
b.end();
139+
});
140+
141+
bench( format( '%s::root', pkg ), function benchmark( b ) {
142+
var doc;
143+
var out;
144+
var i;
145+
146+
doc = {
147+
'foo': 'bar'
148+
};
149+
150+
b.tic();
151+
for ( i = 0; i < b.iterations; i++ ) {
152+
out = has( doc, '' );
153+
if ( typeof out !== 'boolean' ) {
154+
b.fail( 'should return a boolean' );
155+
}
156+
}
157+
b.toc();
158+
if ( out !== true ) {
159+
b.fail( 'should return expected value' );
160+
}
161+
b.pass( 'benchmark finished' );
162+
b.end();
163+
});

‎json-pointer/has/docs/repl.txt‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
{{alias}}( document, pointer )
3+
Tests if a JSON Pointer resolves to a value in a document.
4+
5+
Per RFC 6901, an empty string refers to the root of the document, and
6+
the function returns `true` for any valid object or array.
7+
8+
The `-` token on an array references the position after the last element
9+
(i.e., a nonexistent element), and, thus, the function returns `false`.
10+
11+
Parameters
12+
----------
13+
document: Object|Array
14+
JSON document.
15+
16+
pointer: string
17+
JSON Pointer string.
18+
19+
Returns
20+
-------
21+
bool: boolean
22+
Boolean indicating if a pointer resolves.
23+
24+
Examples
25+
--------
26+
> var bool = {{alias}}( { 'foo': [ 'bar', 'baz' ] }, '/foo/0' )
27+
true
28+
> bool = {{alias}}( { 'foo': 'bar' }, '/foo' )
29+
true
30+
> bool = {{alias}}( { 'foo': 'bar' }, '/missing' )
31+
false
32+
> bool = {{alias}}( { 'foo': 'bar' }, '' )
33+
true
34+
35+
See Also
36+
--------
37+

0 commit comments

Comments
 (0)