New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

excepturiest

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

excepturiest

A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps

latest
Source
npmnpm
Version
1.1.4
Version published
Maintainers
1
Created
Source

core

npm npm bundle size (minified + gzip) no external dependencies

core is a string mapping library. The idea behind this package was to give customization to almost everything in the library, therefore almost any piece of code depends of constants (More on it later on).

Basic usage

Without any customizations, core can be used as is.

const sentence = 'abc';
const cipher = 'def';
const { encode, decode } = core({
  mappings: {
    a: 'd',
    b: 'e',
    c: 'f',
  },
});

encode(sentence);
// Returns 'def'

decode(cipher);
// Returns 'abc'

encode & decode

encode is a function returned from calling core function. It takes a string to encode and optionally a configuration object. So far, the configuration object consists of one field called throwOnUnknownCharacters, which is boolean value. The name is quite descriptive, during encoding if there's no suitable mapping for a character, then the error would be thrown. If you don't wanna throw error on unknown characters, set this option to false (It's true by defualt).

decode is almost the same with this distinction that, it will use reversed mappings and it will throw if there's no matching character for a ciphertext. The option name is the same: throwOnUnknownCharacters.

Customization

core has many optional configuration fields, really useful especially when dealing with things such as morse code package. The core library has the following options.

type CoreOptions = {
  mappings: Record<string, string>;
  ciphertextWordsSeparator?: string;
  ciphertextCharactersSeparator?: string;
  plaintextWordsSeparator?: string;
  plaintextCharactersSeparator?: string;
};

plaintextWordsSeparator & plaintextCharactersSeparator

These options specify the library should divide a string to encode it. The core library will split the input string by plaintextWordsSeparator and then it will split words to characters by plaintextCharactersSeparator. The last step is mapping character to ciphertext. You can control these parameters to your desire. By default plaintextWordsSeparator is a single space and a plaintextCharactersSeparator is an empty string ``.

ciphertextWordsSeparator & ciphertextCharactersSeparator

During encoding after the characters are mapped to cipher, the cipher is joined, firstly by a ciphertextCharactersSeparator and then by ciphertextWordsSeparator. Decoding is reversed process.

Take a look for a example for a better understanding.

const sentence = 's o m e / s t r a n g e / f e a t u r e';
const notReallyACipher = 'some strange feature';

// ceaser is using core under the hood
const { encode, decode } = caesar({
  encryptionOffset: 0,
  plaintextWordsSeparator: ' / ',
  plaintextCharactersSeparator: ' ',
  ciphertextWordsSeparator: ' ',
  ciphertextCharactersSeparator: '',
});

encode(sentence);
// Returns 'some strange feature'

decode(notReallyACipher);
// Returns 's o m e / s t r a n g e / f e a t u r e'

Keywords

consequatur

FAQs

Package last updated on 03 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts