From a7e750cfaee7989ce031d399e321fccc56dd2e8b Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Tue, 27 Feb 2024 01:29:05 +0530 Subject: [PATCH 01/66] #1075 added feat: parse-ndjson --- .../@stdlib/utils/parse-ndjson/README.md | 154 +++++++++++++++++ .../utils/parse-ndjson/benchmark/benchmark.js | 54 ++++++ .../@stdlib/utils/parse-ndjson/docs/repl.txt | 57 ++++++ .../utils/parse-ndjson/docs/types/index.d.ts | 34 ++++ .../utils/parse-ndjson/docs/types/test.ts | 54 ++++++ .../utils/parse-ndjson/examples/index.js | 64 +++++++ .../@stdlib/utils/parse-ndjson/lib/index.js | 39 +++++ .../@stdlib/utils/parse-ndjson/lib/main.js | 64 +++++++ .../@stdlib/utils/parse-ndjson/package.json | 67 +++++++ .../@stdlib/utils/parse-ndjson/test/test.js | 163 ++++++++++++++++++ 10 files changed, 750 insertions(+) create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/README.md create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/package.json create mode 100644 lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md new file mode 100644 index 000000000000..312c3d5233d3 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -0,0 +1,154 @@ + + +# Parse NDJSON + +> Parse a string containing serialized newline-delimited JSON (NDJSON). + +## Usage + +```javascript +var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); +``` + +### **parseJSON( str[, reviver] )** +Parses a `string` as `newline-delimited JSON`. + +```javascript +var out = parseNDJSON( '{"beep":"boop"}\n{"example":42}' ); +// returns [{'beep':'boop'}, {'example':42}] +``` +If unable to parse a `string` as newline-delimited JSON, the function returns an error. +```javascript +var out = parseNDJSON( 'beep' ); +// returns +``` +To transform the `string` being parsed, provide a `reviver`. +```javascript +const reviver = function (key, value) { + if (key === '' || key === 'beep') { + return typeof value === 'string' ? value.toUpperCase() : value; + } + return typeof value === 'number' ? value * 2 : value; +} + + const str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; + const out = parseNDJSON(str, reviver) + // returns [{'beep': 'BOOP'}, {'value': 40}, {'numbers': [2,4,6]}] +``` + +## Notes ++ In contrast to the native `JSON.parse()`, this implementation parses `string` as `newline-delimited JSON` and returns an array of parsed JSONs. +```javascript +var out = JSON.parse( '{"beep":"boop"}\n{"foo":"baz"}' ); +// returns + +out = parseNDJSON( '{"beep":"boop"}\n{"foo":"baz"}' ); +// returns [ {'beep':'boop'}, {'foo':'baz'} ] +``` + ++ In contrast to the native `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 = parseNDJSON( null ); +// throws +``` + ++ In contrast to the native JSON.parse(), this implementation does __not__ throw a SyntaxError if unable to parse a string as newline-delimited JSON. +```javascript +var out = parseNDJSON( '{"beep":"boop}' ); +// returns + +out = JSON.parse( '{"beep":"boop}' ); +// throws +``` + ++ In contrast to the native `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 parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); + +var out; + +var parseNDJSON = require( './../lib' ); + +var out; + +out = parseNDJSON('{"name":"John"}\n{"name":"Doe"}'); +// returns [ { name: 'John' }, { name: 'Doe' } ] + +var reviver = function (key, value) { + if (key === 'name') { + return value.toUpperCase(); + } + return value; +}; + +out = parseNDJSON('{"name":"John"}\n{"name":"Doe"}', reviver); +// returns [ { name: 'JOHN' }, { name: 'DOE' } ] + +out = parseNDJSON('{"name":John}\n{"name":Doe}'); +// returns + +out = parseNDJSON(''); +// returns [] + +out = parseNDJSON('{}'); +// returns [{}] + +out = parseNDJSON('{"name":"Eve"}\n42\ntrue\n[1,2,3]'); +// returns [ { name: 'Eve' }, 42, true, [1,2,3] ] +``` +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js new file mode 100644 index 000000000000..d3a669a24f9d --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @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 parseNDJSON = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var str; + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Generate an NDJSON string with a changing property key in each line. + str = '{"beep":"boop","'+fromCodePoint( 97 + (i%26) ) + '":true}\n{"example":' + i + '}\n'; + out = parseNDJSON( str ); + if ( out.some( function( val ) { return val instanceof Error; } ) ) { + b.fail( 'should return an array of JSON objects' ); + } + } + b.toc(); + if ( out.some( function( val ) { return val instanceof Error; } ) ) { + b.fail( 'should return an array of JSON objects' ); + } else { + b.pass( 'benchmark finished' ); + } + b.end(); +}); + +// TODO: Add benchmarks with different sized NDJSON strings diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt new file mode 100644 index 000000000000..c2bf5e60fb4c --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -0,0 +1,57 @@ +{{alias}}( str[, reviver] ) + Attempts to parse a string as Newline-Delimited JSON (NDJSON). + + Function behavior differs from `JSON.parse()` as follows: + + - Returns array of parsed JSON + - Throws a `TypeError` if provided any value which is not a string. + - Returns, rather than throws, a `SyntaxError` if unable to parse a string as NDJSON. + - Throws a `TypeError` if provided a `reviver` argument which is not a function. + + Parameters + ---------- + `str`: `string` + String to parse as Newline-Delimited JSON. + + reviver: Function (optional) + Transformation function. + + Returns + ------- + `out`: `Array<*>|Error` + Array of Parsed values or an error. + + Examples + -------- + + Example 1: Parsing Valid NDJSON + + > const validNDJSON = '{"beep":"boop"}\\n{"example":42}\\n{"data":[1,2,3]}'; + > const result = {{alias}}(validNDJSON); + Result: [ {'beep':'boop'}, {'example':42}, {'data':[1,2,3]} ] + + Example 2: Handling Parsing Errors + + > const invalidNDJSON = '{"beep":"boop"}{"example":42}{"data":[1,2,3]}'; + > const resultWithError = {{alias}}(invalidNDJSON); + Result: [ SyntaxError: Unexpected end of JSON input ] + + Example 3: Using a Reviver Function + + > const ndjsonString = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; + > const reviver = function (key, value) { + if (key === '' || key === 'beep') { + + // Uppercase the values for the 'beep' property + return typeof value === 'string' ? value.toUpperCase() : value; + } + + // Double the values for other properties + return typeof value === 'number' ? value * 2 : value; + }; + + > const resultWithReviver = {{alias}}(ndjsonString, reviver); + Result: [ {'beep':'boop'}, undefined, undefined ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts new file mode 100644 index 000000000000..895d1eb2d6ba --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -0,0 +1,34 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/** +* Parses a string as Newline-Delimited JSON (NDJSON). +* +* @param str - Input string containing NDJSON. +* @returns Array of parsed values or an error +* +* @example +* var arr = parseNDJSON( '{"beep":"boop"}\\n{"example":42}\\n{"data":[1,2,3]}' ); +* // returns [ {'beep':'boop'}, {'example':42}, {'data':[1,2,3]} ] +*/ +declare function parseNDJSON(str: string, revivor?: Function): Array|Error; + +// EXPORTS // +export = parseNDJSON; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts new file mode 100644 index 000000000000..f69ecfc109dd --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts @@ -0,0 +1,54 @@ +/* +* @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 parseNDJSON from './index'; + + +// TESTS // + +// The function returns an array of parsed values... +{ + const validNDJSON: string = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; + const result: Array|Error = parseNDJSON(validNDJSON); // $ExpectType Array | Error +} + +// The function does not compile if the argument is a value other than a string... +{ + parseNDJSON(true); // $ExpectError + parseNDJSON(false); // $ExpectError + parseNDJSON(5); // $ExpectError + parseNDJSON([]); // $ExpectError + parseNDJSON({}); // $ExpectError + parseNDJSON((x: number): number => x); // $ExpectError +} + +// The function does not compile if the second argument is a value other than a function... +{ + parseNDJSON( '{"beep":"boop"}\n{"example":42}', true ); // $ExpectError + parseNDJSON( '{"beep":"boop"}\n{"example":42}', false ); // $ExpectError + parseNDJSON( '{"beep":"boop"}\n{"example":42}', 5 ); // $ExpectError + parseNDJSON( '{"beep":"boop"}\n{"example":42}', [] ); // $ExpectError + parseNDJSON( '{"beep":"boop"}\n{"example":42}', {} ); // $ExpectError + parseNDJSON( '{"beep":"boop"}\n{"example":42}', 'baz' ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + parseNDJSON(); // $ExpectError + parseNDJSON('{"beep":"boop"}', 'baz', 'foo'); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js new file mode 100644 index 000000000000..1b582ca8ba90 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -0,0 +1,64 @@ +/** +* @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 parseNDJSON = require( './../lib' ); + +var ndjsonString = '{"name":"John"}\n{"name":"Doe"}'; + +// Example 1: Parse a simple NDJSON string +var parsedArray = parseNDJSON(ndjsonString); +console.log(parsedArray); +// => [ { name: 'John' }, { name: 'Doe' } ] + +// Example 2: Parse an NDJSON string with a reviver function +var reviver = function (key, value) { + if (key === 'name') { + return value.toUpperCase(); + } + return value +}; + +var parsedArrayWithReviver = parseNDJSON(ndjsonString, reviver); +console.log(parsedArrayWithReviver); +// => [ { name: 'JOHN' }, { name: 'DOE' } ] + +// Example 3: Parse an NDJSON string with an error (missing closing double quote) +var invalidNDJSONString = '{"name":John}\n{"name":Doe}'; +var parsedWithError = parseNDJSON(invalidNDJSONString); +console.log(parsedWithError instanceof Error); +// => true + +// Example 4: Parse an empty NDJSON string +var ndjsonString4 = ''; +var parsedArray4 = parseNDJSON(ndjsonString4); +console.log(parsedArray4); +// => [] + +// Example 5: Parse an NDJSON string with a single empty object +var ndjsonString5 = '{}'; +var parsedArray5 = parseNDJSON(ndjsonString5); +console.log(parsedArray5); +// => [ {} ] + +// Example 6: Parse an NDJSON string with different data types +var ndjsonString6 = '{"name":"Eve"}\n42\ntrue\n[1,2,3]'; +var parsedArray6 = parseNDJSON(ndjsonString6); +console.log(parsedArray6); +// => [ { name: 'Eve' }, 42, true, [1,2,3] ] \ No newline at end of file diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js new file mode 100644 index 000000000000..c922fb7ac208 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js @@ -0,0 +1,39 @@ +/** +* @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'; + +/** +* Parse a string as Newline-Delimited JSON (NDJSON). +* +* @module @stdlib/utils/parse-ndjson +* +* @example +* var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); +* +* var arr = parseNDJSON( '{"beep":"boop"}\n{"example":42}\n' ); +* // returns [{'beep':'boop'}, {'example':42}] +*/ + +// MODULES // + +var main = require( './main.js' ); + +// EXPORTS + +module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js new file mode 100644 index 000000000000..61f0edbcabe9 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -0,0 +1,64 @@ +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var parseJSON = require( '@stdlib/utils/parse-json' ); + + +// MAIN // + +/** + * Parses a string as newline-delimited JSON (NDJSON). + * + * @param {string} str - input string + * @param {Function} [reviver] - transformation function applied to each line + * @throws {TypeError} first argument must be a string + * @throws {TypeError} reviver must be a function + * @returns {Array<(*|Error)>} array of parsed values or parse errors + * + * @example + * var obj = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); + * // returns [{'name':'John'}, {'name':'Doe'}] + */ +function parseNDJSON( str, reviver ) { + if ( !isString( str ) ) { + throw new TypeError( 'invalid argument. First argument must be a string. Value: `%s`.', str); + } + if ( arguments.length > 1 && !isFunction( reviver ) ) { + throw new TypeError( 'invalid argument. Reviver argument must be a function.Value: `%s`.', str ); + } + + // checks if str contains whitespace only + if (/^\s*$/.test(str)){ + return [] + } + + var lines = str.split( '\n' ); + var out = []; + + for ( var i = 0; i < lines.length; i++ ) { + try { + if (reviver){ + var parsed = parseJSON( lines[ i ], reviver ); + } else { + var parsed = parseJSON(lines[ i ]); + } + + if (parsed instanceof Error){ + return parsed; + } + out.push( parsed ); + + } catch ( error ) { + return error; + } + } + + return out; +} + +// EXPORTS // + +module.exports = parseNDJSON; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json new file mode 100644 index 000000000000..6d7086b7982c --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/utils/parse-ndjson", + "version": "0.0.1", + "description": "Parse a string as Newline-Delimited JSON (NDJSON).", + "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": { + "tape": "^5.7.5" + }, + "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", + "ndjson", + "parse", + "newline", + "json", + "string", + "str" + ] +} diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js new file mode 100644 index 000000000000..d9d7c99d5464 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -0,0 +1,163 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var parseNDJSON = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof parseNDJSON, '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() { + parseNDJSON( 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() { + parseNDJSON( 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() { + parseNDJSON( '{"a":"b"}\n{"c": "d"}', value ); + }; + } +}); + +tape( 'the function returns an array of parsed values if provided valid NDJSON', function test( t ) { + var expected; + var actual; + + expected = [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ]; + actual = parseNDJSON( '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}' ); + t.deepEqual( actual, expected, 'deep equal' ); + + expected = []; + actual = parseNDJSON(''); + + t.deepEqual( actual, expected, 'returns an empty array' ); + + t.end(); +}); + +tape( 'the function returns an error if provided invalid NDJSON', function test( t ) { + var out = parseNDJSON('{"beep":"boop"'); + t.equal( out instanceof SyntaxError, true, 'returns an error' ); + t.end(); +}); + +tape( 'the function supports providing a custom reviver function', function test( t ) { + var expected; + var actual; + var str; + + const reviver = function (key, value) { + if (key === '' || key === 'beep') { + // Uppercase the values for the 'beep' property + return typeof value === 'string' ? value.toUpperCase() : value; + } + // Double the values for other properties + return typeof value === 'number' ? value * 2 : value; + } + + str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; + expected = [{'beep': 'BOOP'}, {'value': 40}, {'numbers': [2,4,6]}] + actual = parseNDJSON( str, reviver ); + + t.deepEqual( actual, expected, 'supports custom reviver' ); + + t.end(); + + +}) + From 7c3c7f0e6d2409dc39c2e22711711267ee17580e Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:12:25 +0000 Subject: [PATCH 02/66] chore: update copyright years --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 2 +- .../@stdlib/utils/parse-ndjson/benchmark/benchmark.js | 2 +- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index 312c3d5233d3..135652d791fc 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -1,7 +1,7 @@ \ No newline at end of file + From 4b3d5c397fa2dd3ace89f9fe4139d7da3dc5d395 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 28 Feb 2024 00:30:57 +0530 Subject: [PATCH 04/66] Update benchmark.js Signed-off-by: Manik Sharma --- .../utils/parse-ndjson/benchmark/benchmark.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index f3251554aab7..57f8d50cf4a5 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -38,16 +38,23 @@ bench( pkg, function benchmark( b ) { // Generate an NDJSON string with a changing property key in each line. str = '{"beep":"boop","'+fromCodePoint( 97 + (i%26) ) + '":true}\n{"example":' + i + '}\n'; out = parseNDJSON( str ); - if ( out.some( function( val ) { return val instanceof Error; } ) ) { - b.fail( 'should return an array of JSON objects' ); + + for ( let i = 0; i < out.length; i++ ){ + if ( out[i] instanceof Error ){ + b.fail( 'should return an array of JSON objects' ); + } } } b.toc(); - if ( out.some( function( val ) { return val instanceof Error; } ) ) { - b.fail( 'should return an array of JSON objects' ); - } else { - b.pass( 'benchmark finished' ); + + for ( let i = 0; i < out.length; i++ ){ + if ( out[i] instanceof Error ){ + b.fail( 'should return an array of JSON objects' ); + } } + + b.pass( 'benchmark finished' ) + b.end(); }); From 679e74fc9645ce726527960d30faabf899fcbb5c Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 28 Feb 2024 18:45:16 +0530 Subject: [PATCH 05/66] Update README.md Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/README.md | 126 ++++++++++-------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index cd92dce9c84d..8a70ac6384ff 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -7,7 +7,7 @@ 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 + 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, @@ -16,9 +16,11 @@ See the License for the specific language governing permissions and limitations under the License. --> -# Parse NDJSON +# parseNDJSON -> Parse a string containing serialized newline-delimited JSON (NDJSON). +> Parse a string containing serialized newline-delimited [JSON][json] (NDJSON). + +
## Usage @@ -26,12 +28,13 @@ limitations under the License. var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); ``` -### **parseNDJSON( str[, reviver] )** +#### parseNDJSON( str\[, reviver] ) + Parses a `string` as `newline-delimited JSON`. ```javascript var out = parseNDJSON( '{"beep":"boop"}\n{"example":42}' ); -// returns [{'beep':'boop'}, {'example':42}] +// returns [ {'beep':'boop'}, {'example':42} ] ``` If unable to parse a `string` as newline-delimited JSON, the function returns an error. @@ -44,8 +47,8 @@ var out = parseNDJSON( 'beep' ); To transform the `string` being parsed, provide a `reviver`. ```javascript -const reviver = function (key, value) { - if (key === '' || key === 'beep') { +function reviver( key, value ){ + if ( key === '' || key === 'beep' ) { return typeof value === 'string' ? value.toUpperCase() : value; } return typeof value === 'number' ? value * 2 : value; @@ -53,50 +56,60 @@ const reviver = function (key, value) { const str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; const out = parseNDJSON(str, reviver); -// returns [{'beep': 'BOOP'}, {'value': 40}, {'numbers': [2,4,6]}] -``` - -## Notes -+ In contrast to the native `JSON.parse()`, this implementation parses `string` as `newline-delimited JSON` and returns an array of parsed JSONs. - -```javascript -var out = JSON.parse( '{"beep":"boop"}\n{"foo":"baz"}' ); -// returns - -out = parseNDJSON( '{"beep":"boop"}\n{"foo":"baz"}' ); -// returns [ {'beep':'boop'}, {'foo':'baz'} ] -``` - -- In contrast to the native `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 = parseNDJSON( null ); -// throws +// returns [ {'beep': 'BOOP'}, {'value': 40}, {'numbers': [2,4,6]} ] ``` -- In contrast to the native JSON.parse(), this implementation does __not__ throw a SyntaxError if unable to parse a string as newline-delimited JSON. +
-```javascript -var out = parseNDJSON( '{"beep":"boop}' ); -// returns + -out = JSON.parse( '{"beep":"boop}' ); -// throws -``` +
-- In contrast to the native `JSON.parse()`, this implementation throws a TypeError if provided a reviver argument which is not a function. +## Notes -```javascript -var out = JSON.parse( '{"a":"b"}', [] ); -// returns {'a':'b'} +- In contrast to the native [`JSON.parse()`][json-parse], this implementation parses `string` as `newline-delimited JSON` and returns an array of parsed JSONs. + + ```javascript + var out = JSON.parse( '{"beep":"boop"}\n{"foo":"baz"}' ); + // returns + + out = parseNDJSON( '{"beep":"boop"}\n{"foo":"baz"}' ); + // returns [ {'beep':'boop'}, {'foo':'baz'} ] + ``` + +- 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 = parseNDJSON( 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 newline-delimited JSON. + + ```javascript + var out = parseNDJSON( '{"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 = parseNDJSON( '{"a":"b"}', [] ); + // throws + ``` -out = parseNDJSON( '{"a":"b"}', [] ); -// throws -``` +
+
@@ -109,31 +122,32 @@ var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); var out; -out = parseNDJSON('{"name":"John"}\n{"name":"Doe"}'); -// returns [ { name: 'John' }, { name: 'Doe' } ] +out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); +// returns [ { 'name': 'John' }, { 'name': 'Doe' } ] -var reviver = function (key, value) { - if (key === 'name') { +function reviver( key, value ) { + if ( key === 'name' ) { return value.toUpperCase(); } return value; }; -out = parseNDJSON('{"name":"John"}\n{"name":"Doe"}', reviver); -// returns [ { name: 'JOHN' }, { name: 'DOE' } ] +out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}', reviver ); +// returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] -out = parseNDJSON('{"name":John}\n{"name":Doe}'); +out = parseNDJSON( '{"name":John}\n{"name":Doe}' ); // returns -out = parseNDJSON(''); +out = parseNDJSON( '' ); // returns [] -out = parseNDJSON('{}'); +out = parseNDJSON( '{}' ); // returns [{}] -out = parseNDJSON('{"name":"Eve"}\n42\ntrue\n[1,2,3]'); -// returns [ { name: 'Eve' }, 42, true, [1,2,3] ] -``` +out = parseNDJSON( '{"name":"Eve"}\n42\ntrue\n[1,2,3]' ); +// returns [ { 'name': 'Eve' }, 42, true, [1,2,3] ] +``` +
@@ -145,6 +159,8 @@ out = parseNDJSON('{"name":"Eve"}\n42\ntrue\n[1,2,3]'); + + From 5969f4c4a87bac17d923610a3cce2e3f9a448837 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Thu, 29 Feb 2024 16:05:00 +0530 Subject: [PATCH 21/66] README.md updated --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index f583f62c165f..652ec8a26c66 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -37,13 +37,6 @@ var out = parseNDJSON( '{"beep":"boop"}\n{"example":42}' ); // returns [ {'beep':'boop'}, {'example':42} ] ``` -If unable to parse a `string` as newline-delimited JSON, the function returns an error. - -```javascript -var out = parseNDJSON( 42 ); -// throws -``` - To transform the `string` being parsed, provide a `reviver`. ```javascript @@ -105,7 +98,7 @@ var out = parseNDJSON( str, reviver ); out = parseNDJSON( '{"a":"b"}', [] ); // throws - ``` + ``` From edcd8d54be0658952ee47740c3c0e4a373595523 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Thu, 29 Feb 2024 16:12:09 +0530 Subject: [PATCH 22/66] README.md updated --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index 652ec8a26c66..f7686b803fb5 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -70,6 +70,7 @@ var out = parseNDJSON( str, reviver ); // returns [ {'beep':'boop'}, {'foo':'baz'} ] ``` + - In contrast to the native [`JSON.parse()`][json-parse], this implementation throws a TypeError if provided any value which is not a `string`. ```javascript @@ -80,6 +81,7 @@ var out = parseNDJSON( str, reviver ); // throws ``` + - In contrast to the native [`JSON.parse()`][json-parse], this implementation does **not** throw a SyntaxError if unable to parse a string as newline-delimited JSON. ```javascript @@ -89,7 +91,8 @@ var out = parseNDJSON( str, reviver ); 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 @@ -100,6 +103,7 @@ var out = parseNDJSON( str, reviver ); // throws ``` + From 8ae3540298c720faa29834686e29033638f1f245 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Thu, 29 Feb 2024 16:26:48 +0530 Subject: [PATCH 23/66] README.md updated --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index f7686b803fb5..d0652f550fe5 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -64,7 +64,7 @@ var out = parseNDJSON( str, reviver ); ```javascript var out = JSON.parse( '{"beep":"boop"}\n{"foo":"baz"}' ); - // returns + // throws out = parseNDJSON( '{"beep":"boop"}\n{"foo":"baz"}' ); // returns [ {'beep':'boop'}, {'foo':'baz'} ] From 96e56e5d8ab551b93c5f14603dffd767dc9aa48e Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Thu, 29 Feb 2024 21:09:17 +0530 Subject: [PATCH 24/66] chore: ci error package.json fixed --- lib/node_modules/@stdlib/utils/parse-ndjson/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json index 6d7086b7982c..4d400107f80f 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json @@ -34,6 +34,7 @@ "dependencies": { "tape": "^5.7.5" }, + "devDependencies": {}, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" From 94fb9c16612b5a1fc4ef315934364481f1c9f8be Mon Sep 17 00:00:00 2001 From: Shubham Singh Date: Thu, 29 Feb 2024 21:17:48 +0530 Subject: [PATCH 25/66] chore: fixed license --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 4 +++- .../@stdlib/utils/parse-ndjson/docs/types/test.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index d0652f550fe5..be2e867c386e 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -1,4 +1,5 @@ # parseNDJSON diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts index 83a9fac5b745..a113d7b3337d 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts @@ -1,4 +1,4 @@ -/* +/** * @license Apache-2.0 * * Copyright (c) 2024 The Stdlib Authors. From 313f51aaf10d5098acbd127f9089a39324b42884 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:32:43 +0530 Subject: [PATCH 26/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/package.json updated version to "0.0.0" Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json index 4d400107f80f..00ca61175c75 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json @@ -1,6 +1,6 @@ { "name": "@stdlib/utils/parse-ndjson", - "version": "0.0.1", + "version": "0.0.0", "description": "Parse a string as Newline-Delimited JSON (NDJSON).", "license": "Apache-2.0", "author": { From 5cb824876ebf55e5ad653bdc837a0c47db18e03f Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:33:22 +0530 Subject: [PATCH 27/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/README.md Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index be2e867c386e..7771d39c0f32 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -119,9 +119,7 @@ var out = parseNDJSON( str, reviver ); ```javascript var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); -var out; - -out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); +var out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); // returns [ { 'name': 'John' }, { 'name': 'Doe' } ] function reviver( key, value ) { From 3a29ca5776f8247b0b9beeee0465e26713aec22f Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:33:44 +0530 Subject: [PATCH 28/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/benchmark/benchmark.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index e6532a0c47ac..5556ed0fec89 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -55,7 +55,6 @@ bench( pkg, function benchmark( b ) { } b.pass( 'benchmark finished' ); - b.end(); }); From ff0a2df7c6a92b3cf7482ff5dc0ed2cc41475b4c Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:33:58 +0530 Subject: [PATCH 29/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index bc736edcfdaf..a5a380d3de91 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -22,6 +22,7 @@ * Parses a string as Newline-Delimited JSON (NDJSON). * * @param str - Input string containing NDJSON. +* @param reviver - transformation function applied to each line * @returns Array of parsed values or an error * * @example From 6c16d3676122349cb0391aec82ad2515d450df20 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:34:16 +0530 Subject: [PATCH 30/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index a5a380d3de91..ef76d318864a 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -33,4 +33,5 @@ declare function parseNDJSON( str: string, reviver?: Function ): Array | Error; // EXPORTS // + export = parseNDJSON; From f6d752c39fd8147f32bcaf302059f28cc12893ac Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:34:35 +0530 Subject: [PATCH 31/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index c9625fe742e8..60eb59929973 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -47,7 +47,7 @@ function parseNDJSON( str, reviver ) { var i; if ( !isString( str ) ) { - throw new TypeError( 'invalid argument. First argument must be a string. Value: `%s`.', str ); + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } if ( arguments.length > 1 && !isFunction( reviver ) ) { throw new TypeError( 'invalid argument. Reviver argument must be a function.Value: `%s`.', str ); From fb7428e46b0d785788ca9538b2f15fed7477ff87 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:34:46 +0530 Subject: [PATCH 32/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js Co-authored-by: Philipp Burckhardt Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index 60eb59929973..45dbc5284d6a 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -50,7 +50,7 @@ function parseNDJSON( str, reviver ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } if ( arguments.length > 1 && !isFunction( reviver ) ) { - throw new TypeError( 'invalid argument. Reviver argument must be a function.Value: `%s`.', str ); + throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', str ) ); } // Checks if str contains whitespace only From 6e0664e9773204050ea6f3eecf141a9b67176f80 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:50:37 +0530 Subject: [PATCH 33/66] Update main.js Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index 45dbc5284d6a..24732bd5929c 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -23,7 +23,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isFunction = require( '@stdlib/assert/is-function' ); var parseJSON = require( '@stdlib/utils/parse-json' ); - +var format = require( '@stdlib/string/format' ); // MAIN // From 5533e9fe279f6360151e8565fd7699971676bcd4 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:52:35 +0530 Subject: [PATCH 34/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index aaf492c4cbdf..75a6ff7090fc 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -20,7 +20,7 @@ Returns ------- - out: Array<*>|Error + out: Array | Error Array of Parsed values or an error. Examples From 99e172dcd88f39f792fc0174cf3e98462b3b6d72 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:52:43 +0530 Subject: [PATCH 35/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index 75a6ff7090fc..752a121262b9 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -31,8 +31,8 @@ // Provide a reviver: > function reviver( key, value ){ - ... if (key === '' || key === 'beep') { - ... return (typeof value === 'string') + ... if ( key === '' || key === 'beep' ) { + ... return ( typeof value === 'string' ) ... ? value.toUpperCase() : value; ... }; ... return typeof value === 'number' ? value * 2 : value; From 8d4db86a2a965b60592bc31d456a5da14ebc53fa Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:53:06 +0530 Subject: [PATCH 36/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index 752a121262b9..c5e499ba03c9 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -21,7 +21,7 @@ Returns ------- out: Array | Error - Array of Parsed values or an error. + Array of parsed values or an error. Examples -------- From 80853bd8a29a56057459a3f65b142cb508f6a4cb Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:53:23 +0530 Subject: [PATCH 37/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index ef76d318864a..df26103a2bd2 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -23,7 +23,7 @@ * * @param str - Input string containing NDJSON. * @param reviver - transformation function applied to each line -* @returns Array of parsed values or an error +* @returns array of parsed values or an error * * @example * var arr = parseNDJSON( '{"beep":"boop"}\\n{"example":42}\\n{"data":[1,2,3]}' ); From afd31a403965ccfbd525fb2180bad81efa77e891 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:54:02 +0530 Subject: [PATCH 38/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index df26103a2bd2..94688fc34179 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -21,7 +21,7 @@ /** * Parses a string as Newline-Delimited JSON (NDJSON). * -* @param str - Input string containing NDJSON. +* @param str - input string containing NDJSON * @param reviver - transformation function applied to each line * @returns array of parsed values or an error * From 40f91a4bb7afb6e21aad5bd089173330ea33bf59 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:55:25 +0530 Subject: [PATCH 39/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js index 4bbd94953fb1..8b1be9f98dca 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Parse a string as Newline-Delimited JSON (NDJSON). +* Parse a string as newline-delimited JSON (NDJSON). * * @module @stdlib/utils/parse-ndjson * From e85bffd2d7ad14ab2bd7f7c3d4961d1ddeb9fa53 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:57:48 +0530 Subject: [PATCH 40/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 8bda6dd4aa4c..3502154a3a8b 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -20,7 +20,7 @@ var parseNDJSON = require( './../lib' ); -var ndjsonString = '{"name":"John"}\n{"name":"Doe"}'; +var str = '{"name":"John"}\n{"name":"Doe"}'; // Example 1: Parse a simple NDJSON string var parsedArray = parseNDJSON(ndjsonString); From 1409bcd5c37acc9a59ebffe9524b077d706c5a1c Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:58:24 +0530 Subject: [PATCH 41/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 3502154a3a8b..0b3d49f302c1 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -23,7 +23,7 @@ var parseNDJSON = require( './../lib' ); var str = '{"name":"John"}\n{"name":"Doe"}'; // Example 1: Parse a simple NDJSON string -var parsedArray = parseNDJSON(ndjsonString); +var out = parseNDJSON( str ); console.log(parsedArray); // => [ { 'name': 'John' }, { 'name': 'Doe' } ] From 0e2a8ad66381900ba1e5d40c115c013fb3fa6c40 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:58:43 +0530 Subject: [PATCH 42/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 0b3d49f302c1..7e1dafff7f61 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -35,7 +35,7 @@ function reviver(key, value) { return value; } -var parsedArrayWithReviver = parseNDJSON(ndjsonString, reviver); +out = parseNDJSON( str, reviver ); console.log(parsedArrayWithReviver); // => [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] From 7264919e05c55c9f4e052503fe788f54ce8a7cc4 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 16:59:15 +0530 Subject: [PATCH 43/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 7e1dafff7f61..253d1873ee6f 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -40,8 +40,8 @@ console.log(parsedArrayWithReviver); // => [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] // Example 3: Parse an NDJSON string with an error (missing closing double quote) -var invalidNDJSONString = '{"name":John}\n{"name":Doe}'; -var parsedWithError = parseNDJSON(invalidNDJSONString); +str = '{"name":John}\n{"name":Doe}'; +out = parseNDJSON( str ); console.log(parsedWithError instanceof Error); // => false From 826bde948eef09dcf128574a6ffff210ab1a102f Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 17:03:12 +0530 Subject: [PATCH 44/66] Update index.js Signed-off-by: Manik Sharma --- .../utils/parse-ndjson/examples/index.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 253d1873ee6f..f88215973174 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -24,7 +24,7 @@ var str = '{"name":"John"}\n{"name":"Doe"}'; // Example 1: Parse a simple NDJSON string var out = parseNDJSON( str ); -console.log(parsedArray); +console.log( out ); // => [ { 'name': 'John' }, { 'name': 'Doe' } ] // Example 2: Parse an NDJSON string with a reviver function @@ -36,29 +36,29 @@ function reviver(key, value) { } out = parseNDJSON( str, reviver ); -console.log(parsedArrayWithReviver); +console.log( out ); // => [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] // Example 3: Parse an NDJSON string with an error (missing closing double quote) str = '{"name":John}\n{"name":Doe}'; out = parseNDJSON( str ); -console.log(parsedWithError instanceof Error); -// => false +console.log( out instanceof Error ); +// => true // Example 4: Parse an empty NDJSON string -var ndjsonString4 = ''; -var parsedArray4 = parseNDJSON(ndjsonString4); -console.log(parsedArray4); +str = ''; +out = parseNDJSON( str ); +console.log( out ); // => [] // Example 5: Parse an NDJSON string with a single empty object -var ndjsonString5 = '{}'; -var parsedArray5 = parseNDJSON(ndjsonString5); -console.log(parsedArray5); +str = '{}'; +out = parseNDJSON( str ); +console.log( out ); // => [ {} ] // Example 6: Parse an NDJSON string with different data types -var ndjsonString6 = '{"name":"Eve"}\n42\ntrue\n[1,2,3]'; -var parsedArray6 = parseNDJSON(ndjsonString6); -console.log(parsedArray6); +str = '{"name":"Eve"}\n42\ntrue\n[1,2,3]'; +out = parseNDJSON( str ); +console.log( out ); // => [ { 'name': 'Eve' }, 42, true, [1,2,3] ] From 92d2f2e00a0d7a28cda95e1099ed18e0dc8a144c Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 17:04:15 +0530 Subject: [PATCH 45/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index 94688fc34179..13f204e37e06 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -32,6 +32,7 @@ declare function parseNDJSON( str: string, reviver?: Function ): Array | Error; + // EXPORTS // export = parseNDJSON; From 90472cc24fccfeedfa4830368074da0e3e9ecd1d Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 17:04:59 +0530 Subject: [PATCH 46/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index 24732bd5929c..f86528cfa1e4 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -34,7 +34,7 @@ var format = require( '@stdlib/string/format' ); * @param {Function} [reviver] - transformation function applied to each line * @throws {TypeError} first argument must be a string * @throws {TypeError} reviver must be a function -* @returns {Array<(*|Error)>} array of parsed values or parse errors +* @returns {Array|Error} array of parsed values or an error * * @example * var obj = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); From 8375edc2fa0b603fc01921b2ffafc5d5b40b4381 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 17:07:34 +0530 Subject: [PATCH 47/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index 09d4aa6f26cf..13e24d3ef3d8 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -167,7 +167,7 @@ tape( 'the function supports providing a custom reviver function', function test 'value': 40 }, { - 'numbers': [2, 4, 6] + 'numbers': [ 2, 4, 6 ] } ]; actual = parseNDJSON( str, reviver ); From 9bb2cf50e65a25e3f3b5274ffa4d701e4ea39445 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Sat, 2 Mar 2024 17:07:44 +0530 Subject: [PATCH 48/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js Co-authored-by: Athan Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index 13e24d3ef3d8..12203961db7f 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -172,7 +172,7 @@ tape( 'the function supports providing a custom reviver function', function test ]; actual = parseNDJSON( str, reviver ); - t.deepEqual( actual, expected, 'supports custom reviver' ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); From 8e3eb1f73a9a9e98fd26756945b8f132407241ce Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 6 Mar 2024 16:45:14 +0530 Subject: [PATCH 49/66] Added support for trailing newline and alternate characters --- .../@stdlib/utils/parse-ndjson/README.md | 18 ++- .../utils/parse-ndjson/benchmark/benchmark.js | 2 + .../@stdlib/utils/parse-ndjson/docs/repl.txt | 4 +- .../utils/parse-ndjson/docs/types/index.d.ts | 3 +- .../utils/parse-ndjson/docs/types/test.ts | 1 + .../utils/parse-ndjson/examples/index.js | 18 ++- .../@stdlib/utils/parse-ndjson/lib/index.js | 6 +- .../@stdlib/utils/parse-ndjson/lib/main.js | 28 +++- .../@stdlib/utils/parse-ndjson/package.json | 132 +++++++++--------- .../@stdlib/utils/parse-ndjson/test/test.js | 28 +--- 10 files changed, 131 insertions(+), 109 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index 7771d39c0f32..7ed5744ab89a 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -36,7 +36,7 @@ Parses a `string` as `newline-delimited JSON`. ```javascript var out = parseNDJSON( '{"beep":"boop"}\n{"example":42}' ); -// returns [ {'beep':'boop'}, {'example':42} ] +// returns [ { 'beep': 'boop' }, { 'example': 42 } ] ``` To transform the `string` being parsed, provide a `reviver`. @@ -51,7 +51,7 @@ function reviver( key, value ) { var str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; var out = parseNDJSON( str, reviver ); -// returns [ {'beep': 'BOOP'}, {'value': 40}, {'numbers': [2,4,6]} ] +// returns [ { 'beep' : 'BOOP' }, { 'value': 40 }, { 'numbers': [ 2, 4, 6 ] } ] ``` @@ -69,7 +69,7 @@ var out = parseNDJSON( str, reviver ); // throws out = parseNDJSON( '{"beep":"boop"}\n{"foo":"baz"}' ); - // returns [ {'beep':'boop'}, {'foo':'baz'} ] + // returns [ { 'beep': 'boop' }, { 'foo': 'baz' } ] ``` @@ -99,7 +99,7 @@ var out = parseNDJSON( str, reviver ); ```javascript var out = JSON.parse( '{"a":"b"}', [] ); - // returns {'a':'b'} + // returns { 'a': 'b' } out = parseNDJSON( '{"a":"b"}', [] ); // throws @@ -135,14 +135,20 @@ out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}', reviver ); out = parseNDJSON( '{"name":John}\n{"name":Doe}' ); // returns -out = parseNDJSON( '' ); +out = parseNDJSON( ' ' ); // returns [] out = parseNDJSON( '{}' ); // returns [ {} ] out = parseNDJSON( '{"name":"Eve"}\n42\ntrue\n[1,2,3]' ); -// returns [ { 'name': 'Eve' }, 42, true, [1,2,3] ] +// returns [ { 'name': 'Eve' }, 42, true, [ 1, 2, 3 ] ] + +out = parseNDJSON( '{"name":John}\r\n{"name":Doe}' ) +// returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] + +out = parseNDJSON( '{"name":John}\n{"name":Doe}\n' ) +// returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] ``` diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index 5556ed0fec89..6448bab361ac 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -20,6 +20,7 @@ // MODULES // + var bench = require( '@stdlib/bench' ); var fromCodePoint = require( '@stdlib/string/from-code-point' ); var pkg = require( './../package.json' ).name; @@ -28,6 +29,7 @@ var parseNDJSON = require( './../lib' ); // MAIN // + bench( pkg, function benchmark( b ) { var str; var out; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index c5e499ba03c9..9c1756ffada4 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -27,7 +27,7 @@ -------- > var obj = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; > var result = {{alias}}( obj ) - [ {'beep':'boop'}, {'example':42}, {'data':[1,2,3]} ] + [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ] // Provide a reviver: > function reviver( key, value ){ @@ -39,7 +39,7 @@ ...}; > var ndjsonString = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; > var resultWithReviver = {{alias}}( ndjsonString, reviver ) - [ {'beep':'boop'}, {'example': 84}, {'data': [2, 4, 6]} ] + [ { 'beep': 'boop' }, { 'example': 84 }, { 'data': [ 2, 4, 6 ] } ] See Also -------- diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index 13f204e37e06..47440d60a42b 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -27,7 +27,7 @@ * * @example * var arr = parseNDJSON( '{"beep":"boop"}\\n{"example":42}\\n{"data":[1,2,3]}' ); -* // returns [ {'beep':'boop'}, {'example':42}, {'data':[1,2,3]} ] +* // returns [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ] */ declare function parseNDJSON( str: string, reviver?: Function ): Array | Error; @@ -35,4 +35,5 @@ declare function parseNDJSON( str: string, reviver?: Function ): Array | Er // EXPORTS // + export = parseNDJSON; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts index a113d7b3337d..85e98fe922a6 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts @@ -21,6 +21,7 @@ import parseNDJSON = require( './index' ); // TESTS // + // The function returns an array of parsed values... { const validNDJSON = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index f88215973174..9b414c1328fe 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -28,8 +28,8 @@ console.log( out ); // => [ { 'name': 'John' }, { 'name': 'Doe' } ] // Example 2: Parse an NDJSON string with a reviver function -function reviver(key, value) { - if (key === 'name') { +function reviver( key, value ) { + if ( key === 'name' ) { return value.toUpperCase(); } return value; @@ -58,7 +58,19 @@ console.log( out ); // => [ {} ] // Example 6: Parse an NDJSON string with different data types -str = '{"name":"Eve"}\n42\ntrue\n[1,2,3]'; +str = '{"name":"Eve"}\n42\ntrue\n[1,2,3]\r\n'; out = parseNDJSON( str ); console.log( out ); // => [ { 'name': 'Eve' }, 42, true, [1,2,3] ] + +// Example 7: Parse a simple NDJSON string, followed by a trailing newline + str = '{"name":"John"}\n{"name":"Doe"}\n'; +var out = parseNDJSON( str ); +console.log( out ); +// => [ { 'name': 'John' }, { 'name': 'Doe' } ] + +// Example 8: Parse a simple NDJSON string, with alternate newline characters +str = '{"beep":"boop"}\r\n{"foo":"baz"}'; +var out = parseNDJSON( str ); +console.log( out ); +// => [ { 'beep': 'boop' }, { 'foo': 'baz' } ] \ No newline at end of file diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js index 8b1be9f98dca..e14c11f83797 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js @@ -26,15 +26,17 @@ * @example * var parseNDJSON = require( '@stdlib/utils/parse-ndjson' ); * -* var arr = parseNDJSON( '{"beep":"boop"}\n{"example":42}\n' ); -* // returns [{'beep':'boop'}, {'example':42}] +* var out = parseNDJSON( '{"beep":"boop"}\n{"example":42}' ); +* // returns [ { 'beep': 'boop' }, { 'example': 42 } ] */ // MODULES // + var main = require( './main.js' ); // EXPORTS // + module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index f86528cfa1e4..1f81d153dd3d 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -20,13 +20,17 @@ // MODULES // + var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isFunction = require( '@stdlib/assert/is-function' ); var parseJSON = require( '@stdlib/utils/parse-json' ); var format = require( '@stdlib/string/format' ); +var isWhitespace = require( '@stdlib/assert/is-whitespace' ) +var reEOL = require( '@stdlib/regexp/eol' ); // MAIN // + /** * Parses a string as newline-delimited JSON (NDJSON). * @@ -37,14 +41,16 @@ var format = require( '@stdlib/string/format' ); * @returns {Array|Error} array of parsed values or an error * * @example -* var obj = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); -* // returns [ {'name':'John'}, {'name':'Doe'} ] +* var out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); +* // returns [ { 'name': 'John' }, { 'name': 'Doe' } ] */ + function parseNDJSON( str, reviver ) { var parsed; var lines; var out; var i; + var RE_EOL; if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); @@ -53,16 +59,24 @@ function parseNDJSON( str, reviver ) { throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', str ) ); } - // Checks if str contains whitespace only - if ( /^\s*$/.test(str) ) { + // checks whitespace + if ( isWhitespace( str ) || str == '' ) { return []; } - lines = str.split( '\n' ); + RE_EOL = reEOL(); + + lines = str.split( RE_EOL ); + + // removes trailing newline + if ( lines[ lines.length - 1 ].length == 0 ){ + lines.pop() + } + out = []; for ( i = 0; i < lines.length; i++ ) { - if (reviver) { + if ( reviver ) { parsed = parseJSON( lines[ i ], reviver ); } else { parsed = parseJSON( lines[ i ] ); @@ -70,6 +84,7 @@ function parseNDJSON( str, reviver ) { if ( parsed instanceof Error ) { return parsed; } + out.push( parsed ); } return out; @@ -78,4 +93,5 @@ function parseNDJSON( str, reviver ) { // EXPORTS // + module.exports = parseNDJSON; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json index 00ca61175c75..449f48247665 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/package.json +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/package.json @@ -1,68 +1,68 @@ { - "name": "@stdlib/utils/parse-ndjson", - "version": "0.0.0", - "description": "Parse a string as Newline-Delimited JSON (NDJSON).", - "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": { - "tape": "^5.7.5" - }, - "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", - "ndjson", - "parse", - "newline", - "json", - "string", - "str" - ] + "name": "@stdlib/utils/parse-ndjson", + "version": "0.0.0", + "description": "Parse a string as Newline-Delimited JSON (NDJSON).", + "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": { + "tape": "^5.7.5" + }, + "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", + "ndjson", + "parse", + "newline", + "json", + "string", + "str" + ] } diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index 12203961db7f..c2fa00653467 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -20,6 +20,7 @@ // MODULES // + var tape = require( 'tape' ); var noop = require( '@stdlib/utils/noop' ); var parseNDJSON = require( './../lib' ); @@ -27,6 +28,7 @@ var parseNDJSON = require( './../lib' ); // TESTS // + tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof parseNDJSON, 'function', 'main export is a function' ); @@ -118,17 +120,7 @@ tape( 'the function returns an array of parsed values if provided valid NDJSON', var expected; var actual; - expected = [ - { - 'beep': 'boop' - }, - { - 'example': 42 - }, - { - 'data': [ 1, 2, 3 ] - } - ]; + expected = [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ]; actual = parseNDJSON( '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}' ); t.deepEqual( actual, expected, 'deep equal' ); @@ -141,7 +133,7 @@ tape( 'the function returns an array of parsed values if provided valid NDJSON', }); tape( 'the function returns an error if provided invalid NDJSON', function test( t ) { - var out = parseNDJSON('{"beep":"boop"'); + var out = parseNDJSON( '{"beep":"boop"' ); t.equal( out instanceof SyntaxError, true, 'returns an error' ); t.end(); }); @@ -159,17 +151,7 @@ tape( 'the function supports providing a custom reviver function', function test } str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; - expected = [ - { - 'beep': 'BOOP' - }, - { - 'value': 40 - }, - { - 'numbers': [ 2, 4, 6 ] - } - ]; + expected = [ { 'beep': 'BOOP' }, { 'value': 40 }, { 'numbers': [ 2, 4, 6 ] } ]; actual = parseNDJSON( str, reviver ); t.deepEqual( actual, expected, 'returns expected value' ); From f6f741632ab89f7b1a5028fcf3d17cece493779d Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 6 Mar 2024 17:08:53 +0530 Subject: [PATCH 50/66] Resolved lint errors --- .../@stdlib/utils/parse-ndjson/benchmark/benchmark.js | 1 + lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt | 4 ++-- .../@stdlib/utils/parse-ndjson/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index 6448bab361ac..0f6e81adf4c1 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -18,6 +18,7 @@ 'use strict'; + // MODULES // diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index 9c1756ffada4..dacb3a661cdc 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( str[, reviver] ) - Attempts to parse a string as Newline-Delimited JSON (NDJSON). + Attempts to parse a string as newline-delimited JSON (NDJSON). Function behavior differs from `JSON.parse()` as follows: @@ -13,7 +13,7 @@ Parameters ---------- str: string - String to parse as Newline-Delimited JSON. + String to parse as newline-delimited JSON. reviver: Function (optional) Transformation function. diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index 47440d60a42b..d11b8939b661 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Parses a string as Newline-Delimited JSON (NDJSON). +* Parses a string as newline-delimited JSON (NDJSON). * * @param str - input string containing NDJSON * @param reviver - transformation function applied to each line diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js index e14c11f83797..8b31dc1dff49 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js @@ -30,8 +30,8 @@ * // returns [ { 'beep': 'boop' }, { 'example': 42 } ] */ -// MODULES // +// MODULES // var main = require( './main.js' ); diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index 1f81d153dd3d..c6aae436aec1 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -28,8 +28,8 @@ var format = require( '@stdlib/string/format' ); var isWhitespace = require( '@stdlib/assert/is-whitespace' ) var reEOL = require( '@stdlib/regexp/eol' ); -// MAIN // +// MAIN // /** * Parses a string as newline-delimited JSON (NDJSON). diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index c2fa00653467..11d724118e15 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -18,8 +18,8 @@ 'use strict'; -// MODULES // +// MODULES // var tape = require( 'tape' ); var noop = require( '@stdlib/utils/noop' ); From ee945ee7aeeb918533a298864af18ba2fd175eeb Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 6 Mar 2024 17:21:08 +0530 Subject: [PATCH 51/66] Resolved lint errors --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index 7ed5744ab89a..4f1d00a78ebc 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -144,10 +144,10 @@ out = parseNDJSON( '{}' ); out = parseNDJSON( '{"name":"Eve"}\n42\ntrue\n[1,2,3]' ); // returns [ { 'name': 'Eve' }, 42, true, [ 1, 2, 3 ] ] -out = parseNDJSON( '{"name":John}\r\n{"name":Doe}' ) +out = parseNDJSON( '{"name":John}\r\n{"name":Doe}' ); // returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] -out = parseNDJSON( '{"name":John}\n{"name":Doe}\n' ) +out = parseNDJSON( '{"name":John}\n{"name":Doe}\n' ); // returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] ``` From b7d8c6a9e4d6bf2e69778c9a8b84de2dcebbb7cf Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 6 Mar 2024 17:25:32 +0530 Subject: [PATCH 52/66] Resolved lint errors --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index 4f1d00a78ebc..f179382dddd5 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -145,10 +145,10 @@ out = parseNDJSON( '{"name":"Eve"}\n42\ntrue\n[1,2,3]' ); // returns [ { 'name': 'Eve' }, 42, true, [ 1, 2, 3 ] ] out = parseNDJSON( '{"name":John}\r\n{"name":Doe}' ); -// returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] +// returns [ { 'name': 'John' }, { 'name': 'Doe' } ] out = parseNDJSON( '{"name":John}\n{"name":Doe}\n' ); -// returns [ { 'name': 'JOHN' }, { 'name': 'DOE' } ] +// returns [ { 'name': 'John' }, { 'name': 'Doe' } ] ``` From 9b780d52a808505cf14f44b52dc6e6483f5af15f Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Wed, 6 Mar 2024 17:28:46 +0530 Subject: [PATCH 53/66] Resolved lint errors --- lib/node_modules/@stdlib/utils/parse-ndjson/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md index f179382dddd5..b5ef90096964 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/README.md +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/README.md @@ -144,10 +144,10 @@ out = parseNDJSON( '{}' ); out = parseNDJSON( '{"name":"Eve"}\n42\ntrue\n[1,2,3]' ); // returns [ { 'name': 'Eve' }, 42, true, [ 1, 2, 3 ] ] -out = parseNDJSON( '{"name":John}\r\n{"name":Doe}' ); +out = parseNDJSON( '{"name":"John"}\r\n{"name":"Doe"}' ); // returns [ { 'name': 'John' }, { 'name': 'Doe' } ] -out = parseNDJSON( '{"name":John}\n{"name":Doe}\n' ); +out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}\n' ); // returns [ { 'name': 'John' }, { 'name': 'Doe' } ] ``` From 76c6be0108dffcff288c502b77f5a320b9510527 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Thu, 7 Mar 2024 21:22:08 +0530 Subject: [PATCH 54/66] Update README.md Signed-off-by: Manik Sharma From 8f01e539465359d983fa279a25d104c361ae93be Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Thu, 7 Mar 2024 21:40:31 +0530 Subject: [PATCH 55/66] Update index.js Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js index 8b31dc1dff49..1b77cbaf7689 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/index.js @@ -38,5 +38,4 @@ var main = require( './main.js' ); // EXPORTS // - module.exports = main; From 2064f361e24a72713a34ff2fb35a4a5c24198b9d Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Fri, 8 Mar 2024 18:39:55 +0530 Subject: [PATCH 56/66] Update main.js Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/lib/main.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index c6aae436aec1..a33cdfc021f1 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -20,12 +20,11 @@ // MODULES // - var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isFunction = require( '@stdlib/assert/is-function' ); var parseJSON = require( '@stdlib/utils/parse-json' ); var format = require( '@stdlib/string/format' ); -var isWhitespace = require( '@stdlib/assert/is-whitespace' ) +var isWhitespace = require( '@stdlib/assert/is-whitespace' ); var reEOL = require( '@stdlib/regexp/eol' ); @@ -44,13 +43,13 @@ var reEOL = require( '@stdlib/regexp/eol' ); * var out = parseNDJSON( '{"name":"John"}\n{"name":"Doe"}' ); * // returns [ { 'name': 'John' }, { 'name': 'Doe' } ] */ - function parseNDJSON( str, reviver ) { var parsed; + var RE_EOL; var lines; var out; var i; - var RE_EOL; + if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); @@ -59,8 +58,8 @@ function parseNDJSON( str, reviver ) { throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', str ) ); } - // checks whitespace - if ( isWhitespace( str ) || str == '' ) { + // Checks whitespace + if ( isWhitespace( str ) || str === '' ) { return []; } @@ -68,9 +67,9 @@ function parseNDJSON( str, reviver ) { lines = str.split( RE_EOL ); - // removes trailing newline - if ( lines[ lines.length - 1 ].length == 0 ){ - lines.pop() + // Removes trailing newline + if ( lines[ lines.length - 1 ].length === 0 ) { + lines.pop(); } out = []; @@ -93,5 +92,4 @@ function parseNDJSON( str, reviver ) { // EXPORTS // - module.exports = parseNDJSON; From 1f76d20970736285c191971369bbe30966b2cfb5 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Fri, 8 Mar 2024 19:02:58 +0530 Subject: [PATCH 57/66] Update test.js Signed-off-by: Manik Sharma --- lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index 11d724118e15..443f8334b49a 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -18,7 +18,6 @@ 'use strict'; - // MODULES // var tape = require( 'tape' ); @@ -28,7 +27,6 @@ var parseNDJSON = require( './../lib' ); // TESTS // - tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof parseNDJSON, 'function', 'main export is a function' ); From 8af4a02e4adb210af5bce8abe005d4c19d352757 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:37:34 -0500 Subject: [PATCH 58/66] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../utils/parse-ndjson/benchmark/benchmark.js | 3 +-- .../@stdlib/utils/parse-ndjson/docs/repl.txt | 14 +++++++------- .../utils/parse-ndjson/docs/types/index.d.ts | 1 - .../@stdlib/utils/parse-ndjson/lib/main.js | 2 -- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index 0f6e81adf4c1..52af8fb1d314 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -30,7 +30,6 @@ var parseNDJSON = require( './../lib' ); // MAIN // - bench( pkg, function benchmark( b ) { var str; var out; @@ -40,7 +39,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - // Generate an NDJSON string with a changing property key in each line. + // Generate an NDJSON string with a changing property key in each line: str = '{"beep":"boop","'+fromCodePoint( 97 + (i%26) ) + '":true}\n{"example":' + i + '}'; out = parseNDJSON( str ); diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index dacb3a661cdc..0a912e620d02 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -30,13 +30,13 @@ [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ] // Provide a reviver: - > function reviver( key, value ){ - ... if ( key === '' || key === 'beep' ) { - ... return ( typeof value === 'string' ) - ... ? value.toUpperCase() : value; - ... }; - ... return typeof value === 'number' ? value * 2 : value; - ...}; + > function reviver( key, value ) { + ... if ( key === '' || key === 'beep' ) { + ... return ( typeof value === 'string' ) + ... ? value.toUpperCase() : value; + ... }; + ... return typeof value === 'number' ? value * 2 : value; + ... }; > var ndjsonString = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; > var resultWithReviver = {{alias}}( ndjsonString, reviver ) [ { 'beep': 'boop' }, { 'example': 84 }, { 'data': [ 2, 4, 6 ] } ] diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts index d11b8939b661..952badea34db 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/index.d.ts @@ -35,5 +35,4 @@ declare function parseNDJSON( str: string, reviver?: Function ): Array | Er // EXPORTS // - export = parseNDJSON; diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index a33cdfc021f1..18210f5ad81d 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -57,8 +57,6 @@ function parseNDJSON( str, reviver ) { if ( arguments.length > 1 && !isFunction( reviver ) ) { throw new TypeError( format( 'invalid argument. Reviver argument must be a function. Value: `%s`.', str ) ); } - - // Checks whitespace if ( isWhitespace( str ) || str === '' ) { return []; } From eb2b06b8780ae7f92553abd46c3aeeddd893237b Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:37:57 -0500 Subject: [PATCH 59/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts index 85e98fe922a6..a113d7b3337d 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/types/test.ts @@ -21,7 +21,6 @@ import parseNDJSON = require( './index' ); // TESTS // - // The function returns an array of parsed values... { const validNDJSON = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; From f128dba5faf5ad6358f31d50b32dd013956c25df Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:38:05 -0500 Subject: [PATCH 60/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index 18210f5ad81d..c13bee27efee 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -49,7 +49,6 @@ function parseNDJSON( str, reviver ) { var lines; var out; var i; - if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); From 3efc890427d87e051dcae4b24648efeef3ea2b73 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:38:11 -0500 Subject: [PATCH 61/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js index c13bee27efee..59554ed9d215 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/lib/main.js @@ -64,7 +64,7 @@ function parseNDJSON( str, reviver ) { lines = str.split( RE_EOL ); - // Removes trailing newline + // Remove trailing newline: if ( lines[ lines.length - 1 ].length === 0 ) { lines.pop(); } From 21e58d9ee366fe552a6664aa6aa4538a5cae1394 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:41:19 -0500 Subject: [PATCH 62/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt index 0a912e620d02..45b1efe7788e 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/docs/repl.txt @@ -31,10 +31,10 @@ // Provide a reviver: > function reviver( key, value ) { - ... if ( key === '' || key === 'beep' ) { - ... return ( typeof value === 'string' ) - ... ? value.toUpperCase() : value; - ... }; + ... if ( key === '' || key === 'beep' ) { + ... return ( typeof value === 'string' ) + ... ? value.toUpperCase() : value; + ... }; ... return typeof value === 'number' ? value * 2 : value; ... }; > var ndjsonString = '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}'; From c112f7facd9149155b050f647155ab111f909b35 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:42:30 -0500 Subject: [PATCH 63/66] Update lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/parse-ndjson/examples/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 9b414c1328fe..84316409c79f 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -64,13 +64,13 @@ console.log( out ); // => [ { 'name': 'Eve' }, 42, true, [1,2,3] ] // Example 7: Parse a simple NDJSON string, followed by a trailing newline - str = '{"name":"John"}\n{"name":"Doe"}\n'; -var out = parseNDJSON( str ); +str = '{"name":"John"}\n{"name":"Doe"}\n'; +out = parseNDJSON( str ); console.log( out ); // => [ { 'name': 'John' }, { 'name': 'Doe' } ] // Example 8: Parse a simple NDJSON string, with alternate newline characters str = '{"beep":"boop"}\r\n{"foo":"baz"}'; -var out = parseNDJSON( str ); +out = parseNDJSON( str ); console.log( out ); // => [ { 'beep': 'boop' }, { 'foo': 'baz' } ] \ No newline at end of file From 1fc6a355ca7c55ccbd1b73117834be6f2bbc9507 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:51:05 -0500 Subject: [PATCH 64/66] Update index.js Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/parse-ndjson/examples/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js index 84316409c79f..e36618052378 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/examples/index.js @@ -18,6 +18,7 @@ 'use strict'; +var isError = require( '@stdlib/assert/is-error' ); var parseNDJSON = require( './../lib' ); var str = '{"name":"John"}\n{"name":"Doe"}'; @@ -42,7 +43,7 @@ console.log( out ); // Example 3: Parse an NDJSON string with an error (missing closing double quote) str = '{"name":John}\n{"name":Doe}'; out = parseNDJSON( str ); -console.log( out instanceof Error ); +console.log( isError( out ) ); // => true // Example 4: Parse an empty NDJSON string @@ -73,4 +74,4 @@ console.log( out ); str = '{"beep":"boop"}\r\n{"foo":"baz"}'; out = parseNDJSON( str ); console.log( out ); -// => [ { 'beep': 'boop' }, { 'foo': 'baz' } ] \ No newline at end of file +// => [ { 'beep': 'boop' }, { 'foo': 'baz' } ] From ea33c68e44768b92e2262d572dc236e1b2023363 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 8 Mar 2024 09:55:49 -0500 Subject: [PATCH 65/66] Update test.js Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/parse-ndjson/test/test.js | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js index 443f8334b49a..69d26301ba4b 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/test/test.js @@ -118,7 +118,17 @@ tape( 'the function returns an array of parsed values if provided valid NDJSON', var expected; var actual; - expected = [ { 'beep': 'boop' }, { 'example': 42 }, { 'data': [ 1, 2, 3 ] } ]; + expected = [ + { + 'beep': 'boop' + }, + { + 'example': 42 + }, + { + 'data': [ 1, 2, 3 ] + } + ]; actual = parseNDJSON( '{"beep":"boop"}\n{"example":42}\n{"data":[1,2,3]}' ); t.deepEqual( actual, expected, 'deep equal' ); @@ -149,7 +159,17 @@ tape( 'the function supports providing a custom reviver function', function test } str = '{"beep":"boop"}\n{"value": 20}\n{"numbers": [1,2,3]}'; - expected = [ { 'beep': 'BOOP' }, { 'value': 40 }, { 'numbers': [ 2, 4, 6 ] } ]; + expected = [ + { + 'beep': 'BOOP' + }, + { + 'value': 40 + }, + { + 'numbers': [ 2, 4, 6 ] + } + ]; actual = parseNDJSON( str, reviver ); t.deepEqual( actual, expected, 'returns expected value' ); From 00af9d3b9b5a26ae0c8f2c7f12ace399402a3041 Mon Sep 17 00:00:00 2001 From: Manik Sharma Date: Fri, 8 Mar 2024 20:33:05 +0530 Subject: [PATCH 66/66] Update benchmark.js Signed-off-by: Manik Sharma --- .../@stdlib/utils/parse-ndjson/benchmark/benchmark.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js index 52af8fb1d314..899d4481cb21 100644 --- a/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/utils/parse-ndjson/benchmark/benchmark.js @@ -18,10 +18,8 @@ 'use strict'; - // MODULES // - var bench = require( '@stdlib/bench' ); var fromCodePoint = require( '@stdlib/string/from-code-point' ); var pkg = require( './../package.json' ).name;