From d6ee388e547851751161f78e2589d1d99edf5618 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sat, 22 Feb 2025 22:11:20 +0530 Subject: [PATCH 01/17] feat: initial commit --- .../@stdlib/utils/jsonify-keys/README.md | 157 ++++++++++++++++++ .../utils/jsonify-keys/examples/index.js | 41 +++++ .../@stdlib/utils/jsonify-keys/lib/index.js | 40 +++++ .../@stdlib/utils/jsonify-keys/lib/main.js | 67 ++++++++ .../@stdlib/utils/jsonify-keys/package.json | 60 +++++++ 5 files changed, 365 insertions(+) create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/README.md create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/package.json diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md new file mode 100644 index 000000000000..bc01580d8561 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -0,0 +1,157 @@ + + +# JSONify keys + +> parse [JSON][json]-like strings into valid JavaScript objects. + +
+ +## Usage + +```javascript +var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); +``` + +#### jsonifyKeys( str\[, reviver] ) + +Parses a `string` as [JSON][json]. + +```javascript +var out = parseJSON( '{"beep":"boop"}' ); +// returns {'beep':'boop'} +``` + +If unable to parse a `string` as [JSON][json], the function returns an error. + +```javascript +var out = parseJSON( 'beep' ); +// returns +``` + +To transform the `string` being parsed, provide a `reviver`. + +```javascript +function reviver( key, value ) { + if ( key === '' ) { + return value; + } + if ( key === 'beep' ) { + return value; + } +} + +var str = '{"beep":"boop","a":"b"}'; +var out = parseJSON( str, reviver ); +// returns {'beep':'boop'} +``` + +
+ + + +
+ +## Notes + +- In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided **any** value which is not a `string`. + + ```javascript + var out = JSON.parse( null ); + // returns null + + out = parseJSON( null ); + // throws + ``` + +- In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a `SyntaxError` if unable to parse a `string` as [JSON][json]. + + ```javascript + var out = parseJSON( '{"beep":"boop}' ); + // returns + + out = JSON.parse( '{"beep":"boop}' ); + // throws + ``` + +- In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided a `reviver` argument which is **not** a `function`. + + ```javascript + var out = JSON.parse( '{"a":"b"}', [] ); + // returns {'a':'b'} + + out = parseJSON( '{"a":"b"}', [] ); + // throws + ``` + +
+ + + +
+ +## Examples + + + +```javascript +var parseJSON = require( '@stdlib/utils/parse-json' ); + +var out; + +out = parseJSON( '{"beep":"boop"}' ); +// returns {'beep':'boop'} + +out = parseJSON( '3.14' ); +// returns 3.14 + +out = parseJSON( 'true' ); +// returns true + +out = parseJSON( 'null' ); +// returns null + +out = parseJSON( '{"beep":"boop}' ); +// returns +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js new file mode 100644 index 000000000000..23f19038bca0 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var jsonifyKeys = require( './../lib' ); + +var out = jsonifyKeys( '{beep:"boop"}' ); +console.log( out ); +// => {'beep':'boop'} + +out = jsonifyKeys( '3.14' ); +console.log( out ); +// => 3.14 + +out = jsonifyKeys( 'true' ); +console.log( out ); +// => true + +out = jsonifyKeys( 'null' ); +console.log( out ); +// => null + +out = jsonifyKeys( '{beep:"boop}' ); +console.log( out instanceof Error ); +// => true diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js new file mode 100644 index 000000000000..9d042bf478da --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Parse JSON-like strings into valid JavaScript objects. +* +* @module @stdlib/utils/jsonify-keys +* +* @example +* var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); +* +* var obj = jsonifyKeys( '{ beep: "boop" }' ); +* // returns {'beep':'boop'} +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js new file mode 100644 index 000000000000..b35ad92a3042 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2015 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Attempts to parse a string as JSON. +* +* @param {string} str - string to parse +* @param {Function} [reviver] - transformation function +* @throws {TypeError} first argument must be a string +* @throws {TypeError} reviver must be a function +* @returns {(*|Error)} parsed value or parse error +* +* @example +* var obj = jsonifyKeys( '{beep:"boop"}' ); +* // returns {'beep':'boop'} +*/ +function jsonifyKeys( str, reviver ) { + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + if ( arguments.length > 1 ) { + if ( !isFunction( reviver ) ) { + throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', reviver ) ); + } + } + try { + const withOperators = str.replace( /(\s*?{\s*?|\s*?,\s*?)(\$[a-zA-Z0-9_]+):/g, '$1"$2":' ); + + // handle all keys + const jsonStringified = withOperators.replace( /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); + + return JSON.parse( jsonStringified, reviver ); + } catch ( error ) { + return error; + } +} + + +// EXPORTS // + +module.exports = jsonifyKeys; diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json new file mode 100644 index 000000000000..fd320d96cb42 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json @@ -0,0 +1,60 @@ +{ + "name": "@stdlib/utils/jsonify-keys", + "version": "0.0.0", + "description": "A utility to parse JSON-like strings into valid JavaScript objects, simplifying the handling of loosely formatted data.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "json", + "string", + "parser", + "stringify", + "jsonify", + "string2json" + ] + } + \ No newline at end of file From f8cdc01c35379bd762ca91ef14ca035d1c2f0433 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 19:49:03 +0530 Subject: [PATCH 02/17] feat: add utils/jsonify-keys --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/utils/jsonify-keys/README.md | 26 +-- .../utils/jsonify-keys/benchmark/benchmark.js | 50 +++++ .../@stdlib/utils/jsonify-keys/docs/repl.txt | 33 ++++ .../utils/jsonify-keys/docs/types/index.d.ts | 37 ++++ .../utils/jsonify-keys/docs/types/test.ts | 55 ++++++ .../@stdlib/utils/jsonify-keys/lib/main.js | 18 +- .../@stdlib/utils/jsonify-keys/test/test.js | 171 ++++++++++++++++++ 7 files changed, 372 insertions(+), 18 deletions(-) create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index bc01580d8561..0f8025216e68 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -35,14 +35,14 @@ var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); Parses a `string` as [JSON][json]. ```javascript -var out = parseJSON( '{"beep":"boop"}' ); +var out = jsonifyKeys( '{"beep":"boop"}' ); // returns {'beep':'boop'} ``` If unable to parse a `string` as [JSON][json], the function returns an error. ```javascript -var out = parseJSON( 'beep' ); +var out = jsonifyKeys( 'beep' ); // returns ``` @@ -58,8 +58,8 @@ function reviver( key, value ) { } } -var str = '{"beep":"boop","a":"b"}'; -var out = parseJSON( str, reviver ); +var str = '{ beep: "boop", a: "b"}'; +var out = jsonifyKeys( str, reviver ); // returns {'beep':'boop'} ``` @@ -77,14 +77,14 @@ var out = parseJSON( str, reviver ); var out = JSON.parse( null ); // returns null - out = parseJSON( null ); + out = jsonifyKeys( null ); // throws ``` - In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a `SyntaxError` if unable to parse a `string` as [JSON][json]. ```javascript - var out = parseJSON( '{"beep":"boop}' ); + var out = jsonifyKeys( '{"beep":"boop}' ); // returns out = JSON.parse( '{"beep":"boop}' ); @@ -97,7 +97,7 @@ var out = parseJSON( str, reviver ); var out = JSON.parse( '{"a":"b"}', [] ); // returns {'a':'b'} - out = parseJSON( '{"a":"b"}', [] ); + out = jsonifyKeys( '{"a":"b"}', [] ); // throws ``` @@ -112,23 +112,23 @@ var out = parseJSON( str, reviver ); ```javascript -var parseJSON = require( '@stdlib/utils/parse-json' ); +var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); var out; -out = parseJSON( '{"beep":"boop"}' ); +out = jsonifyKeys( '{ beep: "boop"}' ); // returns {'beep':'boop'} -out = parseJSON( '3.14' ); +out = jsonifyKeys( '3.14' ); // returns 3.14 -out = parseJSON( 'true' ); +out = jsonifyKeys( 'true' ); // returns true -out = parseJSON( 'null' ); +out = jsonifyKeys( 'null' ); // returns null -out = parseJSON( '{"beep":"boop}' ); +out = jsonifyKeys( '{"beep":"boop}' ); // returns ``` diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js new file mode 100644 index 000000000000..283ea3e9d752 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var pkg = require( './../package.json' ).name; +var jsonifyKeys = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var str; + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + str = '{ beep: "boop",'+fromCodePoint( 97 + (i%26) ) + ':true}'; + out = jsonifyKeys( str ); + if ( out instanceof Error ) { + b.fail( out.message ); + } + } + b.toc(); + if ( out instanceof Error ) { + b.fail( 'should return JSON' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt new file mode 100644 index 000000000000..49e0d60798ee --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( str[, reviver] ) + Attempts to parse a JSON-like string into a valid JavaScript object. + + Parameters + ---------- + str: string + String to parse. + + reviver: Function (optional) + Transformation function. + + Returns + ------- + out: any|Error + Parsed value or an error. + + Examples + -------- + > var obj = {{alias}}( '{ beep: "boop"}' ) + { 'beep': 'boop' } + + // Provide a reviver: + > function reviver( key, value ) { + ... if ( key === '' ) { return value; } + ... if ( key === 'beep' ) { return value; } + ... }; + > var str = '{ beep: "boop", a: "b" }'; + > var out = {{alias}}( str, reviver ) + { 'beep': 'boop' } + + See Also + -------- diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts new file mode 100644 index 000000000000..63b0daf2f947 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts @@ -0,0 +1,37 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Attempts to parse a JSON-like string into a valid JavaScript object +* +* @param str - string to parse +* @param reviver - transformation function +* @returns parsed value or parse error +* +* @example +* var obj = jsonifyKeys( '{ beep: "boop" }' ); +* // returns {'beep':'boop'} +*/ +declare function jsonifyKeys( str: string, reviver?: Function ): any; + + +// EXPORTS // + +export = jsonifyKeys; diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts new file mode 100644 index 000000000000..50e2dce6e978 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts @@ -0,0 +1,55 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import jsonifyKeys = require( './index' ); + + +// TESTS // + +// The function returns a parsed value... +{ + jsonifyKeys( '{beep:"boop"}' ); // $ExpectType any + jsonifyKeys( '"beep"' ); // $ExpectType any + jsonifyKeys( '22' ); // $ExpectType any +} + +// The function does not compile if the first argument is a value other than a string... +{ + jsonifyKeys( true ); // $ExpectError + jsonifyKeys( false ); // $ExpectError + jsonifyKeys( 5 ); // $ExpectError + jsonifyKeys( [] ); // $ExpectError + jsonifyKeys( {} ); // $ExpectError + jsonifyKeys( ( x: number ): number => x ); // $ExpectError +} + +// The function does not compile if the second argument is a value other than a function... +{ + jsonifyKeys( '{beep:"boop"}', true ); // $ExpectError + jsonifyKeys( '{beep:"boop"}', false ); // $ExpectError + jsonifyKeys( '{beep:"boop"}', 5 ); // $ExpectError + jsonifyKeys( '{beep:"boop"}', [] ); // $ExpectError + jsonifyKeys( '{beep:"boop"}', {} ); // $ExpectError + jsonifyKeys( '{beep:"boop"}', 'baz' ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + jsonifyKeys(); // $ExpectError + jsonifyKeys( '{beep:"boop"}', 'baz', 'boz' ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index b35ad92a3042..3e2f22a05d98 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -41,6 +41,9 @@ var format = require( '@stdlib/string/format' ); * // returns {'beep':'boop'} */ function jsonifyKeys( str, reviver ) { + var jsonStringified; + var withOperators; + if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } @@ -50,11 +53,16 @@ function jsonifyKeys( str, reviver ) { } } try { - const withOperators = str.replace( /(\s*?{\s*?|\s*?,\s*?)(\$[a-zA-Z0-9_]+):/g, '$1"$2":' ); - - // handle all keys - const jsonStringified = withOperators.replace( /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); - + // handle keys prefixed with a `$` - useful for some cases like mongodb aggregator pipelines + + // matches the keys by selecting either a '{' or a ',' and adds quotes to it + withOperators = str.replace( /(\s*?{\s*?|\s*?,\s*?)(\$[a-zA-Z0-9_]+):/g, '$1"$2":' ); + + // handle all generic keys + + // Matches the keys by selecting either a '{' or a ',' and adds quotes to it + jsonStringified = withOperators.replace( /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); + return JSON.parse( jsonStringified, reviver ); } catch ( error ) { return error; diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js new file mode 100644 index 000000000000..7aa577f5817a --- /dev/null +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -0,0 +1,171 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var jsonifyKeys = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof jsonifyKeys, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws if not provided a string', function test( t ) { + var values; + var i; + + values = [ + 3.14, + NaN, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + jsonifyKeys( value ); + }; + } +}); + +tape( 'the function throws if not provided a string (reviver)', function test( t ) { + var values; + var i; + + values = [ + 3.14, + NaN, + true, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + jsonifyKeys( value, noop ); + }; + } +}); + +tape( 'the function throws if provided a reviver argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + null, + void 0, + [], + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + jsonifyKeys( '{"a":"b"}', value ); + }; + } +}); + +tape( 'the function returns a JSON value if provided valid JSON', function test( t ) { + var expected; + var actual; + + expected = { + 'beep': 'boop' + }; + actual = jsonifyKeys( '{beep:"boop"}' ); + t.deepEqual( actual, expected, 'deep equal' ); + + expected = null; + actual = jsonifyKeys( 'null' ); + t.equal( actual, expected, 'returns null' ); + + expected = true; + actual = jsonifyKeys( 'true' ); + t.equal( actual, expected, 'returns true' ); + + expected = 3.14; + actual = jsonifyKeys( '3.14' ); + t.equal( actual, expected, 'returns 3.14' ); + + t.end(); +}); + +tape( 'the function returns an error if provided invalid JSON', function test( t ) { + var out = jsonifyKeys( '{beep:"boop}' ); + t.equal( out instanceof Error, true, 'returns an error' ); + t.end(); +}); + +tape( 'the function supports providing a custom reviver function', function test( t ) { + var expected; + var actual; + var str; + + str = '{ beep: "boop", a: "b" }'; + expected = { + 'beep': 'boop' + }; + actual = jsonifyKeys( str, reviver ); + + t.deepEqual( actual, expected, 'supports custom reviver' ); + + t.end(); + + function reviver( key, value ) { + if ( key === '' ) { + return value; + } + if ( key === 'beep' ) { + return value; + } + } +}); From 078c58e6261f54077e4bcdaf8226d4721147e9e0 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 19:51:22 +0530 Subject: [PATCH 03/17] docs: update comments for better readablity --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index 3e2f22a05d98..95a7c1bd4856 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -53,14 +53,14 @@ function jsonifyKeys( str, reviver ) { } } try { - // handle keys prefixed with a `$` - useful for some cases like mongodb aggregator pipelines + // Handle keys prefixed with a `$` - useful for some cases like mongodb aggregator pipelines - // matches the keys by selecting either a '{' or a ',' and adds quotes to it + // Hatches the keys by selecting the word next to a '{' or a ',' and adds quotes to it withOperators = str.replace( /(\s*?{\s*?|\s*?,\s*?)(\$[a-zA-Z0-9_]+):/g, '$1"$2":' ); - // handle all generic keys + // Handle all generic keys - // Matches the keys by selecting either a '{' or a ',' and adds quotes to it + // Matches the keys by selecting the word next to a '{' or a ',' and adds quotes to it jsonStringified = withOperators.replace( /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); return JSON.parse( jsonStringified, reviver ); From 0b8327daea2c8df67495668cbfd351950942ae69 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 19:51:22 +0530 Subject: [PATCH 04/17] docs: update comments for better readablity --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/README.md | 10 +++++----- .../@stdlib/utils/jsonify-keys/docs/repl.txt | 8 ++++++++ .../@stdlib/utils/jsonify-keys/package.json | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index 0f8025216e68..c4fa99fbe8a7 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -20,7 +20,7 @@ limitations under the License. # JSONify keys -> parse [JSON][json]-like strings into valid JavaScript objects. +> Parse a [JSON][json]-like string as [JSON][json].
@@ -32,7 +32,7 @@ var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); #### jsonifyKeys( str\[, reviver] ) -Parses a `string` as [JSON][json]. +Parses a [JSON][json]-like string as a [JSON][json] ```javascript var out = jsonifyKeys( '{"beep":"boop"}' ); @@ -84,10 +84,10 @@ var out = jsonifyKeys( str, reviver ); - In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a `SyntaxError` if unable to parse a `string` as [JSON][json]. ```javascript - var out = jsonifyKeys( '{"beep":"boop}' ); + var out = jsonifyKeys( '{ beep: "boop}' ); // returns - out = JSON.parse( '{"beep":"boop}' ); + out = JSON.parse( '{ "beep": "boop}' ); // throws ``` @@ -97,7 +97,7 @@ var out = jsonifyKeys( str, reviver ); var out = JSON.parse( '{"a":"b"}', [] ); // returns {'a':'b'} - out = jsonifyKeys( '{"a":"b"}', [] ); + out = jsonifyKeys( '{ a: "b"}', [] ); // throws ``` diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt index 49e0d60798ee..393c6c028cac 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -2,6 +2,14 @@ {{alias}}( str[, reviver] ) Attempts to parse a JSON-like string into a valid JavaScript object. + Function behavior differs from `JSON.parse()` as follows: + + - throws a `TypeError` if provided any value which is not a string. + - throws a `TypeError` if provided a `reviver` argument which is not a + function. + - returns, rather than throws, a `SyntaxError` if unable to parse a string + as JSON. + Parameters ---------- str: string diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json index fd320d96cb42..b49f994e12af 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/utils/jsonify-keys", "version": "0.0.0", - "description": "A utility to parse JSON-like strings into valid JavaScript objects, simplifying the handling of loosely formatted data.", + "description": "Parses a JSON-like string as JSON.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 0d99797fe46c5ffacb67e178436f9fa59d66b92c Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:34:48 +0000 Subject: [PATCH 05/17] chore: update copyright years --- lib/node_modules/@stdlib/utils/jsonify-keys/README.md | 2 +- .../@stdlib/utils/jsonify-keys/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index c4fa99fbe8a7..bdcfca771d2c 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2025 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js index 283ea3e9d752..74d97c86bace 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts index 50e2dce6e978..bd41f76bee39 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js index 23f19038bca0..305b29d3418d 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index 95a7c1bd4856..be24e81c9a2e 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2015 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index 7aa577f5817a..8cb67a863f29 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 15040d8ed76ce0004da7fa04f593a59d27ef7a4a Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 21:16:17 +0530 Subject: [PATCH 06/17] chore: fix linting error --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json index b49f994e12af..0619c2400441 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json @@ -57,4 +57,3 @@ "string2json" ] } - \ No newline at end of file From f9878458d182fd2e95cc44b885e2cca6b5c1c40b Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:03:55 +0000 Subject: [PATCH 07/17] chore: fix linting errors --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/utils/jsonify-keys/docs/repl.txt | 4 +- .../utils/jsonify-keys/examples/index.js | 2 +- .../@stdlib/utils/jsonify-keys/package.json | 121 ++++++++++-------- 3 files changed, 68 insertions(+), 59 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt index 393c6c028cac..e1a7ec688343 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -6,9 +6,9 @@ - throws a `TypeError` if provided any value which is not a string. - throws a `TypeError` if provided a `reviver` argument which is not a - function. + function. - returns, rather than throws, a `SyntaxError` if unable to parse a string - as JSON. + as JSON. Parameters ---------- diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js index 305b29d3418d..1dd906d25432 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -36,6 +36,6 @@ out = jsonifyKeys( 'null' ); console.log( out ); // => null -out = jsonifyKeys( '{beep:"boop}' ); +out = jsonifyKeys( '{ beep: "boop }' ); console.log( out instanceof Error ); // => true diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json index 0619c2400441..3aef30f7ad91 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json @@ -1,59 +1,68 @@ { - "name": "@stdlib/utils/jsonify-keys", - "version": "0.0.0", - "description": "Parses a JSON-like string as JSON.", - "license": "Apache-2.0", - "author": { + "name": "@stdlib/utils/jsonify-keys", + "version": "0.0.0", + "description": "Parse a JSON-like string as JSON.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { "name": "The Stdlib Authors", "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "json", - "string", - "parser", - "stringify", - "jsonify", - "string2json" - ] - } + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "json", + "parse", + "try", + "trap", + "catch", + "json.parse", + "string", + "str" + ] +} From a3a07b317953f531acf592d6380f9671b48f0606 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:14:04 +0000 Subject: [PATCH 08/17] docs: use more consistent docs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/README.md | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt | 2 +- .../@stdlib/utils/jsonify-keys/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index bdcfca771d2c..529cb3e8c1b2 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -32,7 +32,7 @@ var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); #### jsonifyKeys( str\[, reviver] ) -Parses a [JSON][json]-like string as a [JSON][json] +Parses a [JSON][json]-like `string` as [JSON][json]. ```javascript var out = jsonifyKeys( '{"beep":"boop"}' ); diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt index e1a7ec688343..5fbea1e2d4f4 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( str[, reviver] ) - Attempts to parse a JSON-like string into a valid JavaScript object. + Attempts to parse a JSON-like string as JSON. Function behavior differs from `JSON.parse()` as follows: diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts index 63b0daf2f947..7f82194855ff 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Attempts to parse a JSON-like string into a valid JavaScript object +* Attempts to parse a JSON-like string as JSON. * * @param str - string to parse * @param reviver - transformation function diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js index 9d042bf478da..6e81fcdf0fb3 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Parse JSON-like strings into valid JavaScript objects. +* Parse a JSON-like string as JSON.. * * @module @stdlib/utils/jsonify-keys * diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index be24e81c9a2e..164c26aba78f 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -28,7 +28,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Attempts to parse a string as JSON. +* Attempts to parse a JSON-like string as JSON. * * @param {string} str - string to parse * @param {Function} [reviver] - transformation function From fec7f5de4589611d22d0255454262e373e25f8ef Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:23:21 +0000 Subject: [PATCH 09/17] chore: use consistent spacing --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../@stdlib/utils/jsonify-keys/docs/repl.txt | 2 +- .../utils/jsonify-keys/docs/types/test.ts | 16 ++++++++-------- .../@stdlib/utils/jsonify-keys/examples/index.js | 2 +- .../@stdlib/utils/jsonify-keys/lib/main.js | 2 +- .../@stdlib/utils/jsonify-keys/test/test.js | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt index 5fbea1e2d4f4..01887ff63acb 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -25,7 +25,7 @@ Examples -------- - > var obj = {{alias}}( '{ beep: "boop"}' ) + > var obj = {{alias}}( '{ beep: "boop" }' ) { 'beep': 'boop' } // Provide a reviver: diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts index bd41f76bee39..44cb8d00365d 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts @@ -23,7 +23,7 @@ import jsonifyKeys = require( './index' ); // The function returns a parsed value... { - jsonifyKeys( '{beep:"boop"}' ); // $ExpectType any + jsonifyKeys( '{ beep: "boop" }' ); // $ExpectType any jsonifyKeys( '"beep"' ); // $ExpectType any jsonifyKeys( '22' ); // $ExpectType any } @@ -40,16 +40,16 @@ import jsonifyKeys = require( './index' ); // The function does not compile if the second argument is a value other than a function... { - jsonifyKeys( '{beep:"boop"}', true ); // $ExpectError - jsonifyKeys( '{beep:"boop"}', false ); // $ExpectError - jsonifyKeys( '{beep:"boop"}', 5 ); // $ExpectError - jsonifyKeys( '{beep:"boop"}', [] ); // $ExpectError - jsonifyKeys( '{beep:"boop"}', {} ); // $ExpectError - jsonifyKeys( '{beep:"boop"}', 'baz' ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', true ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', false ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', 5 ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', [] ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', {} ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', 'baz' ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { jsonifyKeys(); // $ExpectError - jsonifyKeys( '{beep:"boop"}', 'baz', 'boz' ); // $ExpectError + jsonifyKeys( '{ beep: "boop" }', 'baz', 'boz' ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js index 1dd906d25432..2af9cc0a84e3 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -20,7 +20,7 @@ var jsonifyKeys = require( './../lib' ); -var out = jsonifyKeys( '{beep:"boop"}' ); +var out = jsonifyKeys( '{ beep: "boop" }' ); console.log( out ); // => {'beep':'boop'} diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index 164c26aba78f..702cf445cf25 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -37,7 +37,7 @@ var format = require( '@stdlib/string/format' ); * @returns {(*|Error)} parsed value or parse error * * @example -* var obj = jsonifyKeys( '{beep:"boop"}' ); +* var obj = jsonifyKeys( '{ beep: "boop" }' ); * // returns {'beep':'boop'} */ function jsonifyKeys( str, reviver ) { diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index 8cb67a863f29..99bb7d849d46 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -121,7 +121,7 @@ tape( 'the function returns a JSON value if provided valid JSON', function test( expected = { 'beep': 'boop' }; - actual = jsonifyKeys( '{beep:"boop"}' ); + actual = jsonifyKeys( '{ beep: "boop" }' ); t.deepEqual( actual, expected, 'deep equal' ); expected = null; From 5fc54255c85efd792364ad25f6998c98e826dcfc Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:25:32 +0000 Subject: [PATCH 10/17] chore: use consistent spacing --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index 99bb7d849d46..4df1fbb9b432 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -140,7 +140,7 @@ tape( 'the function returns a JSON value if provided valid JSON', function test( }); tape( 'the function returns an error if provided invalid JSON', function test( t ) { - var out = jsonifyKeys( '{beep:"boop}' ); + var out = jsonifyKeys( '{ beep: "boop }' ); t.equal( out instanceof Error, true, 'returns an error' ); t.end(); }); From 3cf60f0e1e1997864f21efd9636fa52e5f8a8034 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:32:51 +0000 Subject: [PATCH 11/17] chore: use consistent spacing --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index 529cb3e8c1b2..4a13162a49de 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -35,7 +35,7 @@ var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); Parses a [JSON][json]-like `string` as [JSON][json]. ```javascript -var out = jsonifyKeys( '{"beep":"boop"}' ); +var out = jsonifyKeys( '{ beep: "boop" }' ); // returns {'beep':'boop'} ``` @@ -58,7 +58,7 @@ function reviver( key, value ) { } } -var str = '{ beep: "boop", a: "b"}'; +var str = '{ beep: "boop", a: "b" }'; var out = jsonifyKeys( str, reviver ); // returns {'beep':'boop'} ``` @@ -97,7 +97,7 @@ var out = jsonifyKeys( str, reviver ); var out = JSON.parse( '{"a":"b"}', [] ); // returns {'a':'b'} - out = jsonifyKeys( '{ a: "b"}', [] ); + out = jsonifyKeys( '{ a: "b" }', [] ); // throws ``` @@ -116,7 +116,7 @@ var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); var out; -out = jsonifyKeys( '{ beep: "boop"}' ); +out = jsonifyKeys( '{ beep: "boop" }' ); // returns {'beep':'boop'} out = jsonifyKeys( '3.14' ); @@ -128,7 +128,7 @@ out = jsonifyKeys( 'true' ); out = jsonifyKeys( 'null' ); // returns null -out = jsonifyKeys( '{"beep":"boop}' ); +out = jsonifyKeys( '{ beep: "boop }' ); // returns ``` From e0d11bd74ace8b228d22c24680673ae8f7026876 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 24 Feb 2025 16:39:07 +0000 Subject: [PATCH 12/17] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../@stdlib/utils/jsonify-keys/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js index 74d97c86bace..ff4cb212138d 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js @@ -35,7 +35,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - str = '{ beep: "boop",'+fromCodePoint( 97 + (i%26) ) + ':true}'; + str = '{ beep: "boop",'+fromCodePoint( 97 + (i%26) ) + ':true }'; out = jsonifyKeys( str ); if ( out instanceof Error ) { b.fail( out.message ); diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index 4df1fbb9b432..3569c1d3b577 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -109,7 +109,7 @@ tape( 'the function throws if provided a reviver argument which is not a functio function badValue( value ) { return function badValue() { - jsonifyKeys( '{"a":"b"}', value ); + jsonifyKeys( '{ a: "b" }', value ); }; } }); From 05ffd693aee30831b1ab0dab4f0d7d13a53df9f6 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 25 Feb 2025 03:10:22 +0000 Subject: [PATCH 13/17] fix: use isError instead of instanceof due to realms --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js index 2af9cc0a84e3..92bee9537c48 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -18,6 +18,7 @@ 'use strict'; +var isError = require( '@stdlib/assert/is-error' ); var jsonifyKeys = require( './../lib' ); var out = jsonifyKeys( '{ beep: "boop" }' ); @@ -37,5 +38,5 @@ console.log( out ); // => null out = jsonifyKeys( '{ beep: "boop }' ); -console.log( out instanceof Error ); +console.log( isError( out ) ); // => true From 30987ef6774b748fd92682b703a567ebcc8bc15d Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 25 Feb 2025 11:46:28 +0530 Subject: [PATCH 14/17] refactor: return a normalized string instead of a parsed JSON --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/utils/jsonify-keys/lib/main.js | 21 +---- .../@stdlib/utils/jsonify-keys/test/test.js | 86 +------------------ 2 files changed, 5 insertions(+), 102 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index 702cf445cf25..fe38594c4541 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -21,6 +21,7 @@ // MODULES // var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var replace = require( '@stdlib/string/replace' ); var isFunction = require( '@stdlib/assert/is-function' ); var format = require( '@stdlib/string/format' ); @@ -38,12 +39,9 @@ var format = require( '@stdlib/string/format' ); * * @example * var obj = jsonifyKeys( '{ beep: "boop" }' ); -* // returns {'beep':'boop'} +* // returns '{ "beep": "boop" }' */ function jsonifyKeys( str, reviver ) { - var jsonStringified; - var withOperators; - if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } @@ -52,21 +50,8 @@ function jsonifyKeys( str, reviver ) { throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', reviver ) ); } } - try { - // Handle keys prefixed with a `$` - useful for some cases like mongodb aggregator pipelines - - // Hatches the keys by selecting the word next to a '{' or a ',' and adds quotes to it - withOperators = str.replace( /(\s*?{\s*?|\s*?,\s*?)(\$[a-zA-Z0-9_]+):/g, '$1"$2":' ); - - // Handle all generic keys - // Matches the keys by selecting the word next to a '{' or a ',' and adds quotes to it - jsonStringified = withOperators.replace( /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); - - return JSON.parse( jsonStringified, reviver ); - } catch ( error ) { - return error; - } + return replace( str, /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); } diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index 3569c1d3b577..d92eef3d7f93 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var noop = require( '@stdlib/utils/noop' ); var jsonifyKeys = require( './../lib' ); @@ -60,67 +59,11 @@ tape( 'the function throws if not provided a string', function test( t ) { } }); -tape( 'the function throws if not provided a string (reviver)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - NaN, - true, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - jsonifyKeys( value, noop ); - }; - } -}); - -tape( 'the function throws if provided a reviver argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - jsonifyKeys( '{ a: "b" }', value ); - }; - } -}); - -tape( 'the function returns a JSON value if provided valid JSON', function test( t ) { +tape( 'the function returns a string value', function test( t ) { var expected; var actual; - expected = { - 'beep': 'boop' - }; + expected = '{ "beep": "boop" }'; actual = jsonifyKeys( '{ beep: "boop" }' ); t.deepEqual( actual, expected, 'deep equal' ); @@ -144,28 +87,3 @@ tape( 'the function returns an error if provided invalid JSON', function test( t t.equal( out instanceof Error, true, 'returns an error' ); t.end(); }); - -tape( 'the function supports providing a custom reviver function', function test( t ) { - var expected; - var actual; - var str; - - str = '{ beep: "boop", a: "b" }'; - expected = { - 'beep': 'boop' - }; - actual = jsonifyKeys( str, reviver ); - - t.deepEqual( actual, expected, 'supports custom reviver' ); - - t.end(); - - function reviver( key, value ) { - if ( key === '' ) { - return value; - } - if ( key === 'beep' ) { - return value; - } - } -}); From e671ff8d8d36a88f55590ebd6b22bc71a970feb3 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 25 Feb 2025 11:57:31 +0000 Subject: [PATCH 15/17] refactor: update tests, examples and docs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/utils/jsonify-keys/README.md | 95 +++---------------- .../utils/jsonify-keys/benchmark/benchmark.js | 2 +- .../utils/jsonify-keys/docs/types/index.d.ts | 7 +- .../utils/jsonify-keys/examples/index.js | 21 +--- .../@stdlib/utils/jsonify-keys/lib/index.js | 4 +- .../@stdlib/utils/jsonify-keys/lib/main.js | 16 +--- .../@stdlib/utils/jsonify-keys/package.json | 2 +- .../@stdlib/utils/jsonify-keys/test/test.js | 27 +++--- 8 files changed, 38 insertions(+), 136 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md index 4a13162a49de..3e002935a7f0 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/README.md +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# JSONify keys +# jsonifyKeys -> Parse a [JSON][json]-like string as [JSON][json]. +> Return a normalized string that can be parsed as [JSON][json].
@@ -30,81 +30,19 @@ limitations under the License. var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); ``` -#### jsonifyKeys( str\[, reviver] ) +#### jsonifyKeys( str ) -Parses a [JSON][json]-like `string` as [JSON][json]. +Returns a normalized string that can be parsed as [JSON][json]. ```javascript var out = jsonifyKeys( '{ beep: "boop" }' ); -// returns {'beep':'boop'} -``` - -If unable to parse a `string` as [JSON][json], the function returns an error. - -```javascript -var out = jsonifyKeys( 'beep' ); -// returns -``` - -To transform the `string` being parsed, provide a `reviver`. - -```javascript -function reviver( key, value ) { - if ( key === '' ) { - return value; - } - if ( key === 'beep' ) { - return value; - } -} - -var str = '{ beep: "boop", a: "b" }'; -var out = jsonifyKeys( str, reviver ); -// returns {'beep':'boop'} +// returns '{ "beep": "boop" }' ```
-
- -## Notes - -- In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided **any** value which is not a `string`. - - ```javascript - var out = JSON.parse( null ); - // returns null - - out = jsonifyKeys( null ); - // throws - ``` - -- In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a `SyntaxError` if unable to parse a `string` as [JSON][json]. - - ```javascript - var out = jsonifyKeys( '{ beep: "boop}' ); - // returns - - out = JSON.parse( '{ "beep": "boop}' ); - // throws - ``` - -- In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a `TypeError` if provided a `reviver` argument which is **not** a `function`. - - ```javascript - var out = JSON.parse( '{"a":"b"}', [] ); - // returns {'a':'b'} - - out = jsonifyKeys( '{ a: "b" }', [] ); - // throws - ``` - -
- - -
## Examples @@ -114,22 +52,13 @@ var out = jsonifyKeys( str, reviver ); ```javascript var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); -var out; - -out = jsonifyKeys( '{ beep: "boop" }' ); -// returns {'beep':'boop'} - -out = jsonifyKeys( '3.14' ); -// returns 3.14 - -out = jsonifyKeys( 'true' ); -// returns true - -out = jsonifyKeys( 'null' ); -// returns null +var out = jsonifyKeys( '{ beep: "boop" }' ); +console.log( out ); +// => '{ "beep": "boop" }' -out = jsonifyKeys( '{ beep: "boop }' ); -// returns +var json = JSON.parse( out ); +console.log( json ); +// => { 'beep': 'boop' } ```
@@ -150,8 +79,6 @@ out = jsonifyKeys( '{ beep: "boop }' ); [json]: http://www.json.org/ -[json-parse]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse -
diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js index ff4cb212138d..0b46c527b52e 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/benchmark/benchmark.js @@ -43,7 +43,7 @@ bench( pkg, function benchmark( b ) { } b.toc(); if ( out instanceof Error ) { - b.fail( 'should return JSON' ); + b.fail( 'should return a string' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts index 7f82194855ff..11b4cc59d3f3 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts @@ -22,14 +22,13 @@ * Attempts to parse a JSON-like string as JSON. * * @param str - string to parse -* @param reviver - transformation function -* @returns parsed value or parse error +* @returns parsed string * * @example * var obj = jsonifyKeys( '{ beep: "boop" }' ); -* // returns {'beep':'boop'} +* // returns '{ "beep": "boop" }' */ -declare function jsonifyKeys( str: string, reviver?: Function ): any; +declare function jsonifyKeys( str: string ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js index 92bee9537c48..7b7eca968db5 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/examples/index.js @@ -18,25 +18,12 @@ 'use strict'; -var isError = require( '@stdlib/assert/is-error' ); var jsonifyKeys = require( './../lib' ); var out = jsonifyKeys( '{ beep: "boop" }' ); console.log( out ); -// => {'beep':'boop'} +// => '{ "beep": "boop" }' -out = jsonifyKeys( '3.14' ); -console.log( out ); -// => 3.14 - -out = jsonifyKeys( 'true' ); -console.log( out ); -// => true - -out = jsonifyKeys( 'null' ); -console.log( out ); -// => null - -out = jsonifyKeys( '{ beep: "boop }' ); -console.log( isError( out ) ); -// => true +var json = JSON.parse( out ); +console.log( json ); +// => { 'beep': 'boop' } diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js index 6e81fcdf0fb3..59fb2949788e 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Parse a JSON-like string as JSON.. +* Return a normalized string that can be parsed as JSON. * * @module @stdlib/utils/jsonify-keys * @@ -27,7 +27,7 @@ * var jsonifyKeys = require( '@stdlib/utils/jsonify-keys' ); * * var obj = jsonifyKeys( '{ beep: "boop" }' ); -* // returns {'beep':'boop'} +* // returns '{ "beep": "boop" }' */ // MODULES // diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index fe38594c4541..d78da47fc7ed 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -22,35 +22,27 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var replace = require( '@stdlib/string/replace' ); -var isFunction = require( '@stdlib/assert/is-function' ); var format = require( '@stdlib/string/format' ); // MAIN // /** -* Attempts to parse a JSON-like string as JSON. +* Returns a normalized string that can be parsed as JSON. * * @param {string} str - string to parse -* @param {Function} [reviver] - transformation function * @throws {TypeError} first argument must be a string -* @throws {TypeError} reviver must be a function -* @returns {(*|Error)} parsed value or parse error +* @returns {string} normalized string * * @example * var obj = jsonifyKeys( '{ beep: "boop" }' ); * // returns '{ "beep": "boop" }' */ -function jsonifyKeys( str, reviver ) { +function jsonifyKeys( str ) { if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - if ( arguments.length > 1 ) { - if ( !isFunction( reviver ) ) { - throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', reviver ) ); - } - } - + // Find the word which is preceded by a `{` or suffixed by a `:` and add quotes to it return replace( str, /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); } diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json index 3aef30f7ad91..48e17721042a 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/package.json +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/utils/jsonify-keys", "version": "0.0.0", - "description": "Parse a JSON-like string as JSON.", + "description": "Return a normalized string that can be parsed as JSON.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js index d92eef3d7f93..37633d028762 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/test/test.js @@ -67,23 +67,20 @@ tape( 'the function returns a string value', function test( t ) { actual = jsonifyKeys( '{ beep: "boop" }' ); t.deepEqual( actual, expected, 'deep equal' ); - expected = null; - actual = jsonifyKeys( 'null' ); - t.equal( actual, expected, 'returns null' ); - - expected = true; - actual = jsonifyKeys( 'true' ); - t.equal( actual, expected, 'returns true' ); - - expected = 3.14; - actual = jsonifyKeys( '3.14' ); - t.equal( actual, expected, 'returns 3.14' ); - t.end(); }); -tape( 'the function returns an error if provided invalid JSON', function test( t ) { - var out = jsonifyKeys( '{ beep: "boop }' ); - t.equal( out instanceof Error, true, 'returns an error' ); +tape( 'the resultant string can be parsed as JSON', function test( t ) { + var expected; + var actual; + var out; + + expected = { + 'beep': 'boop' + }; + out = jsonifyKeys( '{ beep: "boop" }' ); + actual = JSON.parse( out ); + t.deepEqual( actual, expected, 'deep equal' ); + t.end(); }); From c086e1b2d51ea1019db055bb359f175a8f81e994 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 25 Feb 2025 12:03:08 +0000 Subject: [PATCH 16/17] docs: update repl.txt and types --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../@stdlib/utils/jsonify-keys/docs/repl.txt | 30 ++++--------------- .../utils/jsonify-keys/docs/types/index.d.ts | 4 +-- .../utils/jsonify-keys/docs/types/test.ts | 6 ++-- 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt index 01887ff63acb..9e4d1920c608 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/repl.txt @@ -1,41 +1,21 @@ -{{alias}}( str[, reviver] ) - Attempts to parse a JSON-like string as JSON. - - Function behavior differs from `JSON.parse()` as follows: - - - throws a `TypeError` if provided any value which is not a string. - - throws a `TypeError` if provided a `reviver` argument which is not a - function. - - returns, rather than throws, a `SyntaxError` if unable to parse a string - as JSON. +{{alias}}( str ) + Returns a normalized string that can be parsed as JSON. Parameters ---------- str: string String to parse. - reviver: Function (optional) - Transformation function. - Returns ------- - out: any|Error - Parsed value or an error. + out: string + Normalized string that can be parsed as JSON. Examples -------- > var obj = {{alias}}( '{ beep: "boop" }' ) - { 'beep': 'boop' } - - // Provide a reviver: - > function reviver( key, value ) { - ... if ( key === '' ) { return value; } - ... if ( key === 'beep' ) { return value; } - ... }; - > var str = '{ beep: "boop", a: "b" }'; - > var out = {{alias}}( str, reviver ) - { 'beep': 'boop' } + '{ "beep": "boop" }' See Also -------- diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts index 11b4cc59d3f3..c8621bb0a62d 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/index.d.ts @@ -19,10 +19,10 @@ // TypeScript Version: 4.1 /** -* Attempts to parse a JSON-like string as JSON. +* Returns a normalized string that can be parsed as JSON. * * @param str - string to parse -* @returns parsed string +* @returns normalized string * * @example * var obj = jsonifyKeys( '{ beep: "boop" }' ); diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts index 44cb8d00365d..38b809771720 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/docs/types/test.ts @@ -23,9 +23,9 @@ import jsonifyKeys = require( './index' ); // The function returns a parsed value... { - jsonifyKeys( '{ beep: "boop" }' ); // $ExpectType any - jsonifyKeys( '"beep"' ); // $ExpectType any - jsonifyKeys( '22' ); // $ExpectType any + jsonifyKeys( '{ beep: "boop" }' ); // $ExpectType string + jsonifyKeys( '"beep"' ); // $ExpectType string + jsonifyKeys( '22' ); // $ExpectType string } // The function does not compile if the first argument is a value other than a string... From 274370404eb7414ba8ab0ab54f78035931e09300 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Tue, 25 Feb 2025 12:08:27 +0000 Subject: [PATCH 17/17] docs: more readable comments --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js index d78da47fc7ed..5970700f7372 100644 --- a/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js +++ b/lib/node_modules/@stdlib/utils/jsonify-keys/lib/main.js @@ -42,7 +42,7 @@ function jsonifyKeys( str ) { if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - // Find the word which is preceded by a `{` or suffixed by a `:` and add quotes to it + // Find the word that is preceded by a `{` or followed by a `:` and add quotes around it. return replace( str, /(\s*?{\s*?|\s*?,\s*?)(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '$1"$3":' ); }