Skip to content

0x04/string-mutilator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-mutilator

A JavaScript library for mutilate strings.

MIT license

Motivation background

Most of the code from this project was created during a personal codegolf competition to distort the appearance of strings as much as possible but without actually destroying their contents.

So the name mutilator come into my mind.

mutilator (plural mutilators)

  1. Agent noun of mutilate; one who mutilates.

This sounds unnecessarily brutal for now, but I assure you that no strings will be harmed permanently, as long as the functions are used correctly. 😏

So I decided to combine these "strange" functions into one library. More or less just for fun.

Modules

stringMutilator/charCase

Functions for manipulating the letter case of strings.

stringMutilator/compressor

Functions for compressing (pack/unpack etc.) strings.

stringMutilator

Functions

flipBits(string)string

Flip the character bits of a string. The 16 character bits of 'A' are 00000000 01000001 - if we flip the bits (so every 0 becomes 1 and vice versa) they look like this 11111111 10111110. This means that 'A' (0x41) becomes 'ᄒ' (0xFFBE).

jumble(string, [runs])string

Jumble the letters of all words in a string, except the first and last one, to keep it readable.

reverseBits(string)string

Reverse the character bits of a string. The 16 character bits of 'A' are 00000000 01000001 - if we reverse the bits they look like this 1111111 10111110. This means that 'A' (0x41) becomes '舀' (0x8200).

reverse(string)string

Reverse a string.

rockdotize(string, [regexp])string

Create a heavy metal like rockdot string.

rot13(string)string

Rotate the character indexes of a string by 13 digits.

scramble(string)string

Randomize the order of the characters in a string.

shiftBits(string, [n])string

Rotate the character bits of a string.

shift(string, [n])string

Shift the characters of a string by n digits.

toMANS(string, [type])string

Convert A-Z to Mathematical Alphanumeric Symbols.

List of type values:

type Unicode Block
0 Mathematical Bold
1 Mathematical Italic
2 Mathematical Bold Italic
3 Mathematical Script Capital
4 Mathematical Bold Script
5 Mathematical Fraktur
6 Mathematical Double-Struck
7 Mathematical Bold Fraktur
8 Mathematical Sans-Serif
9 Mathematical Sans-Serif Bold
10 Mathematical Sans-Serif Italic
11 Mathematical Sans-Serif Bold Italic
12 Mathematical Monospace

stringMutilator/charCase

Functions for manipulating the letter case of strings.

stringMutilator/charCase.invert ⇒ string

Invert the case of letters in a string.

Kind: static constant of stringMutilator/charCase

Param Type Description
string string The string to be case inverted.
[every] number Only invert every n letter.

Example

stringMutilator.charCase.invert('Hello World!'); // > 'hELLO wORLD!'

stringMutilator/compressor

Functions for compressing (pack/unpack etc.) strings.

stringMutilator/compressor.pack ⇒ string

Pack all characters of a 8-bit string.

Kind: static constant of stringMutilator/compressor

Param Type Description
string string A 8-bit string to pack.

Example

stringMutilator.compressor.pack('Hello World!'); // > '䡥汬漠坯牬搡'

stringMutilator/compressor.unpack ⇒ string

Unpack a packed string.

Kind: static constant of stringMutilator/compressor

Param Type Description
string string The packed string to unpack.

Example

stringMutilator.compressor.unpack('䡥汬漠坯牬搡'); // > 'Hello World!'

stringMutilator/compressor.signature ⇒ string

Return the given, packed string with the unpack signature.

Kind: static constant of stringMutilator/compressor

Param Type Description
string string The packed string to signature.
withEval boolean Determine if the result includes a eval command for executing code.

Example

stringMutilator.compressor.signature('䡥汬漠坯牬搡'); // > 'unescape(escape("䡥汬漠坯牬搡").replace(/u(..)/g, "$1%");'

stringMutilator

flipBits(string) ⇒ string

Flip the character bits of a string. The 16 character bits of 'A' are 00000000 01000001 - if we flip the bits (so every 0 becomes 1 and vice versa) they look like this 11111111 10111110. This means that 'A' (0x41) becomes 'ᄒ' (0xFFBE).

Kind: global function

