@rjsf/utils 5.16.1 → 5.17.1

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/utils.esm.js CHANGED
@@ -1718,29 +1718,33 @@ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateB
1718
1718
  }
1719
1719
 
1720
1720
  // src/dataURItoBlob.ts
1721
- function dataURItoBlob(dataURI) {
1722
- const splitted = dataURI.split(",");
1723
- const params = splitted[0].split(";");
1724
- const type = params[0].replace("data:", "");
1725
- const properties = params.filter((param) => {
1726
- return param.split("=")[0] === "name";
1727
- });
1728
- let name;
1729
- if (properties.length !== 1) {
1730
- name = "unknown";
1731
- } else {
1732
- name = decodeURI(properties[0].split("=")[1]);
1733
- }
1721
+ function dataURItoBlob(dataURILike) {
1722
+ if (dataURILike.indexOf("data:") === -1) {
1723
+ throw new Error("File is invalid: URI must be a dataURI");
1724
+ }
1725
+ const dataURI = dataURILike.slice(5);
1726
+ const splitted = dataURI.split(";base64,");
1727
+ if (splitted.length !== 2) {
1728
+ throw new Error("File is invalid: dataURI must be base64");
1729
+ }
1730
+ const [media, base64] = splitted;
1731
+ const [mime, ...mediaparams] = media.split(";");
1732
+ const type = mime || "";
1733
+ const name = decodeURI(
1734
+ // parse the parameters into key-value pairs, find a key, and extract a value
1735
+ // if no key is found, then the name is unknown
1736
+ mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
1737
+ );
1734
1738
  try {
1735
- const binary = atob(splitted[1]);
1736
- const array = [];
1739
+ const binary = atob(base64);
1740
+ const array = new Array(binary.length);
1737
1741
  for (let i = 0; i < binary.length; i++) {
1738
- array.push(binary.charCodeAt(i));
1742
+ array[i] = binary.charCodeAt(i);
1739
1743
  }
1740
1744
  const blob = new window.Blob([new Uint8Array(array)], { type });
1741
1745
  return { blob, name };
1742
1746
  } catch (error) {
1743
- return { blob: { size: 0, type: error.message }, name: dataURI };
1747
+ throw new Error("File is invalid: " + error.message);
1744
1748
  }
1745
1749
  }
1746
1750
 
@@ -1771,7 +1775,7 @@ import isEqual4 from "lodash/isEqual";
1771
1775
  // src/enumOptionsValueForIndex.ts
1772
1776
  function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
1773
1777
  if (Array.isArray(valueIndex)) {
1774
- return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
1778
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val !== emptyValue);
1775
1779
  }
1776
1780
  const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
1777
1781
  const option = allEnumOptions[index];