• This repository has been archived on 10/May/2022
  • Stars
    star
    273
  • Rank 150,286 (Top 3 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created almost 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IChing-JS

An IChing encoding and decoding library written in typescript for use in javascript-based web apps.

Installation

Clone the repository and run npm install --no-save followed by npm run build.

Node.js

The Node.js files can be found in ./lib/esm5 after building.

Javascript

This library can be used in javascript by including ./lib/umd/index.min.js as script source.

Usage

Encoding

IChing-JS library exports a method iching.encode(payload, options?).

Arguments

  • payload - A string of alphanumeric characters that is the desired payload of the IChing.
  • options (optional) - Additional options:
    • ecLevel - Error correction level, a number between 0 and 1 representing the maximum percentage of errors that can be corrected, relative to the payload length. Defaults to Encoder.EC_MEDIUM (0.15).
    • resolution - A number representing the width and height of the square image produced by the method. Defaults to 1250.
    • roundEdges - A boolean determining whether the symbols' edges in the output image are straight or round. Defaults to false, which means straight edges.
    • inverted - A boolean determining whether the output image is inverted, i.e. white on black instead of black on white. Defaults to false.

Return Value

If the encoding process succeeds, the method will return an object that implements the EncodedIChing interface.

Example

Example usage with options specified:

const payload = "thisisanexample123";
const options = { ecLevel: 0.5, resolution: 2000, roundEdges: true, inverted: false };
const encoded = iching.encode(payload, options);

Or without options:

const payload = "thisisanexample123";
const encoded = iching.encode(payload);

Which is equivalent to:

const payload = "thisisanexample123";
const defaultOptions = { ecLevel: 0.15, resolution: 1250, roundEdges: false, inevrted: false };
const encoded = iching.encode(payload, defaultOptions);

Image can be displayed using HTML canvas:

// 'cvs' and 'ctx' are an HTML canvas element, and its 2D rendering context, respectively.
const imgData = encoded.imageData;
cvs.width = imgData.width;
cvs.height = imgData.height;
const ctxImgData = new ImageData(imgData.data, imgData.width, imgData.height);
ctx.putImageData(ctxImgData, 0, 0);

// If 'img' is an HTML image element, its 'src' attribute can be set like follows:
img.src = cvs.toDataURL();

Decoding

IChing-JS library exports a method iching.decode(imageData, width, height).

Arguments

  • imageData - A Uint8ClampedArray of RGBA pixel values in the form [r0, g0, b0, a0, r1, g1, b1, a1, ...]. The length of this array should be 4 * width * height.
  • width - The width of the image to be decoded.
  • height - The height of the image to be decoded.

Return value

If the decoding process succeeds, the method will return an object that implements the DecodedIChing interface.

Example

Example usage:

// Let 'width' and 'height' be the width and height of the input image, respectively,
// and 'imageData' be a Uint8ClampedArray of RGBA pixel values, and of length 4 * width * height.
const decoded = iching.decode(imageData, width, height);
console.log(decoded.version, decoded.size);
console.log(decoded.data);

Documentation

Detailed HTML docs can be found here.

License

IChing-JS is released under the GPLv3 license.
Copyright Β© Nodle

More Repositories

1

chain

A repo for the Nodle blockchain node β›“
Rust
186
star
2

nodlesdk-quickstart-android

Quickstart for the latest NodleSDK on Android
Kotlin
19
star
3

substrate-client-kotlin

Substrate RPC-client implementation made in pure Kotlin.
Kotlin
16
star
4

docs.nodle.com

JavaScript
14
star
5

nodlesdk-quickstart-ios

Quickstart for the latest NodleSDK on iOS
Swift
11
star
6

n1

C
11
star
7

dtn7-kotlin

Delay-tolerant networking software suite for Kotlin, Bundle Protocol Version 7
Kotlin
10
star
8

action-try-runtime

Dockerfile
7
star
9

libwhisper-android

Android implementation of the Whisper Tracing protocol https://www.coalitionnetwork.org/
Kotlin
6
star
10

NodleSDK-Release

Repository that contains release build and podspec of NodleSDK
Objective-C
4
star
11

nodle-rosetta-server

TypeScript
3
star
12

subquery

Nodle's subquery-based API server
TypeScript
3
star
13

smart-mission-contracts

A library of smart contract samples for smart missions
Rust
2
star
14

nodle4stakers

Quick start utility scripts & guide to run nodle staker validator's node.
Shell
2
star
15

nodlesdk-unity

ShaderLab
2
star
16

action-cargo-source

Source container for GH action action-cargo
Dockerfile
2
star
17

action-cargo

Github action packed with a docker image
1
star
18

chain-loadtest

TypeScript
1
star
19

PKI

Rust
1
star
20

users-marketcap-ratio

Rust
1
star
21

busypot

This tool offers a mix of useful commands for interacting with Nodle parachain or any other compatible substrate based parachain. The commands specially include propose-xcm which allows a member of technical committee to propose a native transaction on the relay chain on behalf of Nodle.
Rust
1
star
22

rosetta-typescript-sdk

TypeScript
1
star
23

rollup

Nodle Network on zkSync/EVM
Solidity
1
star