/*
CSV Parse

Please look at the [project documentation](https://csv.js.org/parse/) for
additional information.
*/

/* WEBPACK VAR INJECTION */

/* harmony default export */

/* harmony export (binding) */

/* harmony import */

/* this.options.columns !== true && */

/*#__PURE__*/

/**
 * Iterates through children that are "valid elements".
 *
 * The provided forEachFunc(child, index) will be called for each
 * leaf child with the index reflecting the position relative to "valid components".
 */

/**
 * Iterates through children that are typically specified as `props.children`,
 * but only maps over children that are "valid elements".
 *
 * The mapFunction provided index will be normalised to the components mapped,
 * so an invalid component would not increase the index.
 *
 */

/**
* @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.
*/

/**
* Attempts to call a `RegExp` method.
*
* @private
* @param {*} value - value to test
* @returns {boolean} boolean indicating if able to call a `RegExp` method
*/

/**
* Escape a regular expression string or pattern.
*
* @module @stdlib/utils/escape-regexp-string
*
* @example
* var rescape = require( '@stdlib/utils/escape-regexp-string' );
*
* var str = rescape( '[A-Z]*' );
* // returns '\\[A\\-Z\\]\\*'
*/

/**
* Escapes a regular expression string.
*
* @param {string} str - regular expression string
* @throws {TypeError} first argument must be a string primitive
* @returns {string} escaped string
*
* @example
* var str = rescape( '[A-Z]*' );
* // returns '\\[A\\-Z\\]\\*'
*/

/**
* Replace search occurrences with a replacement string.
*
* @module @stdlib/string/replace
*
* @example
* var replace = require( '@stdlib/string/replace' );
*
* var str = 'beep';
* var out = replace( str, 'e', 'o' );
* // returns 'boop'
*
* str = 'Hello World';
* out = replace( str, /world/i, 'Mr. President' );
* // returns 'Hello Mr. President'
*/

/**
* Replace search occurrences with a replacement string.
*
* @param {string} str - input string
* @param {(string|RegExp)} search - search expression
* @param {(string|Function)} newval - replacement value or function
* @throws {TypeError} first argument must be a string primitive
* @throws {TypeError} second argument argument must be a string primitive or regular expression
* @throws {TypeError} third argument must be a string primitive or function
* @returns {string} new string containing replacement(s)
*
* @example
* var str = 'beep';
* var out = replace( str, 'e', 'o' );
* // returns 'boop'
*
* @example
* var str = 'Hello World';
* var out = replace( str, /world/i, 'Mr. President' );
* // returns 'Hello Mr. President'
*
* @example
* var capitalize = require( '@stdlib/string/capitalize' );
*
* var str = 'Oranges and lemons say the bells of St. Clement\'s';
*
* function replacer( match, p1 ) {
*     return capitalize( p1 );
* }
*
* var out = replace( str, /([^\s]*)/gi, replacer);
* // returns 'Oranges And Lemons Say The Bells Of St. Clement\'s'
*/

/**
* Test if a value is `null`.
*
* @module @stdlib/assert/is-null
*
* @example
* var isNull = require( '@stdlib/assert/is-null' );
*
* var value = null;
*
* var bool = isNull( value );
* // returns true
*/

/**
* Test if a value is a regular expression.
*
* @module @stdlib/assert/is-regexp
*
* @example
* var isRegExp = require( '@stdlib/assert/is-regexp' );
*
* var bool = isRegExp( /\.+/ );
* // returns true
*
* bool = isRegExp( {} );
* // returns false
*/

/**
* Tests if a value is `null`.
*
* @param {*} value - value to test
* @returns {boolean} boolean indicating whether value is null
*
* @example
* var bool = isNull( null );
* // returns true
*
* bool = isNull( true );
* // returns false
*/

/**
* Tests if a value is a regular expression.
*
* @param {*} value - value to test
* @returns {boolean} boolean indicating whether value is a regular expression
*
* @example
* var bool = isRegExp( /\.+/ );
* // returns true
*
* @example
* var bool = isRegExp( {} );
* // returns false
*/

/***/

//   // return !isNaN( parseInt( obj ) );

//   // return Number.isInteger(parseInt(value))

//   return /^(\-|\+)?[1-9][0-9]*$/.test(value)

// "too much recursion" error.

// 1 is for quote.length

// Activate records emition if above from_line

// Auto discovery of record_delimiter, unix, mac and windows supported

// Borrowed from jquery