Param Type Description
string string The input string.

Example

stringMutilator.flipBits('Hello World!'); // > 'ᄋレモモミ￟ᄄミヘモロ￞'

jumble(string, [runs]) ⇒ string

Jumble the letters of all words in a string, except the first and last one, to keep it readable.

Kind: global function
See: https://www.mnn.com/lifestyle/arts-culture/stories/why-your-brain-can-read-jumbled-letters

Param Type Default Description
string string The input string.
[runs] number 3 The number of attempts to get a real randomized word string.

Example

stringMutilator.jumble('Hello World!'); // > 'Hlelo Wrlod!'

reverseBits(string) ⇒ string

Reverse the character bits of a string. The 16 character bits of 'A' are 00000000 01000001 - if we reverse the bits they look like this 1111111 10111110. This means that 'A' (0x41) becomes '舀' (0x8200).

Kind: global function

Param Type Description
string string The input string.

Example

stringMutilator.reverseBits('Hello World!'); // > 'ሀꘀ㘀㘀Ѐ一㘀☀萀'

reverse(string) ⇒ string

Reverse a string.

Kind: global function

Param Type Description
string string The input string.

Example

stringMutilator.reverse('Hello World.'); // > '.dlroW olleH'

rockdotize(string, [regexp]) ⇒ string

Create a heavy metal like rockdot string.

Kind: global function
See

Param Type Default Description
string string The string to rockdotize.
[regexp] RegExp <RegExp /\w/gi> A RegExp to select every character that should get rockdotized.

Example

stringMutilator.rockdotize('Hello World!'); // > 'Ḧël̈l̈ö Ẅör̈l̈d̈!'

rot13(string) ⇒ string

Rotate the character indexes of a string by 13 digits.

Kind: global function
See: https://en.wikipedia.org/wiki/ROT13

Param Type Description
string string The input string.

Example

stringMutilator.rot13('Hello World!'); // > 'Uryyb Jbeyq!'

scramble(string) ⇒ string

Randomize the order of the characters in a string.

Kind: global function

Param Type Description
string string The string to scramble.

Example

stringMutilator.scramble('Hello World!'); // > 'WorH!llo led'

shiftBits(string, [n]) ⇒ string

Rotate the character bits of a string.

Kind: global function

Param Type Default Description
string string The input string.
[n] number 1 Number of digits to rotate the character bit. Positive for right rotation, negative for left rotation.

shift(string, [n]) ⇒ string

Shift the characters of a string by n digits.

Kind: global function

Param Type Default Description
string string The string to shift.
[n] number 1 Number of digits to rotate the characters. Positive for right rotation, negative for left rotation.

Example

stringMutilator.shift('Hello World!', 3); // > 'lo World!Hel'

toMANS(string, [type]) ⇒ string

Convert A-Z to Mathematical Alphanumeric Symbols.

List of type values:

type Unicode Block
0 Mathematical Bold
1 Mathematical Italic
2 Mathematical Bold Italic
3 Mathematical Script Capital
4 Mathematical Bold Script
5 Mathematical Fraktur
6 Mathematical Double-Struck
7 Mathematical Bold Fraktur
8 Mathematical Sans-Serif
9 Mathematical Sans-Serif Bold
10 Mathematical Sans-Serif Italic
11 Mathematical Sans-Serif Bold Italic
12 Mathematical Monospace

Kind: global function
Summary: Convert A-Z to Mathematical Alphanumeric Symbols.
See: https://unicode-table.com/en/blocks/mathematical-alphanumeric-symbols

Param Type Default Description
string string The input string.
[type] number 0 A number between 0 and 12.

Example

stringMutilator.toMANS('Hello World!', 1); // > '𝐻𝑒𝑙𝑙𝑜 𝑊𝑜𝑟𝑙𝑑.'

Involutory functions

An involutory function, is a function f that is its own inverse.

TLDR; This type of function returns a result from a value that returns the initial value when the function is called again with the previous result.

Which means in short:

import { rot13 } from 'string-mutilator'; rot13(rot13('Hello World!')) === 'Hello World!'; // > true

List of involutory

License

© 2019 by Oliver Kühn. Released under the MIT license.