1.0.6 • Published 2 years ago

smoke-machine-js v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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

ParamType
strstring

helperFunctions.stringToByteBuffer(str) ⇒

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

ParamType
strstring

helperFunctions.intFromBytes(bytearray) ⇒

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

ParamType
bytearraybytearray

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.

ParamType
floatnumber

helperFunctions.getTime(full) ⇒

Kind: static method of helperFunctions
Returns: Formatted string time

ParamTypeDefaultDescription
fullbooleanfalseWhether 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

ParamTypeDescription
strstringThe 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.

ParamTypeDescription
objectobjectThe stringified data to be converted.

helperFunctions.degreesToRadians(deg)

Converts degrees to radians. Simple as.

Kind: static method of helperFunctions

ParamType
degnumber

helperFunctions.radiansToDegrees(rad)

Converts radians to degrees. Simple as.

Kind: static method of helperFunctions

ParamType
radnumber

helperFunctions.milesToKilometers(miles)

Converts miles to kilometers. Simple as.

Kind: static method of helperFunctions

ParamType
milesnumber

helperFunctions.kilometersToMiles(kilometers)

Converts kilometers to miles. Simple as.

Kind: static method of helperFunctions

ParamType
kilometersnumber

helperFunctions.bytesToHexString(data, length)

Converts a byte array into a hexadecimal string.

Kind: static method of helperFunctions

ParamTypeDefaultDescription
databytearrayData to be encoded
lengthnumber32The 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

ParamTypeDescription
arrarrayArray to be selected from.

helperFunctions.capitalizeString(str)

Capitalizes a given string.

Kind: static method of helperFunctions

ParamTypeDescription
strstringString 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.

ParamTypeDescription
inumberThe 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

ParamTypeDescription
strstringThe 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

ParamType
strstring

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.

ParamTypeDescription
bbByteBufferThe 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

ParamTypeDescription
strstringThe 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

ParamTypeDescription
strstringThe 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.

ParamTypeDescription
strstringThe 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.

ParamTypeDescription
jsonobjectThe parsed JSON object.

Dependencies

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

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago