@sanity/util 6.23.0-next.7 → 6.24.0-next.8
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/lib/accepts.d.ts +22 -0
- package/lib/accepts.js +28 -0
- package/lib/accepts.js.map +1 -0
- package/package.json +8 -4
package/lib/accepts.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
4
|
+
*
|
|
5
|
+
* Inspired by https://github.com/enyo/dropzone (MIT) (c) 2021 Matias Meno
|
|
6
|
+
* Based on https://github.com/react-dropzone/attr-accept (MIT) (c) 2015 Andrey Okonetchnikov
|
|
7
|
+
*
|
|
8
|
+
* Diverges from attr-accept in one case: when the accept entry is an extension (e.g. `.pdf`)
|
|
9
|
+
* and the file has no name, this returns `true` (fail open). Browsers omit the file name while
|
|
10
|
+
* hovering a file over an input and only provide it on drop, so failing closed would incorrectly
|
|
11
|
+
* reject files during hover.
|
|
12
|
+
*
|
|
13
|
+
* @param file - https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
14
|
+
* @param acceptedFiles - List of accepted mime types (comma-separated string or array)
|
|
15
|
+
* @returns True if file is accepted, false otherwise
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function accepts(file: {
|
|
19
|
+
type: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
}, acceptedFiles: string | string[]): boolean;
|
|
22
|
+
//# sourceMappingURL=accepts.d.ts.map
|
package/lib/accepts.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the provided file type should be accepted by the input with accept attribute.
|
|
3
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept
|
|
4
|
+
*
|
|
5
|
+
* Inspired by https://github.com/enyo/dropzone (MIT) (c) 2021 Matias Meno
|
|
6
|
+
* Based on https://github.com/react-dropzone/attr-accept (MIT) (c) 2015 Andrey Okonetchnikov
|
|
7
|
+
*
|
|
8
|
+
* Diverges from attr-accept in one case: when the accept entry is an extension (e.g. `.pdf`)
|
|
9
|
+
* and the file has no name, this returns `true` (fail open). Browsers omit the file name while
|
|
10
|
+
* hovering a file over an input and only provide it on drop, so failing closed would incorrectly
|
|
11
|
+
* reject files during hover.
|
|
12
|
+
*
|
|
13
|
+
* @param file - https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
14
|
+
* @param acceptedFiles - List of accepted mime types (comma-separated string or array)
|
|
15
|
+
* @returns True if file is accepted, false otherwise
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function accepts(file, acceptedFiles) {
|
|
19
|
+
if (!file || !acceptedFiles) return !0;
|
|
20
|
+
let acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(","), fileName = file.name || "", mimeType = (file.type || "").toLowerCase(), baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
21
|
+
return acceptedFilesArray.some((type) => {
|
|
22
|
+
let validType = type.trim().toLowerCase();
|
|
23
|
+
return validType.charAt(0) === "." ? !fileName || fileName.toLowerCase().endsWith(validType) : validType.endsWith("/*") ? baseMimeType === validType.replace(/\/.*$/, "") : mimeType === validType;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { accepts };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=accepts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accepts.js","names":[],"sources":["../src/accepts/accepts.ts"],"sourcesContent":["/**\n * Check if the provided file type should be accepted by the input with accept attribute.\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept\n *\n * Inspired by https://github.com/enyo/dropzone (MIT) (c) 2021 Matias Meno\n * Based on https://github.com/react-dropzone/attr-accept (MIT) (c) 2015 Andrey Okonetchnikov\n *\n * Diverges from attr-accept in one case: when the accept entry is an extension (e.g. `.pdf`)\n * and the file has no name, this returns `true` (fail open). Browsers omit the file name while\n * hovering a file over an input and only provide it on drop, so failing closed would incorrectly\n * reject files during hover.\n *\n * @param file - https://developer.mozilla.org/en-US/docs/Web/API/File\n * @param acceptedFiles - List of accepted mime types (comma-separated string or array)\n * @returns True if file is accepted, false otherwise\n * @internal\n */\nexport function accepts(\n file: {type: string; name?: string},\n acceptedFiles: string | string[],\n): boolean {\n if (!file || !acceptedFiles) {\n return true\n }\n\n const acceptedFilesArray = Array.isArray(acceptedFiles)\n ? acceptedFiles // eg `['image/png', 'image/jpeg']`\n : acceptedFiles.split(',') // eg `image/png,image/jpeg`\n\n const fileName = file.name || ''\n const mimeType = (file.type || '').toLowerCase()\n const baseMimeType = mimeType.replace(/\\/.*$/, '')\n\n return acceptedFilesArray.some((type) => {\n const validType = type.trim().toLowerCase()\n\n if (validType.charAt(0) === '.') {\n if (fileName) {\n return fileName.toLowerCase().endsWith(validType)\n }\n return true\n }\n\n if (validType.endsWith('/*')) {\n // This is something like a image/* mime type\n return baseMimeType === validType.replace(/\\/.*$/, '')\n }\n\n return mimeType === validType\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,QACd,MACA,eACS;CACT,IAAI,CAAC,QAAQ,CAAC,eACZ,OAAO;CAGT,IAAM,qBAAqB,MAAM,QAAQ,aAAa,IAClD,gBACA,cAAc,MAAM,GAAG,GAErB,WAAW,KAAK,QAAQ,IACxB,YAAY,KAAK,QAAQ,GAAA,CAAI,YAAY,GACzC,eAAe,SAAS,QAAQ,SAAS,EAAE;CAEjD,OAAO,mBAAmB,MAAM,SAAS;EACvC,IAAM,YAAY,KAAK,KAAK,CAAC,CAAC,YAAY;EAc1C,OAZI,UAAU,OAAO,CAAC,MAAM,MAC1B,CAAI,YACK,SAAS,YAAY,CAAC,CAAC,SAAS,SAAS,IAKhD,UAAU,SAAS,IAAI,IAElB,iBAAiB,UAAU,QAAQ,SAAS,EAAE,IAGhD,aAAa;CACtB,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/util",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.24.0-next.8",
|
|
4
4
|
"description": "Utilities shared across projects of Sanity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"types": "./lib/index.d.ts",
|
|
30
30
|
"typesVersions": {
|
|
31
31
|
"*": {
|
|
32
|
+
"accepts": [
|
|
33
|
+
"./lib/accepts.d.ts"
|
|
34
|
+
],
|
|
32
35
|
"fs": [
|
|
33
36
|
"./lib/fs.d.ts"
|
|
34
37
|
],
|
|
@@ -54,6 +57,7 @@
|
|
|
54
57
|
},
|
|
55
58
|
"exports": {
|
|
56
59
|
".": "./lib/index.js",
|
|
60
|
+
"./accepts": "./lib/accepts.js",
|
|
57
61
|
"./client": "./lib/client.js",
|
|
58
62
|
"./concurrency-limiter": "./lib/concurrency-limiter.js",
|
|
59
63
|
"./content": "./lib/content.js",
|
|
@@ -66,10 +70,10 @@
|
|
|
66
70
|
"dependencies": {
|
|
67
71
|
"@date-fns/tz": "^1.5.0",
|
|
68
72
|
"@date-fns/utc": "^2.1.1",
|
|
69
|
-
"@sanity/client": "^8.
|
|
70
|
-
"@sanity/types": "6.
|
|
73
|
+
"@sanity/client": "^8.15.1",
|
|
74
|
+
"@sanity/types": "6.24.0-next.8+56f09b0b4e",
|
|
71
75
|
"date-fns": "^4.4.0",
|
|
72
|
-
"get-it": "^9.
|
|
76
|
+
"get-it": "^9.7.0",
|
|
73
77
|
"rxjs": "^7.8.2"
|
|
74
78
|
},
|
|
75
79
|
"devDependencies": {
|