// Buffer.from "\ufeff", 'utf16le

// Buffer.from("\ufeff")

// Buffer.from('EFBBBF', 'hex')

// Buffer.from([239, 187, 191])

// Buffer.from([255, 254])

// CSV_RECORD_INCONSISTENT_COLUMNS

// CSV_RECORD_INCONSISTENT_FIELDS_LENGTH

// Callback can either be a function or a string

// Central parser implementation

// Check if the string starts with a forward slash...

// Convert the first line into column names

// Copy function arguments

// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted

// Current error encountered by a record

// DOM APIs, for completeness

// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a

// Does not start the time, just sets up the members needed.

// Don't get fooled by e.g. browserify environments.

// Dont loose time calling cast

// EXPORTS //

// Ensure we are not ending in a quoting state

// Escape a quote

// Escape is only active inside quoted fields

// Fields in the first line are converted as-is to columns

// For IE 6–8

// For non-IE10 modern browsers

// For web workers, where supported

// From the spec: "Wait until any invocations of this algorithm started before this one have completed."

// Give a chance for events to be registered later

// Great, nothing to do

// Handle UTF BOM

// Handle empty string

// Helper to test if a character is a space or a line delimiter

// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:

// Implementation of `Transform._flush`

// Implementation of `Transform._transform`

// In relax mode, treat opening quote preceded by chrs as regular

// Increment record length if record size must not exceed a limit

// Keep it in case we implement the `cast_int` option

// MAIN //

// MODULES //

// Merge with user options

// No enough data

// Normalize option `bom`

// Normalize option `cast_date`

// Normalize option `cast`

// Normalize option `columns_duplicates_to_array`

// Normalize option `columns`

// Normalize option `comment`

// Normalize option `delimiter`

// Normalize option `encoding`

// Normalize option `escape`

// Normalize option `from_line`

// Normalize option `from`

// Normalize option `info`

// Normalize option `ltrim`

// Normalize option `max_record_size`

// Normalize option `objname`

// Normalize option `on_record`

// Normalize option `quote`

// Normalize option `raw`

// Normalize option `record_delimiter`

// Normalize option `relax_column_count`

// Normalize option `relax`

// Normalize option `rtrim`

// Normalize option `skip_empty_lines`

// Normalize option `skip_lines_with_empty_values`

// Normalize option `skip_lines_with_error`

// Normalize option `to_line`

// Normalize option `to`

// Normalize option `trim`

// Normalize options `trim`, `ltrim` and `rtrim`

// Not currently escaping and chr is a quote

// Note, the following are equals:

// Note: defined first because other options depends on it

// On some exotic environments, it's not clear which object `setimmediate` was

// Only escape the characters between the `/`:

// Previous char was a valid escape char

// Reassemble:

// Renormalize original options with the new encoding

// Return a tuple with the error and the casted value

// Short circuit for the from_line options

// Skip BOM

// Skip full comment line

// Skip if line is empty and skip_empty_lines activated

// Skip if the remaining buffer can be delimiter

// Skip if the remaining buffer can be escape sequence

// Skip if the remaining buffer can be row delimiter following the closing quote

// Skip if the remaining buffer smaller than comment

// Skip if the remaining buffer smaller than record delimiter

// Skip last line if it has no characters

// So if we're currently running a task, we'll need to delay this invocation.

// Spec says greater than zero

// Store and register the task

// TODO: need to compare bytes instead of single char

// The test against `importScripts` prevents this implementation from being installed inside a web worker,

// Todo: rename CSV_INCONSISTENT_RECORD_LENGTH to

// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to

// Transform record array to an object

// Treat next char as a regular character

// Turn duplicate columns into an array

// VARIABLES //

// Wait for more data

// We are quoting, the char is an escape chr and there is a chr to escape

// We need to de-construct the string...

// __isInt(value){

// `setimmediate` library.

// able to install onto.  Search each possibility in the same order as the

// and this field can't be associated to a key present in columns

// because the final record is an object

// escapeIsQuote: options.escape === options.quote,

// eslint-disable-line no-unused-vars

// eslint-disable-line no-useless-escape

// if(escape !== null && this.state.quoting === true && chr === escape && pos + 1 < bufLen){

// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.

// non-generic

// rename columns

// rtrim in non quoting is handle in __onField

// setimmediate attaches itself to the global object

// to convert chars/strings into buffers.

// treat the current char as a regular char

// where `global.postMessage` means something completely different and can't be used for this purpose.

// }
