| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 800dbb6 commit 50adcca
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1160,25 +1160,26 @@ condition list **must** be passed through to the `defaultResolve` function. | |||
| 1160 | 1160 | ```js | |
| 1161 | 1161 | /** | |
| 1162 | 1162 | * @param {string} specifier | |
| 1163 | - * @param {object} context | ||
| 1164 | - * @param {string} context.parentURL | ||
| 1165 | - * @param {string[]} context.conditions | ||
| 1166 | - * @param {function} defaultResolve | ||
| 1167 | - * @returns {object} response | ||
| 1168 | - * @returns {string} response.url | ||
| 1163 | + * @param {{ | ||
| 1164 | + * parentURL: !(string | undefined), | ||
| 1165 | + * conditions: !(Array<string>), | ||
| 1166 | + * }} context | ||
| 1167 | + * @param {Function} defaultResolve | ||
| 1168 | + * @returns {!(Promise<{ url: string }>)} | ||
| 1169 | 1169 | */ | |
| 1170 | 1170 | export async function resolve(specifier, context, defaultResolve) { | |
| 1171 | 1171 | const { parentURL = null } = context; | |
| 1172 | - if (someCondition) { | ||
| 1172 | + if (Math.random() > 0.5) { // Some condition. | ||
| 1173 | 1173 | // For some or all specifiers, do some custom logic for resolving. | |
| 1174 | - // Always return an object of the form {url: <string>} | ||
| 1174 | + // Always return an object of the form {url: <string>}. | ||
| 1175 | 1175 | return { | |
| 1176 | - url: (parentURL) ? | ||
| 1177 | - new URL(specifier, parentURL).href : new URL(specifier).href | ||
| 1176 | + url: parentURL ? | ||
| 1177 | + new URL(specifier, parentURL).href : | ||
| 1178 | + new URL(specifier).href, | ||
| 1178 | 1179 | }; | |
| 1179 | 1180 | } | |
| 1180 | - if (anotherCondition) { | ||
| 1181 | - // When calling the defaultResolve, the arguments can be modified. In this | ||
| 1181 | + if (Math.random() < 0.5) { // Another condition. | ||
| 1182 | + // When calling `defaultResolve`, the arguments can be modified. In this | ||
| 1182 | 1183 | // case it's adding another value for matching conditional exports. | |
| 1183 | 1184 | return defaultResolve(specifier, { | |
| 1184 | 1185 | ...context, | |
@@ -1220,18 +1221,17 @@ not a string, it will be converted to a string using [`util.TextDecoder`][]. | |||
| 1220 | 1221 | ```js | |
| 1221 | 1222 | /** | |
| 1222 | 1223 | * @param {string} url | |
| 1223 | - * @param {object} context (currently empty) | ||
| 1224 | - * @param {function} defaultGetFormat | ||
| 1225 | - * @returns {object} response | ||
| 1226 | - * @returns {string} response.format | ||
| 1224 | + * @param {Object} context (currently empty) | ||
| 1225 | + * @param {Function} defaultGetFormat | ||
| 1226 | + * @returns {Promise<{ format: string }>} | ||
| 1227 | 1227 | */ | |
| 1228 | 1228 | export async function getFormat(url, context, defaultGetFormat) { | |
| 1229 | - if (someCondition) { | ||
| 1229 | + if (Math.random() > 0.5) { // Some condition. | ||
| 1230 | 1230 | // For some or all URLs, do some custom logic for determining format. | |
| 1231 | 1231 | // Always return an object of the form {format: <string>}, where the | |
| 1232 | 1232 | // format is one of the strings in the table above. | |
| 1233 | 1233 | return { | |
| 1234 | - format: 'module' | ||
| 1234 | + format: 'module', | ||
| 1235 | 1235 | }; | |
| 1236 | 1236 | } | |
| 1237 | 1237 | // Defer to Node.js for all other URLs. | |
@@ -1251,19 +1251,17 @@ potentially avoid reading files from disk. | |||
| 1251 | 1251 | ```js | |
| 1252 | 1252 | /** | |
| 1253 | 1253 | * @param {string} url | |
| 1254 | - * @param {object} context | ||
| 1255 | - * @param {string} context.format | ||
| 1256 | - * @param {function} defaultGetSource | ||
| 1257 | - * @returns {object} response | ||
| 1258 | - * @returns {string|buffer} response.source | ||
| 1254 | + * @param {{ format: string }} context | ||
| 1255 | + * @param {Function} defaultGetSource | ||
| 1256 | + * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>} | ||
| 1259 | 1257 | */ | |
| 1260 | 1258 | export async function getSource(url, context, defaultGetSource) { | |
| 1261 | 1259 | const { format } = context; | |
| 1262 | - if (someCondition) { | ||
| 1260 | + if (Math.random() > 0.5) { // Some condition. | ||
| 1263 | 1261 | // For some or all URLs, do some custom logic for retrieving the source. | |
| 1264 | 1262 | // Always return an object of the form {source: <string|buffer>}. | |
| 1265 | 1263 | return { | |
| 1266 | - source: '...' | ||
| 1264 | + source: '...', | ||
| 1267 | 1265 | }; | |
| 1268 | 1266 | } | |
| 1269 | 1267 | // Defer to Node.js for all other URLs. | |
@@ -1286,28 +1284,25 @@ unknown-to-Node.js file extensions. See the [transpiler loader example][] below. | |||
| 1286 | 1284 | ||
| 1287 | 1285 | ```js | |
| 1288 | 1286 | /** | |
| 1289 | - * @param {string|buffer} source | ||
| 1290 | - * @param {object} context | ||
| 1291 | - * @param {string} context.url | ||
| 1292 | - * @param {string} context.format | ||
| 1293 | - * @param {function} defaultTransformSource | ||
| 1294 | - * @returns {object} response | ||
| 1295 | - * @returns {string|buffer} response.source | ||
| 1287 | + * @param {!(SharedArrayBuffer | string | Uint8Array)} source | ||
| 1288 | + * @param {{ | ||
| 1289 | + * url: string, | ||
| 1290 | + * format: string, | ||
| 1291 | + * }} context | ||
| 1292 | + * @param {Function} defaultTransformSource | ||
| 1293 | + * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>} | ||
| 1296 | 1294 | */ | |
| 1297 | - export async function transformSource(source, | ||
| 1298 | - context, | ||
| 1299 | - defaultTransformSource) { | ||
| 1295 | + export async function transformSource(source, context, defaultTransformSource) { | ||
| 1300 | 1296 | const { url, format } = context; | |
| 1301 | - if (someCondition) { | ||
| 1297 | + if (Math.random() > 0.5) { // Some condition. | ||
| 1302 | 1298 | // For some or all URLs, do some custom logic for modifying the source. | |
| 1303 | 1299 | // Always return an object of the form {source: <string|buffer>}. | |
| 1304 | 1300 | return { | |
| 1305 | - source: '...' | ||
| 1301 | + source: '...', | ||
| 1306 | 1302 | }; | |
| 1307 | 1303 | } | |
| 1308 | 1304 | // Defer to Node.js for all other sources. | |
| 1309 | - return defaultTransformSource( | ||
| 1310 | - source, context, defaultTransformSource); | ||
| 1305 | + return defaultTransformSource(source, context, defaultTransformSource); | ||
| 1311 | 1306 | } | |
| 1312 | 1307 | ``` | |
| 1313 | 1308 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments