Skip to content

Commit

Permalink
Merge pull request #5 from UmamiAppearance/v0.3.0
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
UmamiAppearance authored Sep 28, 2021
2 parents 7e1d645 + a6a4d48 commit 70d1c42
Show file tree
Hide file tree
Showing 11 changed files with 1,156 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BaseEx.code-workspace
dist
dist/*
!dist/BaseEx.cjs.js
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm](https://img.shields.io/npm/v/base-ex?color=%23009911&style=for-the-badge)](https://www.npmjs.com/package/base-ex)


**BaseEx** is a collection of classes for data representation from Base16 (hex) to BasE91.
**BaseEx** is a collection of classes for data representation from Base16 (hex) to basE91.
BaseEx is completely standalone and works client and server side.
There are other good solutions for e.g. Base32, Base64, Base85, but BaseEx has them all in one place.
The **Ex** in the name stands for **Ex**ponent (of n) or - as read out loud - for an **X**.
Expand All @@ -30,7 +30,7 @@ git clone https://github.com/UmamiAppearance/BaseExJS.git
nmp install base-ex
```

## Build
## Builds
The GitHub repository has ready to use builds included. You can find them in [dist](https://github.com/UmamiAppearance/BaseExJS/tree/main/dist). The npm package comes without pre build files.

For building you have to run:
Expand Down Expand Up @@ -71,11 +71,16 @@ import {Base32} from "./path/BaseEx.esm.min.js"

#### Node
```js
// ESM6 Module

// main class
import {BaseEx} from "base-ex"

// explicit converter (e.g. Base32)
import {Base32} from "base-ex"
// explicit converter (e.g. Base64)
import {Base64} from "base-ex"

// CommonJS
const BaseEx = require("base-ex");
```

#### Available imports Browser/Node
Expand All @@ -86,6 +91,8 @@ The **classic import** via script tag has them all available without further ado
* ...
* ``BaseEx.BaseEx``

The same goes for the CommonJS import from Node. The only difference is, that the scope is not necessarily named ``BaseEx``, as this is defined by the user (``const myName = require("base-ex") --> myName.Base16...``).

Full **import** for **ES6** modules:

```js
Expand Down
24 changes: 14 additions & 10 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
decode: Object.keys(baseEx),
},
importType: "esm",
importTypes: ["esm", "node", "iife"],
importTypes: ["esm", "node-esm", "node-cjs", "iife"],
};
// Set the initial output
Data.output = baseEx[Data.curTypes.decode][Data.mode](Data.input, Data.curTypes.encode);
Expand Down Expand Up @@ -262,17 +262,21 @@
const use = (isBytes) ? "setting as default:" : "making use of default";

// import types
const importComment = (this.importType !== "iife") ? `${this.importType}-module` : this.importType;
const importComment = (this.importType.match(".*esm")) ? `${this.importType}-module` : this.importType;
let importStatement;
let iife = "";
let scopeVar = "";
let note = "// Note:\n// - It is not necessary to import both modules\n// (use only what you need)";
if (this.importType === "esm") {
importStatement = `import { ${subFNName}, BaseEx } from "./path/BaseEx.esm.min.js";`;
note += "\n// - remember to adjust the import path";
} else if (this.importType === "node") {
} else if (this.importType === "node-esm") {
importStatement = `import { ${subFNName}, BaseEx } from "base-ex";`;
} else if (this.importType === "node-cjs") {
importStatement = `const BaseEx = require("base-ex");`;
scopeVar = "BaseEx.";
note = "";
} else {
iife = "BaseEx.";
scopeVar = "BaseEx.";
importStatement = `// use the following line as your script tag:\n// <script src="path/BaseEx.iise.min.js"></script>`;
note = "// Note:\n// - remember to adjust the path in your script tag";
}
Expand All @@ -288,19 +292,19 @@
const input = ${input.replace("<", "&lt;").replace(">", "&gt;")};
// Main class BaseEx
const baseExA = new ${iife}BaseEx();
const baseExA = new ${scopeVar}BaseEx();
const outputA = baseExA.${this.curTypes.decode}.${this.mode}(input, "${this.curTypes.encode}");
// Main class BaseEx, ${use} ${this.curTypes.encode}-type
const baseExB = new ${iife}BaseEx(${fixedType.substr(2)});
const baseExB = new ${scopeVar}BaseEx(${fixedType.substr(2)});
const outputB = baseExB.${this.curTypes.decode}.${this.mode}(input);
// Direct use of the required base converter
const ${this.curTypes.decode}A = new ${iife}${subFNName}(${version});
const ${this.curTypes.decode}A = new ${scopeVar}${subFNName}(${version});
const outputC = ${this.curTypes.decode}A.${this.mode}(input, "${this.curTypes.encode}");
// Direct use of the base converter, ${use} ${this.curTypes.encode}-type
const ${this.curTypes.decode}B = new ${iife}${subFNName}("${baseEx[this.curTypes.decode].version}"${fixedType});
const ${this.curTypes.decode}B = new ${scopeVar}${subFNName}("${baseEx[this.curTypes.decode].version}"${fixedType});
const outputD = ${this.curTypes.decode}B.${this.mode}(input);
// ${copyPasteInfo}
Expand Down Expand Up @@ -393,7 +397,7 @@
}
#code-section select {
width: auto;
margin: 0;
margin: 0 0 0 1rem;
}
footer {
text-align: right;
Expand Down
Loading

0 comments on commit 70d1c42

Please sign in to comment.