build/modelscript.umd.js
async function loadCSVURI(filepath, options) {
              const reqMethod = (filepath.search('https', 'gi') > -1) ? get : get;
              return new Promise((resolve, reject) => {
                const csvData = [];
                const config = Object.assign({ checkType: true, }, options);
                const req = reqMethod(filepath, res => {
                  csvtojson(config).fromStream(res)
                    .on('json', jsonObj => {
                      csvData.push(jsonObj);
                    })
                    .on('error', err => {
                      return reject(err);
                    })
                    .on('done', error => {
                      if (error) {
                        return reject(error);
                      } else {
                        return resolve(csvData);
                      }
                    });
                });
                req.on('error', reject);
              });
            }
async function loadCSVURI(filepath, options) {
              const reqMethod = (filepath.search('https', 'gi') > -1) ? get : get;
              return new Promise((resolve, reject) => {
                const csvData = [];
                const config = Object.assign({ checkType: true, }, options);
                const req = reqMethod(filepath, res => {
                  csvtojson(config).fromStream(res)
                    .on('json', jsonObj => {
                      csvData.push(jsonObj);
                    })
                    .on('error', err => {
                      return reject(err);
                    })
                    .on('done', error => {
                      if (error) {
                        return reject(error);
                      } else {
                        return resolve(csvData);
                      }
                    });
                });
                req.on('error', reject);
              });
            }
async function loadCSVURI ( filepath , options ) { const reqMethod = ( filepath . search ( 'https' , 'gi' ) > - 1 ) ? get : get ; return new Promise ( ( resolve , reject ) => { const csvData = [ ] ; const config = Object . assign ( { checkType : true , } , options ) ; const req = reqMethod ( filepath , res => { csvtojson ( config ) . fromStream ( res ) . on ( 'json' , jsonObj => { csvData . push ( jsonObj ) ; } ) . on ( 'error' , err => { return reject ( err ) ; } ) . on ( 'done' , error => { if ( error ) { return reject ( error ) ; } else { return resolve ( csvData ) ; } } ) ; } ) ; req . on ( 'error' , reject ) ; } ) ; }
Asynchronously loads a CSV from a remote URL and returns an array of objects
@example
// returns [{header:value,header2:value2}]
loadCSVURI('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/data.csv').then(csvData).catch(console.error)
@memberOf csv
@param {string} filepath - URL to CSV path
@param {Object} [options] - options passed to csvtojson
@returns {Object[]} returns an array of objects from a csv where each column header is the property name
Asynchronously loads a CSV from a remote URL and returns an array of objects