0.0.4 • Published 6 years ago

thehigherrealm v0.0.4

Weekly downloads
1
License
UNLICENSED
Repository
-
Last release
6 years ago

The Higher Realm

personal module with my functions for my projects
Version 0.0.4
EARLY DEVELOPMENT

Features

Contained (Checks if string is in array and return arguments. Used for CLI.)
Goto (Function call by string without eval().)
Save/Load Data (Saves and Loads objects to/from JSON.)
Clear (Clears Command Line Windows Only)


Usage

CLI Functions meant to be used with readline-sync
realm = require('thehigherrealm')

contained():

// contained(input, [list,  of, possibilities], args)
// If args exists it'll be activates.
// Args makes function return the input divided by words in array if the input is found in the output

input = readline.question("Enter: "); // readline-sync get input
if(realm.contained(input, ['exit', 'quit', 'leave'])) { // Check input
    procese.exit(); // Exits
}

// Contained is not case sensitive

input = realm.contained(readline.question("> "), ['deposit', 'withdraw'], true); // readline gets input, passes it to contained and checks with args
if (input[0] == 'deposit') { // Check if first word was 'deposit'
  user.deposit(input[1]) // Deposits second word (amount)
}
if (input[0] == 'withdraw') { // Check if second word was 'withdraw'
  user.withdraw(input[1]); // Withdraws second word (amount)
}

Goto:

// goto(function_name, [list, of, arguments])
// Returns false if function isn't found

function menu(x) { //Sample Function
    console.log(x + '!');
}

place = "menu" // Function Name.
args = ["Hey"] // Arguments. Can accept any amount.
realm.goto(place, args) // goto(location, arguments)

// OUTPUT:
// > "Hey!"

Save/Load:

// save(object, location)
// load(location)   returns object

user = {
    fname: 'John',
    lname: 'Smith',
    age: 36
}
realm.save(user, 'saves/' + user.fname + '.json') // Saves user object

user = null // Clears the variable to load it

user = realm.load('saves/John.json') // Loads user back up
console.log(user.fname, user.lname, age)

// OUTPUT:
// > John, Smith, 32

Clear:

// clear()
// No arguments

realm.clear();

// Clears windows cmd or powershell
// Same thing as:
console.log('\x1Bc')
//but easier to rememeber
0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

1.0.0

6 years ago