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

smoke-machine-js

v1.0.6

Published

A collection of helper functions often used in my projects.

Downloads

15

Readme

smoke-signal-js logo

smoke-machine-js

A collection of helpful functions, polyfills, and definitions I frequently use in my projects.

Contains general content, as well as project-specific code snippets which is implemented in multiple contexts.

This package is intended primarily for personal use, but please feel free to use/improve any of the functions provided here.

Installation

npm install smoke-machine-js

Usage

// For ES6 imports
import { helperFunctions } from 'smoke-machine-js';

// For commonJS
const { helperFunctions } = require('smoke-machine-js');

Documentation

Documentation for all modules. GitHub | NPM | View on Website | Donate

Helper Functions

A collection of functions for processing and formatting data.

Some of these may be redundant, depending on their runtime (e.g. helperFunctions.getTime() in a browser with the Internationalization API). These functions are mostly meant to act as polyfills for runtimes where they are not natively supported.

Many of these functions are extremely simple (e.g. helperFunctions.arrayRandom(arr)), and you may ask yourself why they require a function. The reason is that I do not feel like writing it 200,000 times, or the underlying code isn't nearly as semantic as a named function.


helperFunctions.stringToSHA256(str) ⇒

Kind: static method of helperFunctions
Returns: ByteBuffer containing SHA256 encoded str

| Param | Type | | ----- | ------------------- | | str | string |

helperFunctions.stringToByteBuffer(str) ⇒

Kind: static method of helperFunctions
Returns: Byte Array containing encoded str

| Param | Type | | ----- | ------------------- | | str | string |

helperFunctions.intFromBytes(bytearray) ⇒

Kind: static method of helperFunctions
Returns: Decoded 64-bit Floating Point number

| Param | Type | | --------- | ---------------------- | | bytearray | bytearray |

helperFunctions.roundFloat(float) ⇒

Useful for rounding single-precision floats (such as those encoded in a Java application)

Kind: static method of helperFunctions
Returns: Number rounded to the 100ths place.

| Param | Type | | ----- | ------------------- | | float | number |

helperFunctions.getTime(full) ⇒

Kind: static method of helperFunctions
Returns: Formatted string time

| Param | Type | Default | Description | | ----- | -------------------- | ------------------ | -------------------------------------------------------- | | full | boolean | false | Whether or not function returns seconds. default: false. |

helperFunctions.projectAudit()

Iterates over all files (excluding node_modules and the like) to determine the (roughly estimated) number of lines of code in a given project

Kind: static method of helperFunctions

helperFunctions.crc32(str) ⇒

Generates a crc32 checksum from a string

Kind: static method of helperFunctions
Returns: crc32 checksum number

| Param | Type | Description | | ----- | ------------------- | ------------------------------------- | | str | string | The stringified data to be converted. |

helperFunctions.parsedJsonStringsToInt(object) ⇒

Takes a parsed JSON object which contains numbers read as strings and converts those strings to numbers. e.g. userID: "1234" would become userID: 1234. Also has the nasty tendency to turn empty arrays into zeroes.

Kind: static method of helperFunctions
Returns: Object with numbers, rather than strings.

| Param | Type | Description | | ------ | ------------------- | ------------------------------------- | | object | object | The stringified data to be converted. |

helperFunctions.degreesToRadians(deg)

Converts degrees to radians. Simple as.

Kind: static method of helperFunctions

| Param | Type | | ----- | ------------------- | | deg | number |

helperFunctions.radiansToDegrees(rad)

Converts radians to degrees. Simple as.

Kind: static method of helperFunctions

| Param | Type | | ----- | ------------------- | | rad | number |

helperFunctions.milesToKilometers(miles)

Converts miles to kilometers. Simple as.

Kind: static method of helperFunctions

| Param | Type | | ----- | ------------------- | | miles | number |

helperFunctions.kilometersToMiles(kilometers)

Converts kilometers to miles. Simple as.

Kind: static method of helperFunctions

| Param | Type | | ---------- | ------------------- | | kilometers | number |

helperFunctions.bytesToHexString(data, length)

Converts a byte array into a hexadecimal string.

Kind: static method of helperFunctions

| Param | Type | Default | Description | | ------ | ---------------------- | --------------- | ----------------------------------------------------------------------------- | | data | bytearray | | Data to be encoded | | length | number | 32 | The maximum number of bytes which will be read (left justified). Default: 32. |

helperFunctions.arrayRandom(arr)

Selects a pseudorandom value from the provided array. Because I was sick of typing 'Math.' 200 times.

Kind: static method of helperFunctions

| Param | Type | Description | | ----- | ------------------ | -------------------------- | | arr | array | Array to be selected from. |

helperFunctions.capitalizeString(str)

Capitalizes a given string.

Kind: static method of helperFunctions

| Param | Type | Description | | ----- | ------------------- | ------------------------ | | str | string | String to be capitalized |

helperFunctions.generateOrdinal(i) ⇒

Generates an ordinal suffix for a number. e.g. 1 becomes 1st, 9 becomes 9th.

Kind: static method of helperFunctions
Returns: The number concatenated with its ordinal.

| Param | Type | Description | | ----- | ------------------- | -------------------------------------------------- | | i | number | The number for which an ordinal will be generated. |

helperFunctions.removeMarkdownTags(str) ⇒

Coarsely removes markdown tags from a string. e.g. Hello world becomes Hello world

Kind: static method of helperFunctions
Returns: The number without markdown tags

| Param | Type | Description | | ----- | ------------------- | ----------------------------------- | | str | string | The string with Markdown formatting |

helperFunctions.camelCase(str) ⇒

Formats a string to camelCase e.g. Hello World becomes helloWorld.

Kind: static method of helperFunctions
Returns: camelCase string

| Param | Type | | ----- | ------------------- | | str | string |

Launch Functions

A collection of functions specific to Launch-related projects:

  • Launch
  • Launch II
  • Launch: Experimental
  • Counterforce
  • Counterforce II
  • smokeSignal

launchFunctions.stringFromData(bb) ⇒

Reads a Short at the provided ByteBuffer's offset, reads a string of the length denoted by the read short. This DOES iterate the ByteBuffer in the namespace where the function is called.

Kind: static method of launchFunctions
Returns: The string which was read.

| Param | Type | Description | | ----- | ----------------------- | -------------------------------------------------- | | bb | ByteBuffer | The ByteBuffer from which the string will be read. |

launchFunctions.getStringData(str) ⇒

Converts a string to a ByteBuffer containing a short (representing the length of the converted string), followed by the converted string.

Kind: static method of launchFunctions
Returns: ByteArray

| Param | Type | Description | | ----- | ------------------- | ----------------------------------- | | str | string | The string which will be converted. |

launchFunctions.getStringDataSize(str) ⇒

Returns the byte-size of a short (representing the length of the string), followed by a byte-encoded string

Kind: static method of launchFunctions
Returns: Number

| Param | Type | Description | | ----- | ------------------- | ---------------------------------- | | str | string | The string which will be measured. |

launchFunctions.sanitizeName(str) ⇒

Sanitized the given name for profanity, as well as dangerous characters. Not currently functional.

Kind: static method of launchFunctions
Returns: The sanitized string.

| Param | Type | Description | | ----- | ------------------- | ----------------------------------- | | str | string | The string which will be sanitized. |

launchFunctions.cleanJSONGameSave(json) ⇒

Cleans coarsely converted JSON game save (from XML) for use in Counterforce. This is an ultra-specific function for Counterforce.

Kind: static method of launchFunctions
Returns: Cleaned object.

| Param | Type | Description | | ----- | ------------------- | ----------------------- | | json | object | The parsed JSON object. |

Dependencies

Huge shout-out to bytebuffer.js. This package powers several of my projects and is phenomenal.