@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/index.js CHANGED
@@ -1853,29 +1853,33 @@ function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateB
1853
1853
  }
1854
1854
 
1855
1855
  // src/dataURItoBlob.ts
1856
- function dataURItoBlob(dataURI) {
1857
- const splitted = dataURI.split(",");
1858
- const params = splitted[0].split(";");
1859
- const type = params[0].replace("data:", "");
1860
- const properties = params.filter((param) => {
1861
- return param.split("=")[0] === "name";
1862
- });
1863
- let name;
1864
- if (properties.length !== 1) {
1865
- name = "unknown";
1866
- } else {
1867
- name = decodeURI(properties[0].split("=")[1]);
1868
- }
1856
+ function dataURItoBlob(dataURILike) {
1857
+ if (dataURILike.indexOf("data:") === -1) {
1858
+ throw new Error("File is invalid: URI must be a dataURI");
1859
+ }
1860
+ const dataURI = dataURILike.slice(5);
1861
+ const splitted = dataURI.split(";base64,");
1862
+ if (splitted.length !== 2) {
1863
+ throw new Error("File is invalid: dataURI must be base64");
1864
+ }
1865
+ const [media, base64] = splitted;
1866
+ const [mime, ...mediaparams] = media.split(";");
1867
+ const type = mime || "";
1868
+ const name = decodeURI(
1869
+ // parse the parameters into key-value pairs, find a key, and extract a value
1870
+ // if no key is found, then the name is unknown
1871
+ mediaparams.map((param) => param.split("=")).find(([key]) => key === "name")?.[1] || "unknown"
1872
+ );
1869
1873
  try {
1870
- const binary = atob(splitted[1]);
1871
- const array = [];
1874
+ const binary = atob(base64);
1875
+ const array = new Array(binary.length);
1872
1876
  for (let i = 0; i < binary.length; i++) {
1873
- array.push(binary.charCodeAt(i));
1877
+ array[i] = binary.charCodeAt(i);
1874
1878
  }
1875
1879
  const blob = new window.Blob([new Uint8Array(array)], { type });
1876
1880
  return { blob, name };
1877
1881
  } catch (error) {
1878
- return { blob: { size: 0, type: error.message }, name: dataURI };
1882
+ throw new Error("File is invalid: " + error.message);
1879
1883
  }
1880
1884
  }
1881
1885
 
@@ -1906,7 +1910,7 @@ var import_isEqual4 = __toESM(require("lodash/isEqual"));
1906
1910
  // src/enumOptionsValueForIndex.ts
1907
1911
  function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
1908
1912
  if (Array.isArray(valueIndex)) {
1909
- return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val);
1913
+ return valueIndex.map((index2) => enumOptionsValueForIndex(index2, allEnumOptions)).filter((val) => val !== emptyValue);
1910
1914
  }
1911
1915
  const index = valueIndex === "" || valueIndex === null ? -1 : Number(valueIndex);
1912
1916
  const option = allEnumOptions[index];