Skip to content

Commit

Permalink
Added named exports for browser and node implementation (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmester committed Aug 7, 2022
1 parent 1941a06 commit 6dc9ba9
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 1 deletion.
4 changes: 4 additions & 0 deletions browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../dist/jdenticon-module",
"types": "../types/module.d.ts"
}
4 changes: 4 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "../dist/jdenticon-node",
"types": "../types/module.d.ts"
}
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
},
"default": "./dist/jdenticon-node.js"
},
"./browser": {
"types": "./types/module.d.ts",
"import": "./dist/jdenticon-module.mjs",
"default": "./dist/jdenticon-module.js"
},
"./node": {
"types": "./types/module.d.ts",
"import": "./dist/jdenticon-node.mjs",
"default": "./dist/jdenticon-node.js"
},
"./standalone": {
"types": "./types/umd.d.ts",
"default": "./dist/jdenticon.min.js"
Expand Down Expand Up @@ -93,6 +103,8 @@
"bin/",
"dist/",
"standalone/",
"browser/",
"node/",
"types/*.d.ts"
],
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/rollup/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ import { testBrowser } from "../base-browser-test";
import * as jdenticonEsm from "jdenticon";
testBrowser(jdenticonEsm, "browser-esm");

import * as jdenticonEsmBrowser from "jdenticon/browser";
testBrowser(jdenticonEsmBrowser, "browser-esm");

import * as jdenticonEsmNode from "jdenticon/node";
testBrowser(jdenticonEsmNode, "node-esm");

import * as jdenticonUmd from "jdenticon/standalone";
testBrowser(jdenticonUmd, "browser-umd");
4 changes: 4 additions & 0 deletions test/e2e/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export default {
output: {
file: "./app.bundle.js",
format: "iife",
globals: {
"canvas-renderer": "{}",
},
},
external: ["canvas-renderer"],
plugins: [
commonjs(),
nodeResolve({
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/webpack/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ import { testBrowser } from "../base-browser-test";
import * as jdenticonEsm from "jdenticon";
testBrowser(jdenticonEsm, "browser-esm");

import * as jdenticonEsmBrowser from "jdenticon/browser";
testBrowser(jdenticonEsmBrowser, "browser-esm");

import * as jdenticonEsmNode from "jdenticon/node";
testBrowser(jdenticonEsmNode, "node-esm");

import * as jdenticonUmd from "jdenticon/standalone";
testBrowser(jdenticonUmd, "browser-umd");
testBrowser(jdenticonUmd, "browser-umd");
59 changes: 59 additions & 0 deletions test/types/module-browser/module-test-explicit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { configure, drawIcon, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/browser";

const newConfig: JdenticonConfig = {
lightness: {
color: [0.40, 0.80],
grayscale: [0.30, 0.90]
},
saturation: {
color: 0.50,
grayscale: 0.00
},
hues: [45, 677],
padding: 0.3,
replaceMode: "observe",
backColor: "#86444400"
};

const oldConfig: JdenticonConfig = {
lightness: {
color: [0.4, 0.8],
grayscale: [0.3, 0.9]
},
saturation: 0.5
};

window.jdenticon_config = oldConfig;

configure(oldConfig);

toPng("value to hash", 100);
toSvg("value to hash", 100);

toPng("value to hash", 100, 0.08);
toSvg("value to hash", 100, 0.08);

toPng("value to hash", 100, newConfig);
toSvg("value to hash", 100, newConfig);

var el = document.createElement("canvas");
update(el, "value");
update(el, "value", 0.08);
update(el, "value", newConfig);
update("#selector", "value");
update("#selector", "value", 0.08);
update("#selector", "value", newConfig);

updateSvg("#selector", "value", newConfig);
updateCanvas("#selector", "value", newConfig);

var ctx = el.getContext("2d");
if (ctx) {
drawIcon(ctx, "value", 100);
drawIcon(ctx, "value", 100, 0.08);
drawIcon(ctx, "value", 100, newConfig);
}

// Ensure Jdenticon dodn't leak Node typings.
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
const timeoutRef: number = setTimeout(() => { }, 100);
47 changes: 47 additions & 0 deletions test/types/module-node14/module-test-explicit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/node";

const newConfig: JdenticonConfig = {
lightness: {
color: [0.40, 0.80],
grayscale: [0.30, 0.90]
},
saturation: {
color: 0.50,
grayscale: 0.00
},
hues: [45, 677],
padding: 0.3,
replaceMode: "observe",
backColor: "#86444400"
};

const oldConfig: JdenticonConfig = {
lightness: {
color: [0.4, 0.8],
grayscale: [0.3, 0.9]
},
saturation: 0.5
};

configure(oldConfig);

toPng("value to hash", 100);
toSvg("value to hash", 100);

toPng("value to hash", 100, 0.08);
toSvg("value to hash", 100, 0.08);

const buffer: Buffer = toPng("value to hash", 100, newConfig);

toSvg("value to hash", 100, newConfig);

// Check that Node typings are loaded
buffer.swap64();

update("#selector", "value");
update("#selector", "value", 0.08);
update("#selector", "value", newConfig);

updateSvg("#selector", "value", newConfig);
updateCanvas("#selector", "value", newConfig);

47 changes: 47 additions & 0 deletions test/types/module-node16/module-test-explicit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/node";

const newConfig: JdenticonConfig = {
lightness: {
color: [0.40, 0.80],
grayscale: [0.30, 0.90]
},
saturation: {
color: 0.50,
grayscale: 0.00
},
hues: [45, 677],
padding: 0.3,
replaceMode: "observe",
backColor: "#86444400"
};

const oldConfig: JdenticonConfig = {
lightness: {
color: [0.4, 0.8],
grayscale: [0.3, 0.9]
},
saturation: 0.5
};

configure(oldConfig);

toPng("value to hash", 100);
toSvg("value to hash", 100);

toPng("value to hash", 100, 0.08);
toSvg("value to hash", 100, 0.08);

const buffer: Buffer = toPng("value to hash", 100, newConfig);

toSvg("value to hash", 100, newConfig);

// Check that Node typings are loaded
buffer.swap64();

update("#selector", "value");
update("#selector", "value", 0.08);
update("#selector", "value", newConfig);

updateSvg("#selector", "value", newConfig);
updateCanvas("#selector", "value", newConfig);

0 comments on commit 6dc9ba9

Please sign in to comment.