|
40 | 40 | decode: Object.keys(baseEx), |
41 | 41 | }, |
42 | 42 | importType: "esm", |
43 | | - importTypes: ["esm", "node", "iife"], |
| 43 | + importTypes: ["esm", "node-esm", "node-cjs", "iife"], |
44 | 44 | }; |
45 | 45 | // Set the initial output |
46 | 46 | Data.output = baseEx[Data.curTypes.decode][Data.mode](Data.input, Data.curTypes.encode); |
|
262 | 262 | const use = (isBytes) ? "setting as default:" : "making use of default"; |
263 | 263 |
|
264 | 264 | // import types |
265 | | - const importComment = (this.importType !== "iife") ? `${this.importType}-module` : this.importType; |
| 265 | + const importComment = (this.importType.match(".*esm")) ? `${this.importType}-module` : this.importType; |
266 | 266 | let importStatement; |
267 | | - let iife = ""; |
| 267 | + let scopeVar = ""; |
268 | 268 | let note = "// Note:\n// - It is not necessary to import both modules\n// (use only what you need)"; |
269 | 269 | if (this.importType === "esm") { |
270 | 270 | importStatement = `import { ${subFNName}, BaseEx } from "./path/BaseEx.esm.min.js";`; |
271 | 271 | note += "\n// - remember to adjust the import path"; |
272 | | - } else if (this.importType === "node") { |
| 272 | + } else if (this.importType === "node-esm") { |
273 | 273 | importStatement = `import { ${subFNName}, BaseEx } from "base-ex";`; |
| 274 | + } else if (this.importType === "node-cjs") { |
| 275 | + importStatement = `const BaseEx = require("base-ex");`; |
| 276 | + scopeVar = "BaseEx."; |
| 277 | + note = ""; |
274 | 278 | } else { |
275 | | - iife = "BaseEx."; |
| 279 | + scopeVar = "BaseEx."; |
276 | 280 | importStatement = `// use the following line as your script tag:\n// <script src="path/BaseEx.iise.min.js"></script>`; |
277 | 281 | note = "// Note:\n// - remember to adjust the path in your script tag"; |
278 | 282 | } |
|
288 | 292 | const input = ${input.replace("<", "<").replace(">", ">")}; |
289 | 293 |
|
290 | 294 | // Main class BaseEx |
291 | | -const baseExA = new ${iife}BaseEx(); |
| 295 | +const baseExA = new ${scopeVar}BaseEx(); |
292 | 296 | const outputA = baseExA.${this.curTypes.decode}.${this.mode}(input, "${this.curTypes.encode}"); |
293 | 297 |
|
294 | 298 | // Main class BaseEx, ${use} ${this.curTypes.encode}-type |
295 | | -const baseExB = new ${iife}BaseEx(${fixedType.substr(2)}); |
| 299 | +const baseExB = new ${scopeVar}BaseEx(${fixedType.substr(2)}); |
296 | 300 | const outputB = baseExB.${this.curTypes.decode}.${this.mode}(input); |
297 | 301 |
|
298 | 302 | // Direct use of the required base converter |
299 | | -const ${this.curTypes.decode}A = new ${iife}${subFNName}(${version}); |
| 303 | +const ${this.curTypes.decode}A = new ${scopeVar}${subFNName}(${version}); |
300 | 304 | const outputC = ${this.curTypes.decode}A.${this.mode}(input, "${this.curTypes.encode}"); |
301 | 305 |
|
302 | 306 | // Direct use of the base converter, ${use} ${this.curTypes.encode}-type |
303 | | -const ${this.curTypes.decode}B = new ${iife}${subFNName}("${baseEx[this.curTypes.decode].version}"${fixedType}); |
| 307 | +const ${this.curTypes.decode}B = new ${scopeVar}${subFNName}("${baseEx[this.curTypes.decode].version}"${fixedType}); |
304 | 308 | const outputD = ${this.curTypes.decode}B.${this.mode}(input); |
305 | 309 |
|
306 | 310 | // ${copyPasteInfo} |
|
393 | 397 | } |
394 | 398 | #code-section select { |
395 | 399 | width: auto; |
396 | | - margin: 0; |
| 400 | + margin: 0 0 0 1rem; |
397 | 401 | } |
398 | 402 | footer { |
399 | 403 | text-align: right; |
|
0 commit comments