Skip to content

Commit 940e89d

Browse files
committed
Auto-generated commit
1 parent 416eac7 commit 940e89d

11 files changed

Lines changed: 740 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+
- [`a9780f1`](https://github.com/stdlib-js/stdlib/commit/a9780f1bd8903e6946f3d565d929a26ba4356970) - add `utils/json-pointer/parse` [(#14824)](https://github.com/stdlib-js/stdlib/pull/14824)
1314
- [`2593ea6`](https://github.com/stdlib-js/stdlib/commit/2593ea6b21e1190ee06c710d5cf7a597e2e245c0) - add `utils/json-pointer/base/resolve-token` [(#16326)](https://github.com/stdlib-js/stdlib/pull/16326)
1415
- [`0a22d73`](https://github.com/stdlib-js/stdlib/commit/0a22d737a2f828ebf30c8ea8ba1952d1bed155c7) - add `utils/json-pointer/base/assert/is-safe-token` [(#16320)](https://github.com/stdlib-js/stdlib/pull/16320)
1516

@@ -46,6 +47,7 @@ A total of 10 issues were closed in this release:
4647

4748
<details>
4849

50+
- [`a9780f1`](https://github.com/stdlib-js/stdlib/commit/a9780f1bd8903e6946f3d565d929a26ba4356970) - **feat:** add `utils/json-pointer/parse` [(#14824)](https://github.com/stdlib-js/stdlib/pull/14824) _(by Gururaj Gurram, Athan Reines)_
4951
- [`2593ea6`](https://github.com/stdlib-js/stdlib/commit/2593ea6b21e1190ee06c710d5cf7a597e2e245c0) - **feat:** add `utils/json-pointer/base/resolve-token` [(#16326)](https://github.com/stdlib-js/stdlib/pull/16326) _(by Gururaj Gurram, Athan Reines)_
5052
- [`0a22d73`](https://github.com/stdlib-js/stdlib/commit/0a22d737a2f828ebf30c8ea8ba1952d1bed155c7) - **feat:** add `utils/json-pointer/base/assert/is-safe-token` [(#16320)](https://github.com/stdlib-js/stdlib/pull/16320) _(by Gururaj Gurram, Athan Reines)_
5153
- [`a3ef833`](https://github.com/stdlib-js/stdlib/commit/a3ef8332fc0b02f15802a6edb81df0ede5457fc6) - **fix:** add support for `d`, `s`, `u`, and `v` regexp flags [(#16543)](https://github.com/stdlib-js/stdlib/pull/16543) _(by Rajan Pantha)_

‎json-pointer/parse/README.md‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
# parse
22+
23+
> Parse a [JSON Pointer][json-pointer] ([RFC 6901][rfc-6901]) string into an array of reference tokens.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var parse = require( '@stdlib/utils/json-pointer/parse' );
31+
```
32+
33+
#### parse( pointer )
34+
35+
Parses a [JSON Pointer][json-pointer] string into an array of unescaped reference tokens.
36+
37+
```javascript
38+
var tokens = parse( '/foo/bar' );
39+
// returns [ 'foo', 'bar' ]
40+
41+
tokens = parse( '/a~1b/c~0d' );
42+
// returns [ 'a/b', 'c~d' ]
43+
44+
tokens = parse( '' );
45+
// returns []
46+
```
47+
48+
</section>
49+
50+
<!-- /.usage -->
51+
52+
<section class="notes">
53+
54+
## Notes
55+
56+
- Per [RFC 6901][rfc-6901], an empty string refers to the root of the document, and, thus, the function returns an empty array `[]`.
57+
- Non-empty pointers must begin with a `/` character.
58+
- Escape sequences are decoded. During decoding, `~1` is unescaped to `/` before `~0` is unescaped to `~`.
59+
60+
</section>
61+
62+
<!-- /.notes -->
63+
64+
<section class="examples">
65+
66+
<!-- eslint no-undef: "error" -->
67+
68+
## Examples
69+
70+
```javascript
71+
var parse = require( '@stdlib/utils/json-pointer/parse' );
72+
73+
var tokens = parse( '/foo/bar' );
74+
// returns [ 'foo', 'bar' ]
75+
76+
tokens = parse( '/foo/0' );
77+
// returns [ 'foo', '0' ]
78+
79+
tokens = parse( '/a~1b/c~0d' );
80+
// returns [ 'a/b', 'c~d' ]
81+
82+
tokens = parse( '/~01' );
83+
// returns [ '~1' ]
84+
85+
tokens = parse( '/' );
86+
// returns [ '' ]
87+
88+
tokens = parse( '' );
89+
// returns []
90+
```
91+
92+
</section>
93+
94+
<!-- /.examples -->
95+
96+
<!-- 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. -->
97+
98+
<section class="references">
99+
100+
## References
101+
102+
- [RFC 6901 - JavaScript Object Notation (JSON) Pointer][rfc-6901]
103+
104+
</section>
105+
106+
<!-- /.references -->
107+
108+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
109+
110+
<section class="related">
111+
112+
</section>
113+
114+
<!-- /.related -->
115+
116+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
117+
118+
<section class="links">
119+
120+
[json-pointer]: https://datatracker.ietf.org/doc/html/rfc6901
121+
122+
[rfc-6901]: https://datatracker.ietf.org/doc/html/rfc6901
123+
124+
</section>
125+
126+
<!-- /.links -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 parse = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( format( '%s::shallow', pkg ), function benchmark( b ) {
32+
var out;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
out = parse( '/foo/bar' );
38+
if ( typeof out !== 'object' ) {
39+
b.fail( 'should return an array' );
40+
}
41+
}
42+
b.toc();
43+
if ( out.length !== 2 ) {
44+
b.fail( 'should return expected tokens' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
49+
50+
bench( format( '%s::escaped', pkg), function benchmark( b ) {
51+
var out;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
out = parse( '/a~1b/c~0d/foo/0' );
57+
if ( typeof out !== 'object' ) {
58+
b.fail( 'should return an array' );
59+
}
60+
}
61+
b.toc();
62+
if ( out.length !== 4 ) {
63+
b.fail( 'should return expected tokens' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
});
68+
69+
bench( format( '%s::deep', pkg ), function benchmark( b ) {
70+
var out;
71+
var i;
72+
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
out = parse( '/a/b/c/d/e/f/g/h' );
76+
if ( typeof out !== 'object' ) {
77+
b.fail( 'should return an array' );
78+
}
79+
}
80+
b.toc();
81+
if ( out.length !== 8 ) {
82+
b.fail( 'should return expected tokens' );
83+
}
84+
b.pass( 'benchmark finished' );
85+
b.end();
86+
});
87+
88+
bench( format( '%s::root', pkg ), function benchmark( b ) {
89+
var out;
90+
var i;
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
out = parse( '' );
95+
if ( typeof out !== 'object' ) {
96+
b.fail( 'should return an array' );
97+
}
98+
}
99+
b.toc();
100+
if ( out.length !== 0 ) {
101+
b.fail( 'should return empty array' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
});

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( pointer )
3+
Parses a JSON Pointer string into an array of reference tokens.
4+
5+
Per RFC 6901, an empty string refers to the root, and, thus, the function
6+
returns an empty array. Non-empty pointers must begin with a '/' character.
7+
8+
Escape sequences are decoded:. During decoding, `~1` is unescaped to `/`
9+
before `~0` is unescaped to `~`.
10+
11+
Parameters
12+
----------
13+
pointer: string
14+
JSON Pointer string.
15+
16+
Returns
17+
-------
18+
tokens: Array<string>
19+
Array of reference tokens.
20+
21+
Examples
22+
--------
23+
> var tokens = {{alias}}( '/foo/bar' )
24+
[ 'foo', 'bar' ]
25+
> tokens = {{alias}}( '/a~1b/c~0d' )
26+
[ 'a/b', 'c~d' ]
27+
> tokens = {{alias}}( '' )
28+
[]
29+
30+
See Also
31+
--------
32+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Parses a JSON Pointer string into an array of reference tokens.
23+
*
24+
* ## Notes
25+
*
26+
* - Implements parsing per RFC 6901.
27+
* - An empty string returns an empty array (i.e., refers to the root of the document).
28+
* - Escape sequences are decoded. During decoding, `~1` is unescaped to `/` before `~0` is unescaped to `~`.
29+
*
30+
* @param pointer - JSON Pointer string
31+
* @throws input argument must be either empty or start with a `/` character
32+
* @returns array of reference tokens
33+
*
34+
* @example
35+
* var tokens = parse( '/foo/bar' );
36+
* // returns [ 'foo', 'bar' ]
37+
*
38+
* @example
39+
* var tokens = parse( '/a~1b/c~0d' );
40+
* // returns [ 'a/b', 'c~d' ]
41+
*
42+
* @example
43+
* var tokens = parse( '' );
44+
* // returns []
45+
*/
46+
declare function parse( pointer: string ): Array<string>;
47+
48+
49+
// EXPORTS //
50+
51+
export = parse;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
import parse = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an array of strings...
25+
{
26+
parse( '/foo/bar' ); // $ExpectType string[]
27+
parse( '' ); // $ExpectType string[]
28+
}
29+
30+
// The compiler throws an error if the function is provided an argument which is not a string...
31+
{
32+
parse( 123 ); // $ExpectError
33+
parse( true ); // $ExpectError
34+
parse( false ); // $ExpectError
35+
parse( null ); // $ExpectError
36+
parse( undefined ); // $ExpectError
37+
parse( [] ); // $ExpectError
38+
parse( {} ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
parse(); // $ExpectError
44+
parse( '/foo', 2 ); // $ExpectError
45+
}

0 commit comments

Comments
 (0)