Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csv42

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv42 - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

5

lib/cjs/value.js

@@ -44,3 +44,6 @@ "use strict";

function parseUnescapedValue(value) {
if (value[0] >= '0' && value[0] <= '9') {
if (value[0] >= '-' && value[0] <= '9') {
// a number can start with one of the following characters: 01234567890.-
// the range above contains these characters, but also the forward slash /.
// That is not a problem though: parsing as number will fail
var number = Number(value);

@@ -47,0 +50,0 @@ return !isNaN(number) ? number : value;

@@ -36,3 +36,6 @@ export function createFormatValue(delimiter) {

function parseUnescapedValue(value) {
if (value[0] >= '0' && value[0] <= '9') {
if (value[0] >= '-' && value[0] <= '9') {
// a number can start with one of the following characters: 01234567890.-
// the range above contains these characters, but also the forward slash /.
// That is not a problem though: parsing as number will fail
const number = Number(value);

@@ -39,0 +42,0 @@ return !isNaN(number) ? number : value;

@@ -239,3 +239,6 @@ (function (global, factory) {

function parseUnescapedValue(value) {
if (value[0] >= '0' && value[0] <= '9') {
if (value[0] >= '-' && value[0] <= '9') {
// a number can start with one of the following characters: 01234567890.-
// the range above contains these characters, but also the forward slash /.
// That is not a problem though: parsing as number will fail
const number = Number(value);

@@ -242,0 +245,0 @@ return !isNaN(number) ? number : value;

2

lib/umd/csv42.min.js

@@ -1,1 +0,1 @@

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).csv42={})}(this,function(n){"use strict";function r(n,e){let t=n,r=0;for(;r<e.length&&void 0!==t;)t=t?.[e[r]],r++;return t}function h(n,e,t){let r=n;var o=e.length-1;let i=0;for(;i<o;){var u=e[i];void 0===r[u]&&("number"==typeof e[i+1]?r[u]=[]:r[u]={}),r=r[u],i++}return r[e[o]]=t,n}function c(n){return"object"==typeof n&&null!==n&&n.constructor===Object}function t(n){return n.map((n,e)=>"number"==typeof n?"["+n+"]":/[.\[\]]/.test(n)||""===n?'["'+n+'"]':(0<e?".":"")+n).join("")}function p(t){var n,e,r=[];let o=0;for(;o<t.length;)"."===t[o]&&o++,"["===t[o]?(o++,'"'===t[o]?(o++,r.push(i(n=>'"'===n)),u('"')):(n=i(n=>"]"===n),e=Number(n),r.push(isNaN(e)?n:e)),u("]")):r.push(i(n=>"."===n||"["===n));function i(n){for(var e=o;o<t.length&&!n(t[o]);)o++;return t.substring(e,o)}function u(n){if(t[o]!==n)throw new SyntaxError(`Invalid JSON path: ${n} expected at position `+o);o++}return r}function l(n,e){return o(n,e).map(n=>({name:t(n),getValue:function(e){if(1!==e.length)return n=>r(n,e);{const t=e[0];return n=>n[t]}}(n)}))}const i=Symbol();function o(n,e){const t={};n.forEach(n=>{e(n)||c(n)?function n(e,t,r){for(const o in e){const i=e[o],u=t[o]||(t[o]=Array.isArray(i)?[]:{});r(i)?n(i,u,r):a(i,u)}}(n,t,e):a(n,t)});n=[];return function t(n,r,o){if(!0===n[i]||null===n[i]&&u(n))o.push(r);else if(Array.isArray(n))n.forEach((n,e)=>t(n,r.concat(e),o));else if(c(n))for(const e in n)t(n[e],r.concat(e),o)}(t,[],n),n}function a(n,e){void 0===e[i]&&(e[i]=null!=n||null)}function u(n){return 0===Object.keys(n).length}function s(n){const r=new RegExp("["+n+'"\r\n]'),o=/"/g;return function n(e){var t;return"string"==typeof e?(t=e,r.test(t)||0===t.length?`"${t.replaceAll(o,'""')}"`:t):"number"==typeof e||"boolean"==typeof e?e+"":null==e?"":n(JSON.stringify(e))}}function g(n){var e;return 0===n.length?null:"0"<=(n=y(n))[0]&&n[0]<="9"?(e=Number(n),isNaN(e)?n:e):"true"===n||"false"!==n&&("null"!==n?"{"!==n[0]&&"["!==n[0]?n:JSON.parse(n):null)}const e=/""/g;function y(n){return'"'===n[0]?n.substring(1,n.length-1).replaceAll(e,'"'):n}function m(n){if(1!==n.length)throw new Error(`Invalid delimiter: must be a single character but is "${n}"`);return n}function v(n,e){return A(n,e)||b(n,e)}function A(n,e){return n.charCodeAt(e)===f}function b(n,e){return n.charCodeAt(e)===d&&n.charCodeAt(e+1)===f}const f=10,d=13;n.collectNestedPaths=o,n.createFormatValue=s,n.csv2json=function(r,n){const o=!1!==n?.header,i=m(n?.delimiter||",").charCodeAt(0),u=34;var e=n?.parseValue||g,t=[];let a=0;var f,c=function(){const t=[];s((n,e)=>{t.push(o?String(n):"Field "+e)},y),o||(a=0);return t}();const l=n?.fields?function(n,e){var t,r=[];for(t of e){var o=void 0!==t.index?t.index:n.indexOf(t.name);if(-1===o)throw new Error(`Field "${t.name}" not found in the csv data`);if(r[o])throw new Error("Duplicate field for index "+o);r[o]=t}return r}(c,Array.isArray(n?.fields)?n?.fields:n?.fields(c)):(f=!1!==n?.nested,c.map(t=>{const r=p(t),o=r[0];return{name:t,setValue:0!==r.length&&f?1===r.length?(n,e)=>n[o]=e:(n,e)=>h(n,r,e):(n,e)=>n[t]=e}}));for(;a<r.length;){const d={};s((n,e)=>{l[e]?.setValue(d,n)},e),t.push(d)}return t;function s(n,e){let t=0;for(;a<r.length&&!v(r,a);)n(function(n){var e=a;if(r.charCodeAt(a)===u){do{for(a++;r.charCodeAt(a)===u&&r.charCodeAt(a+1)===u;)a+=2}while(a<r.length&&r.charCodeAt(a)!==u);if(r.charCodeAt(a)!==u)throw new Error('Unexpected end: end quote " missing');a++}else for(;a<r.length&&r.charCodeAt(a)!==i&&!v(r,a);)a++;return n(r.substring(e,a))}(e),t),t++,r.charCodeAt(a)===i&&a++;A(r,a)?a++:b(r,a)&&(a+=2)}},n.getIn=r,n.isObject=c,n.isObjectOrArray=function(n){return c(n)||Array.isArray(n)},n.json2csv=function(e,n){var t=!1!==n?.header;const r=m(n?.delimiter||",");var o=function(n){if(v(n,0))return n;throw new Error('Invalid EOL character: choose "\\n" or "\\r\\n"')}(n?.eol||"\r\n"),i="function"==typeof n?.flatten?n?.flatten:!1===n?.flatten?()=>!1:c;const u=n?.fields?Array.isArray(n?.fields)?n?.fields:n?.fields(e):l(e,i),a=n?.formatValue||s(r);let f="";t&&(f+=u.map(n=>a(n.name)).join(r)+o);for(let n=0;n<e.length;n++)f+=function(e){return u.map(n=>a(n.getValue(e))).join(r)}(e[n])+o;return f},n.parsePath=p,n.parseValue=g,n.setIn=h,n.stringifyPath=t,n.unescapeValue=y});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).csv42={})}(this,function(n){"use strict";function r(n,e){let t=n,r=0;for(;r<e.length&&void 0!==t;)t=t?.[e[r]],r++;return t}function h(n,e,t){let r=n;var o=e.length-1;let i=0;for(;i<o;){var u=e[i];void 0===r[u]&&("number"==typeof e[i+1]?r[u]=[]:r[u]={}),r=r[u],i++}return r[e[o]]=t,n}function c(n){return"object"==typeof n&&null!==n&&n.constructor===Object}function t(n){return n.map((n,e)=>"number"==typeof n?"["+n+"]":/[.\[\]]/.test(n)||""===n?'["'+n+'"]':(0<e?".":"")+n).join("")}function p(t){var n,e,r=[];let o=0;for(;o<t.length;)"."===t[o]&&o++,"["===t[o]?(o++,'"'===t[o]?(o++,r.push(i(n=>'"'===n)),u('"')):(n=i(n=>"]"===n),e=Number(n),r.push(isNaN(e)?n:e)),u("]")):r.push(i(n=>"."===n||"["===n));function i(n){for(var e=o;o<t.length&&!n(t[o]);)o++;return t.substring(e,o)}function u(n){if(t[o]!==n)throw new SyntaxError(`Invalid JSON path: ${n} expected at position `+o);o++}return r}function l(n,e){return o(n,e).map(n=>({name:t(n),getValue:function(e){if(1!==e.length)return n=>r(n,e);{const t=e[0];return n=>n[t]}}(n)}))}const i=Symbol();function o(n,e){const t={};n.forEach(n=>{e(n)||c(n)?function n(e,t,r){for(const o in e){const i=e[o],u=t[o]||(t[o]=Array.isArray(i)?[]:{});r(i)?n(i,u,r):a(i,u)}}(n,t,e):a(n,t)});n=[];return function t(n,r,o){if(!0===n[i]||null===n[i]&&u(n))o.push(r);else if(Array.isArray(n))n.forEach((n,e)=>t(n,r.concat(e),o));else if(c(n))for(const e in n)t(n[e],r.concat(e),o)}(t,[],n),n}function a(n,e){void 0===e[i]&&(e[i]=null!=n||null)}function u(n){return 0===Object.keys(n).length}function s(n){const r=new RegExp("["+n+'"\r\n]'),o=/"/g;return function n(e){var t;return"string"==typeof e?(t=e,r.test(t)||0===t.length?`"${t.replaceAll(o,'""')}"`:t):"number"==typeof e||"boolean"==typeof e?e+"":null==e?"":n(JSON.stringify(e))}}function g(n){var e;return 0===n.length?null:"-"<=(n=y(n))[0]&&n[0]<="9"?(e=Number(n),isNaN(e)?n:e):"true"===n||"false"!==n&&("null"!==n?"{"!==n[0]&&"["!==n[0]?n:JSON.parse(n):null)}const e=/""/g;function y(n){return'"'===n[0]?n.substring(1,n.length-1).replaceAll(e,'"'):n}function m(n){if(1!==n.length)throw new Error(`Invalid delimiter: must be a single character but is "${n}"`);return n}function v(n,e){return A(n,e)||b(n,e)}function A(n,e){return n.charCodeAt(e)===f}function b(n,e){return n.charCodeAt(e)===d&&n.charCodeAt(e+1)===f}const f=10,d=13;n.collectNestedPaths=o,n.createFormatValue=s,n.csv2json=function(r,n){const o=!1!==n?.header,i=m(n?.delimiter||",").charCodeAt(0),u=34;var e=n?.parseValue||g,t=[];let a=0;var f,c=function(){const t=[];s((n,e)=>{t.push(o?String(n):"Field "+e)},y),o||(a=0);return t}();const l=n?.fields?function(n,e){var t,r=[];for(t of e){var o=void 0!==t.index?t.index:n.indexOf(t.name);if(-1===o)throw new Error(`Field "${t.name}" not found in the csv data`);if(r[o])throw new Error("Duplicate field for index "+o);r[o]=t}return r}(c,Array.isArray(n?.fields)?n?.fields:n?.fields(c)):(f=!1!==n?.nested,c.map(t=>{const r=p(t),o=r[0];return{name:t,setValue:0!==r.length&&f?1===r.length?(n,e)=>n[o]=e:(n,e)=>h(n,r,e):(n,e)=>n[t]=e}}));for(;a<r.length;){const d={};s((n,e)=>{l[e]?.setValue(d,n)},e),t.push(d)}return t;function s(n,e){let t=0;for(;a<r.length&&!v(r,a);)n(function(n){var e=a;if(r.charCodeAt(a)===u){do{for(a++;r.charCodeAt(a)===u&&r.charCodeAt(a+1)===u;)a+=2}while(a<r.length&&r.charCodeAt(a)!==u);if(r.charCodeAt(a)!==u)throw new Error('Unexpected end: end quote " missing');a++}else for(;a<r.length&&r.charCodeAt(a)!==i&&!v(r,a);)a++;return n(r.substring(e,a))}(e),t),t++,r.charCodeAt(a)===i&&a++;A(r,a)?a++:b(r,a)&&(a+=2)}},n.getIn=r,n.isObject=c,n.isObjectOrArray=function(n){return c(n)||Array.isArray(n)},n.json2csv=function(e,n){var t=!1!==n?.header;const r=m(n?.delimiter||",");var o=function(n){if(v(n,0))return n;throw new Error('Invalid EOL character: choose "\\n" or "\\r\\n"')}(n?.eol||"\r\n"),i="function"==typeof n?.flatten?n?.flatten:!1===n?.flatten?()=>!1:c;const u=n?.fields?Array.isArray(n?.fields)?n?.fields:n?.fields(e):l(e,i),a=n?.formatValue||s(r);let f="";t&&(f+=u.map(n=>a(n.name)).join(r)+o);for(let n=0;n<e.length;n++)f+=function(e){return u.map(n=>a(n.getValue(e))).join(r)}(e[n])+o;return f},n.parsePath=p,n.parseValue=g,n.setIn=h,n.stringifyPath=t,n.unescapeValue=y});
{
"name": "csv42",
"version": "3.0.0",
"version": "3.0.1",
"description": "A small and fast CSV parser with support for nested JSON",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc