Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blo

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blo - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

dist/random.d.ts

6

dist/image.d.ts

@@ -1,5 +0,5 @@

import type { BloImage, BloImageData, Hsl } from "./types";
export declare function image(seed: string): BloImage;
import type { Address, BloImage, BloImageData, Hsl } from "./types";
export declare function image(address: Address): BloImage;
export declare function randomImageData(random: () => number): BloImageData;
export declare function randomPalette(random: () => number): [Hsl, Hsl, Hsl];
export declare function randomColor(rand: () => number): Hsl;
export declare function seedRandom(seed: string): () => number;

@@ -1,66 +0,74 @@

function s(o) {
const t = u(o), n = f(t), r = f(t), i = f(t);
return [
c(t),
[r, n, i]
];
function h(n) {
const t = d(n);
return function() {
const e = t[0] ^ t[0] << 11;
return t[0] = t[1], t[1] = t[2], t[2] = t[3], t[3] = t[3] ^ t[3] >> 19 ^ e ^ e >> 8, (t[3] >>> 0) / (1 << 31 >>> 0);
};
}
function c(o) {
function d(n) {
const t = new Uint32Array([0, 0, 0, 0]);
for (let o = 0; o < n.length; o++)
t[o % 4] = (t[o % 4] << 5) - t[o % 4] + n.charCodeAt(o);
return t;
}
function g(n) {
const t = h(n.toLowerCase()), o = $(t);
return [m(t), o];
}
function m(n) {
const t = new Uint8Array(32);
for (let n = 0; n < 32; n++)
t[
// row
Math.floor(n / 4) * 4 + n % 4
] = Math.floor(
for (let o = 0; o < 32; o++)
t[o] = Math.floor(
// background: 43% chances
// color: 43% chances
// spot: 13% chances
o() * 2.3
n() * 2.3
);
return t;
}
function f(o) {
function $(n) {
const t = u(n), o = u(n), e = u(n);
return [o, t, e];
}
function u(n) {
return new Uint16Array([
// hue = 0 to 360 (whole color spectrum)
Math.floor(o() * 360),
n() * 360,
// saturation = 40 to 100 (avoid greyish colors)
Math.floor(40 + o() * 60),
40 + n() * 60,
// lightness = 0 to 100 but probabilities are a bell curve around 50%
Math.floor((o() + o() + o() + o()) * 25)
(n() + n() + n() + n()) * 25
]);
}
function u(o) {
const t = $(o);
return function() {
const r = t[0] ^ t[0] << 11;
return t[0] = t[1], t[1] = t[2], t[2] = t[3], t[3] = t[3] ^ t[3] >> 19 ^ r ^ r >> 8, (t[3] >>> 0) / (1 << 31 >>> 0);
};
const w = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" shape-rendering="optimizeSpeed" ';
function p(n, t) {
const o = h(n.toLowerCase()), [e, s, c] = $(o), r = [
"M0,0H8V8H0z",
// background
"",
// color
""
// spot
];
for (let a = 0, i, l; a < 32; a++) {
i = a % 4, l = Math.floor(a / 4);
const f = Math.floor(o() * 2.3);
f > 0 && (r[f] += `M${i},${l}h1v1h-1zM${7 - i},${l}h1v1h-1z`);
}
return `${w}width="${t}" height="${t}"><path fill="hsl(${e[0]} ${e[1]}% ${e[2]}%)" d="${r[0]}"/><path fill="hsl(${s[0]} ${s[1]}% ${s[2]}%)" d="${r[1]}"/><path fill="hsl(${c[0]} ${c[1]}% ${c[2]}%)" d="${r[2]}"/></svg>`;
}
function $(o) {
const t = new Uint32Array([0, 0, 0, 0]);
for (let n = 0; n < o.length; n++)
t[n % 4] = (t[n % 4] << 5) - t[n % 4] + o.charCodeAt(n);
return t;
function b(n, t = 64) {
return "data:image/svg+xml;base64," + btoa(v(n, t));
}
const g = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" shape-rendering="optimizeSpeed" ', m = "</svg>";
function d([o, [t, n, r]], i) {
const l = ["", ""];
for (let e = 0, a, h; e < o.length; e++)
o[e] && ([a, h] = [e % 4, Math.floor(e / 4)], l[o[e] - 1] += `M${a},${h}h1v1h-1zM${7 - a},${h}h1v1h-1z`);
return g + `width="${i}" height="${i}"><path fill="hsl(${t[0]} ${t[1]}% ${t[2]}%)" d="M0,0H8V8H0z"/><path fill="hsl(${n[0]} ${n[1]}% ${n[2]}%)" d="${l[0]}"/><path fill="hsl(${r[0]} ${r[1]}% ${r[2]}%)" d="${l[1]}"/>` + m;
function v(n, t = 64) {
return p(n, t);
}
function v(o, t = 64) {
return "data:image/svg+xml;base64," + btoa(w(o, t));
function x(n) {
return g(n);
}
function w(o, t = 64) {
return d(p(o), t);
}
function p(o) {
return s(o.toLowerCase());
}
export {
v as blo,
p as bloImage,
w as bloSvg
b as blo,
x as bloImage,
v as bloSvg
};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import type { BloImage } from "./types";
export declare function toSvg([data, [b, c, s]]: BloImage, size: number): string;
import type { Address } from "./types";
export declare function svg(address: Address, size: number): string;
{
"name": "blo",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -46,9 +46,6 @@ "author": "Pierre Bertet <hi@bpier.re>",

"scripts": {
"dev": "vite demo",
"demo-cli": "cd demo-cli && bun start",
"dev": "vite ./demos/react",
"build": "tsc && vite build",
"bench-cli": "vitest bench benchmark",
"bench-browser": "vite dev benchmark",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
}
}
<div align="center">
<img width="860" alt="blo" src="https://github.com/bpierre/blo/assets/36158/1ada9bc9-c8d4-4ed6-8bf6-3a70cefce880">
<img width="860" alt="blo" src="https://github.com/bpierre/blo/assets/36158/7ddc0bf0-076d-4c5a-8624-cc8646e4c5aa">
<br><strong>blo</strong> is a small and fast library to generate Ethereum identicons.

@@ -12,3 +12,3 @@ <br><br>

- 🐥 **Small**: **[0.67 KB](https://bundlejs.com/?bundle&q=blo)** gzipped.
- ☄️ **Fast**: **[4.7x faster](#library-comparison)** than the second fastest solution.
- 💥 **Fast**: **[3.5x faster](#library-comparison)** than the second fastest solution.
- 🔍 **Optimized**: Leverages SVG to generate compact and sharp images at any size.

@@ -22,9 +22,10 @@ - 💆 **Simple**: Focuses on Ethereum identicons only, allowing for a simpler API.

| Library | Renders/sec[^1] | Size | Types | Environment[^2] | Rendering |
| ------------------------------------- | --------------------------: | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ---------------------------------------------- | ----------: |
| <b>blo</b> | <nobr><b>☄️ 7,862</b></nobr> | [![](https://img.shields.io/badge/0.67kB-6ead0a)](https://bundlejs.com/?bundle&q=blo) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/all-6ead0a) | SVG |
| <nobr>ethereum-blockies-base64</nobr> | 948 | [![](https://img.shields.io/badge/2.75kB-ee4433)](https://bundlejs.com/?bundle&q=ethereum-blockies-base64) | ![](https://img.shields.io/badge/no-ee4433) | ![](https://img.shields.io/badge/all-6ead0a) | PNG |
| <nobr>@download/blockies</nobr> | 361 | [![](https://img.shields.io/badge/0.67kB-6ead0a)](https://bundlejs.com/?bundle&q=%6ead0a%2Fblockies) | ![](https://img.shields.io/badge/no-ee4433) | ![](https://img.shields.io/badge/dom-ee4433) | Canvas |
| <nobr>blockies-react-svg</nobr> | 1,675 | [![](https://img.shields.io/badge/4kB-ee4433)](https://bundlejs.com/?bundle&q=blockies-react-svg) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/react-ee4433) | SVG (React) |
| <nobr>blockies-ts</nobr> | 381 | [![](https://img.shields.io/badge/1.31kB-6ead0a)](https://bundlejs.com/?bundle&q=blockies-ts) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/dom-ee4433) | Canvas |
| Library | Renders/sec[^1] | Size | Types | Environment[^2] | Rendering |
| ------------------------------------- | ---------------------------: | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ---------------------------------------------- | --------: |
| <b>blo</b> | <nobr><b>💥 8,197</b></nobr> | [![](https://img.shields.io/badge/0.67kB-6ead0a)](https://bundlejs.com/?bundle&q=blo) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/all-6ead0a) | SVG |
| <nobr>ethereum-blockies-base64</nobr> | 807 | [![](https://img.shields.io/badge/2.75kB-ee4433)](https://bundlejs.com/?bundle&q=ethereum-blockies-base64) | ![](https://img.shields.io/badge/no-ee4433) | ![](https://img.shields.io/badge/all-6ead0a) | PNG |
| <nobr>blockies-react-svg</nobr> | 1,749 | [![](https://img.shields.io/badge/4kB-ee4433)](https://bundlejs.com/?bundle&q=blockies-react-svg) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/react-ee4433) | SVG |
| <nobr>@download/blockies</nobr> | 334 | [![](https://img.shields.io/badge/0.67kB-6ead0a)](https://bundlejs.com/?bundle&q=%6ead0a%2Fblockies) | ![](https://img.shields.io/badge/no-ee4433) | ![](https://img.shields.io/badge/dom-ee4433) | Canvas |
| <nobr>blockies-ts</nobr> | 342 | [![](https://img.shields.io/badge/1.31kB-6ead0a)](https://bundlejs.com/?bundle&q=blockies-ts) | ![](https://img.shields.io/badge/yes-6ead0a) | ![](https://img.shields.io/badge/dom-ee4433) | Canvas |
| <nobr>react-blockies</nobr> | 2,361 | [![](https://img.shields.io/badge/4.72kB-ee4433)](https://bundlejs.com/?bundle&q=react-blockies) | ![](https://img.shields.io/badge/no-ee4433) | ![](https://img.shields.io/badge/react-ee4433) | Canvas |

@@ -108,3 +109,3 @@ [^1]: The number of renders per second. It was measured on Chrome 117 Linux with an AMD Ryzen 7 PRO 4750U. [See ./benchmark](./benchmark) for the methodology.

```ts
// The data structure needed to render an icon.
// BloImage contains the data needed to render an icon.
export type BloImage = [BloImageData, Palette];

@@ -149,7 +150,7 @@

blo is short for blockies, which is the name of the original library.
blo is short for blockies, which is the name of [the original library](https://github.com/ethereum/blockies) it is based on.
### Can it be used to generate other types of identicons?
blo implements the Ethereum identicons algorithm only, but you can use it with any type of data, just prefix it with `0x` to fullfill the `Address` type.
blo only focuses on the Ethereum identicons algorithm but you can use it with any data, just prefix it with `0x` to fullfill the expected `Address` type if you are using TypeScript.

@@ -156,0 +157,0 @@ ## License

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc