uti 8.4.0 → 8.5.0

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/README.md CHANGED
@@ -52,9 +52,11 @@ public.plain-text
52
52
  * [Properties](#properties)
53
53
  * [conformsTo](#conformsto)
54
54
  * [Parameters](#parameters-1)
55
+ * [toString](#tostring)
55
56
  * [toJSON](#tojson)
56
57
  * [UTIController](#uticontroller)
57
58
  * [Properties](#properties-1)
59
+ * [registry](#registry)
58
60
  * [utiByMimeType](#utibymimetype)
59
61
  * [utiByFileNameExtension](#utibyfilenameextension)
60
62
  * [register](#register)
@@ -69,6 +71,10 @@ public.plain-text
69
71
  * [Parameters](#parameters-6)
70
72
  * [fileNameConformsTo](#filenameconformsto)
71
73
  * [Parameters](#parameters-7)
74
+ * [assignMimeTypes](#assignmimetypes)
75
+ * [Parameters](#parameters-8)
76
+ * [assignExtensions](#assignextensions)
77
+ * [Parameters](#parameters-9)
72
78
 
73
79
  ## UTI
74
80
 
@@ -94,6 +100,12 @@ Check for conformity.
94
100
 
95
101
  Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if other conforms to the receiver
96
102
 
103
+ ### toString
104
+
105
+ name of the UTI.
106
+
107
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
108
+
97
109
  ### toJSON
98
110
 
99
111
  Deliver JSON representation of the UTI.
@@ -106,7 +118,7 @@ Sample result
106
118
  }
107
119
  ```
108
120
 
109
- Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** json representation of the UTI
121
+ Returns **{name: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), conforms: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>}** json representation of the UTI
110
122
 
111
123
  ## UTIController
112
124
 
@@ -118,6 +130,10 @@ Registry of UTIs.
118
130
  * `utiByMimeType` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [UTI](#uti)>**&#x20;
119
131
  * `utiByFileNameExtension` **[Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [UTI](#uti)>**&#x20;
120
132
 
133
+ ### registry
134
+
135
+ Type: [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [UTI](#uti)>
136
+
121
137
  ### utiByMimeType
122
138
 
123
139
  Type: [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>>
@@ -142,7 +158,7 @@ Lookup a given UTI.
142
158
 
143
159
  * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** UTI
144
160
 
145
- Returns **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** UTI for the given name or undefined if UTI is not present.
161
+ Returns **([UTI](#uti) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** UTI for the given name or undefined if UTI is not present.
146
162
 
147
163
  ### getUTIsForMimeType
148
164
 
@@ -189,6 +205,24 @@ Lookup a UTI for a file name and check conformance.
189
205
 
190
206
  Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** ture if utils for file name are conformant
191
207
 
208
+ ### assignMimeTypes
209
+
210
+ Assign mime types to a UTI
211
+
212
+ #### Parameters
213
+
214
+ * `uti` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
215
+ * `mimeTypes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
216
+
217
+ ### assignExtensions
218
+
219
+ Assign mime types to a UTI
220
+
221
+ #### Parameters
222
+
223
+ * `uti` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
224
+ * `extensions` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
225
+
192
226
  # install
193
227
 
194
228
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uti",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -26,26 +26,27 @@
26
26
  ],
27
27
  "license": "BSD-2-Clause",
28
28
  "scripts": {
29
- "prepare": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs",
29
+ "prepare": "npm run prepare:typescript",
30
+ "prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule -t esnext -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
30
31
  "test": "npm run test:browser-ava && npm run test:ava",
31
32
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
32
33
  "test:browser-ava": "browser-ava --headless --no-keep-open tests/*-ava.mjs tests/*-ava-browser.mjs",
33
34
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
34
35
  "docs": "documentation readme --section=API ./src/**/*.mjs",
35
- "lint": "npm run lint:docs && npm run lint:tsc",
36
+ "lint": "npm run lint:docs && npm run lint:typescript",
36
37
  "lint:docs": "documentation lint ./src/**/*.mjs",
37
- "lint:tsc": "tsc --allowJs --checkJs --noEmit -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
38
+ "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
38
39
  },
39
40
  "devDependencies": {
40
- "ava": "^6.1.1",
41
- "browser-ava": "^2.2.0",
41
+ "ava": "^6.1.3",
42
+ "browser-ava": "^2.2.13",
42
43
  "c8": "^9.1.0",
43
44
  "documentation": "^14.0.3",
44
- "semantic-release": "^23.0.2",
45
- "typescript": "^5.3.3"
45
+ "semantic-release": "^23.1.1",
46
+ "typescript": "^5.4.5"
46
47
  },
47
48
  "engines": {
48
- "node": ">=20.11.1",
49
+ "node": ">=20.13.1",
49
50
  "bun": ">=1.0.0"
50
51
  },
51
52
  "repository": {
package/src/uti.mjs CHANGED
@@ -9,6 +9,14 @@ import types from "./well-known-utis.mjs";
9
9
  * @property {Set<UTI>} conforms
10
10
  */
11
11
  class UTI {
12
+ /**
13
+ * Object representing a UTI.
14
+ * @param {string} name
15
+ * @param {Set<UTI>} conforms
16
+ *
17
+ * @property {string} name
18
+ * @property {Set<UTI>} conforms
19
+ */
12
20
  constructor(name, conforms) {
13
21
  this.name = name;
14
22
  this.conforms = conforms;
@@ -32,6 +40,10 @@ class UTI {
32
40
  return false;
33
41
  }
34
42
 
43
+ /**
44
+ * name of the UTI.
45
+ * @returns {string}
46
+ */
35
47
  toString() {
36
48
  return this.name;
37
49
  }
@@ -45,7 +57,7 @@ class UTI {
45
57
  * "conformsTo": [ "uti1", "uti2"]
46
58
  * }
47
59
  * ```
48
- * @return {Object} json representation of the UTI
60
+ * @return {{name:string, conforms: string[]}} json representation of the UTI
49
61
  */
50
62
  toJSON() {
51
63
  return {
@@ -62,7 +74,7 @@ class UTI {
62
74
  * @property {Map<string,UTI>} utiByFileNameExtension
63
75
  */
64
76
  export class UTIController {
65
- registry = new Map();
77
+ /** @type {Map<string,UTI>} */ registry = new Map();
66
78
  /** @type {Map<string,string[]>} */ utiByMimeType = new Map();
67
79
  /** @type {Map<string,string[]>} */ utiByFileNameExtension = new Map();
68
80
 
@@ -116,7 +128,7 @@ export class UTIController {
116
128
  /**
117
129
  * Lookup a given UTI.
118
130
  * @param {string} name UTI
119
- * @return {string|undefined} UTI for the given name or undefined if UTI is not present.
131
+ * @return {UTI|undefined} UTI for the given name or undefined if UTI is not present.
120
132
  */
121
133
  getUTI(name) {
122
134
  return this.registry.get(name);
@@ -187,24 +199,34 @@ export class UTIController {
187
199
  return false;
188
200
  }
189
201
 
190
- assignMimeTypes(name, mimTypes) {
191
- mimTypes.forEach(type => {
202
+ /**
203
+ * Assign mime types to a UTI
204
+ * @param {string} uti
205
+ * @param {string[]} mimeTypes
206
+ */
207
+ assignMimeTypes(uti, mimeTypes) {
208
+ mimeTypes.forEach(type => {
192
209
  const u = this.utiByMimeType.get(type);
193
210
  if (u === undefined) {
194
- this.utiByMimeType.set(type, [name]);
211
+ this.utiByMimeType.set(type, [uti]);
195
212
  } else {
196
- u.push(name);
213
+ u.push(uti);
197
214
  }
198
215
  });
199
216
  }
200
217
 
201
- assignExtensions(name, extensions) {
218
+ /**
219
+ * Assign mime types to a UTI
220
+ * @param {string} uti
221
+ * @param {string[]} extensions
222
+ */
223
+ assignExtensions(uti, extensions) {
202
224
  extensions.forEach(ext => {
203
225
  const e = this.utiByFileNameExtension.get(ext);
204
226
  if (e === undefined) {
205
- this.utiByFileNameExtension.set(ext, [name]);
227
+ this.utiByFileNameExtension.set(ext, [uti]);
206
228
  } else {
207
- e.push(name);
229
+ e.push(uti);
208
230
  }
209
231
  });
210
232
  }
@@ -546,6 +546,18 @@ export default [
546
546
  fileNameExtension: [".md", ".markdown"],
547
547
  mimeType: "text/markdown"
548
548
  },
549
+ {
550
+ name: "public.jsx",
551
+ conformsTo: "public.source-code",
552
+ fileNameExtension: [".jsx"],
553
+ mimeType: "text/jsx"
554
+ },
555
+ {
556
+ name: "public.mdx",
557
+ conformsTo: ["net.daringfireball.markdown","public.jsx"],
558
+ fileNameExtension: [".mdx"],
559
+ mimeType: "text/mdx"
560
+ },
549
561
  {
550
562
  name: "com.apple.disk-image",
551
563
  conformsTo: "public.disk-image",
package/types/uti.d.mts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @property {Map<string,UTI>} utiByFileNameExtension
6
6
  */
7
7
  export class UTIController {
8
- registry: Map<any, any>;
8
+ /** @type {Map<string,UTI>} */ registry: Map<string, UTI>;
9
9
  /** @type {Map<string,string[]>} */ utiByMimeType: Map<string, string[]>;
10
10
  /** @type {Map<string,string[]>} */ utiByFileNameExtension: Map<string, string[]>;
11
11
  /**
@@ -16,9 +16,9 @@ export class UTIController {
16
16
  /**
17
17
  * Lookup a given UTI.
18
18
  * @param {string} name UTI
19
- * @return {string|undefined} UTI for the given name or undefined if UTI is not present.
19
+ * @return {UTI|undefined} UTI for the given name or undefined if UTI is not present.
20
20
  */
21
- getUTI(name: string): string | undefined;
21
+ getUTI(name: string): UTI | undefined;
22
22
  /**
23
23
  * Lookup a UTIs for a mime type.
24
24
  * @param {string} mimeType mime type to get UTIs for
@@ -48,6 +48,64 @@ export class UTIController {
48
48
  * @return {boolean} ture if utils for file name are conformant
49
49
  */
50
50
  fileNameConformsTo(fileName: string, uti: string): boolean;
51
- assignMimeTypes(name: any, mimTypes: any): void;
52
- assignExtensions(name: any, extensions: any): void;
51
+ /**
52
+ * Assign mime types to a UTI
53
+ * @param {string} uti
54
+ * @param {string[]} mimeTypes
55
+ */
56
+ assignMimeTypes(uti: string, mimeTypes: string[]): void;
57
+ /**
58
+ * Assign mime types to a UTI
59
+ * @param {string} uti
60
+ * @param {string[]} extensions
61
+ */
62
+ assignExtensions(uti: string, extensions: string[]): void;
63
+ }
64
+ /**
65
+ * Object representing a UTI.
66
+ * @param {string} name
67
+ * @param {Set<UTI>} conforms
68
+ *
69
+ * @property {string} name
70
+ * @property {Set<UTI>} conforms
71
+ */
72
+ declare class UTI {
73
+ /**
74
+ * Object representing a UTI.
75
+ * @param {string} name
76
+ * @param {Set<UTI>} conforms
77
+ *
78
+ * @property {string} name
79
+ * @property {Set<UTI>} conforms
80
+ */
81
+ constructor(name: string, conforms: Set<UTI>);
82
+ name: string;
83
+ conforms: Set<UTI>;
84
+ /**
85
+ * Check for conformity.
86
+ * @param {UTI} other
87
+ * @return {boolean} true if other conforms to the receiver
88
+ */
89
+ conformsTo(other: UTI): boolean;
90
+ /**
91
+ * name of the UTI.
92
+ * @returns {string}
93
+ */
94
+ toString(): string;
95
+ /**
96
+ * Deliver JSON representation of the UTI.
97
+ * Sample result
98
+ * ```json
99
+ * {
100
+ * "name": "myUTI",
101
+ * "conformsTo": [ "uti1", "uti2"]
102
+ * }
103
+ * ```
104
+ * @return {{name:string, conforms: string[]}} json representation of the UTI
105
+ */
106
+ toJSON(): {
107
+ name: string;
108
+ conforms: string[];
109
+ };
53
110
  }
111
+ export {};