npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stega-toolkit

v1.1.1

Published

Steganography Utility functions

Downloads

30

Readme

stega-toolkit

A set of steganography utility functions for embedding JSON data in text

Version License Build Status

Table of Contents

Installation

npm install stega-toolkit

API

combine(params)

This method combines a string with some JSON data and returns the result. The JSON data can be any value that can be JSON stringified. When the skip property is true, the original string will be returned without combining the JSON data. It supports boolean values and 'auto'. The default is 'auto', which will only skip encoding when the string is an ISO date string or a URL. If the encodeDates option is true, Date objects in the JSON data will be converted to ISO date strings before being combined with the text.

Parameters

  • params (Object)
    • text (string): The text to combine with the JSON data.
    • dataToEncode (Record<string, any> | string): The JSON data to combine with the text.
    • options (Object): Options for the combine function.
      • skip (boolean | string): Whether to skip combining the JSON data with the text. Defaults to 'auto'.
      • encodeDates (boolean): Whether to encode dates. Defaults to false.

Returns

  • (string): The combined text and JSON data, encoded as a string.

Example

import { combine } from 'stega-toolkit';

let combined = combine({
  text: 'Hello, World!',
  dataToEncode: { name: 'John', age: 30, city: 'New York' },
  options: { skip: 'auto', encodeDates: false },
});

split(zeroWidthStr, options)

This function decodes a string that was encoded using the combine function. It splits the string into the original text and the encoded data, and then attempts to parse the encoded data as JSON. If the decodeDates option is true, it checks the values of the parsed data for ISO date strings and converts them back to Date objects. Note: This function only checks one level down in the object for date strings. Nested objects are not supported.

Parameters

  • zeroWidthStr (string): The string of zero-width characters to be decoded.
  • options (Object): Options for the split function.
    • decodeDates (boolean): Whether to decode dates. Defaults to false.

Returns

  • (Object): An object containing the original text and the decoded data.

Example

import { split } from 'stega-toolkit';

let { text, data } = split(combined, { decodeDates: false });

decode(zeroWidthStr)

This function decodes a string of zero-width characters into a regular string. It iterates over each character in the input string. If the character is a zero-width space, it adds '0' to a binary string. If the character is a zero-width joiner, it adds '1' to the binary string. If the character is a zero-width non-joiner, it converts the binary string to a character and adds it to the result. The function also handles the encoded data length, which is the first four characters of the decoded string. If there are remaining bits in the binary string after the loop, it converts them to a character and adds them to the result.

Parameters

  • zeroWidthStr (string): The string of zero-width characters to be decoded.

Returns

  • (Object): An object containing the decoded string (result) and the length of the encoded data (encodedDataLength).

Example

import { decode } from 'stega-toolkit';

let { result, encodedDataLength } = decode(zeroWidthStr);

encode(dataToHide)

This function encodes a string or JSON object into a string of zero-width characters. The function first converts the input data to a string, if it's not already a string. It then iterates over each character in the string, converting each character to a binary string. For each bit in the binary string, it adds a zero-width space to the result if the bit is '0', or a zero-width joiner if the bit is '1'. After each character, it adds a zero-width non-joiner to the result.

Parameters

  • dataToHide (Record<string, any> | string): The data to be encoded. Can be a string or a JSON object.

Returns

  • (string): The input data encoded as a string of zero-width characters.

Example

import { encode } from 'stega-toolkit';

let hiddenString = encode({ name: 'John', age: 30, city: 'New York' });

Contributing

Contributions are welcome! Please read the Contributing Guidelines before making a pull request.

License

This project is licensed under the MIT License.