@ztimson/utils 0.28.14 → 0.28.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -773,6 +773,9 @@ ${opts.message || this.desc}`;
773
773
  const pascal = pascalCase(str);
774
774
  return pascal.charAt(0).toLowerCase() + pascal.slice(1);
775
775
  }
776
+ function decodeHtml(html) {
777
+ return html.replace(/&nbsp;/g, " ").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&cent;/g, "¢").replace(/&pound;/g, "£").replace(/&yen;/g, "¥").replace(/&euro;/g, "€").replace(/&copy;/g, "©").replace(/&reg;/g, "®").replace(/&trade;/g, "™").replace(/&times;/g, "×").replace(/&divide;/g, "÷").replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec)).replace(/&#x([0-9a-fA-F]+);/g, (match, hex) => String.fromCharCode(parseInt(hex, 16))).replace(/&amp;/g, "&");
778
+ }
776
779
  function formatBytes(bytes, decimals = 2) {
777
780
  if (bytes === 0) return "0 Bytes";
778
781
  const k = 1024;
@@ -943,27 +946,42 @@ ${opts.message || this.desc}`;
943
946
  function fromCsv(csv, hasHeaders = true) {
944
947
  function parseLine(line) {
945
948
  const columns = [];
946
- let current = "", inQuotes2 = false;
949
+ let current = "", inQuotes2 = false, quoteChar2 = null;
947
950
  for (let i = 0; i < line.length; i++) {
948
951
  const char = line[i];
949
952
  const nextChar = line[i + 1];
950
- if (char === '"') {
951
- if (inQuotes2 && nextChar === '"') {
952
- current += '"';
953
+ if ((char === '"' || char === "'") && !inQuotes2) {
954
+ inQuotes2 = true;
955
+ quoteChar2 = char;
956
+ } else if (char === quoteChar2 && inQuotes2) {
957
+ if (nextChar === quoteChar2) {
958
+ current += quoteChar2;
953
959
  i++;
954
- } else inQuotes2 = !inQuotes2;
960
+ } else {
961
+ inQuotes2 = false;
962
+ quoteChar2 = null;
963
+ }
955
964
  } else if (char === "," && !inQuotes2) {
956
965
  columns.push(current.trim());
957
966
  current = "";
958
967
  } else current += char;
959
968
  }
960
969
  columns.push(current.trim());
961
- return columns.map((col) => col.replace(/^"|"$/g, "").replace(/""/g, '"'));
970
+ return columns.map((col) => {
971
+ col = col.replace(/^["']|["']$/g, "");
972
+ return col.replace(/""/g, '"').replace(/''/g, "'");
973
+ });
962
974
  }
963
975
  const rows = [];
964
- let currentRow = "", inQuotes = false;
976
+ let currentRow = "", inQuotes = false, quoteChar = null;
965
977
  for (const char of csv.replace(/\r\n/g, "\n")) {
966
- if (char === '"') inQuotes = !inQuotes;
978
+ if ((char === '"' || char === "'") && !inQuotes) {
979
+ inQuotes = true;
980
+ quoteChar = char;
981
+ } else if (char === quoteChar && inQuotes) {
982
+ inQuotes = false;
983
+ quoteChar = null;
984
+ }
967
985
  if (char === "\n" && !inQuotes) {
968
986
  rows.push(currentRow.trim());
969
987
  currentRow = "";
@@ -3039,6 +3057,7 @@ ${err.message || err.toString()}`);
3039
3057
  exports2.dayOfYear = dayOfYear;
3040
3058
  exports2.dec2Frac = dec2Frac;
3041
3059
  exports2.dec2Hex = dec2Hex;
3060
+ exports2.decodeHtml = decodeHtml;
3042
3061
  exports2.decodeJwt = decodeJwt;
3043
3062
  exports2.deepCopy = deepCopy;
3044
3063
  exports2.deepMerge = deepMerge;