nekrawsd-money-api v2.0.1
nekrawsd-money-api
This is a new API created for the sole intent of making it easy on developers that want to include a currency in their programs.
Installation
To install nekrawsd-money-api, use command prompt and type npm install nekrawsd-money-api
, then in your program, use the following code to require it.
let money = require('nekrawsd-money-api');
Managing the Database
Using export and import, you can modify or save your database for further use, and by cleaning it, you ensure no account has an invalid balance.
let money = require('nekrawsd-money-api');
money.database.import('{"nathanalex66": 428}'); // Updates the database.
money.database.export(); // Returns JSON.
money.database.clean(); // Removes all invalid entries from the database.
Working with Accounts
Accounts have many different ways of being worked with. Some examples are creating accounts, deleting accounts, transferring currency from one account to another, checking the balance of an account, or checking if an account exists.
Creating an Account
To create an account, you can use the code account.create("account_id", "initial_amount")
, where initial_amount is not necessary.
let money = require('nekrawsd-money-api');
money.account.create("nathanalex66"); // Creates an account.
money.account.create("Toshiyuki", 50); // Creates an account with 50 currency.
Deleting an Account
Deleting an account permanently removes the account and it's balance from the database.
let money = require('nekrawsd-money-api');
money.database.import('{"nathanalex66": 625}');
money.account.delete("nathanalex66"); // Deletes the account "nathanalex66"
console.log(money.database.export()); // Returns {}
Transferring Currency
Transferring currency removes money from one account, and adds money to another.
let money = require('nekrawsd-money-api');
money.database.import('{"nathanalex66": 50, "Toshiyuki": 50}');
money.account.transfer("nathanalex66", "Toshiyuki", 25); // Transfers 25 currency from nathanalex66 to Toshiyuki
console.log(money.database.export()); // Returns {"nathanalex66": 25, "Toshiyuki": 75}
Checking Balance
Checking a balance can help you know how much a specific account has.
let money = require('nekrawsd-money-api');
money.database.import('{"nathanalex66": 50}');
console.log(money.account.balance("nathanalex66")); // Outputs 50.
Administrative Actions
These are functions that allow administrative users to change user account totals by adding money, removing money, or setting the money of the account.
let money = require('nekrawsd-money-api');
money.database.import('{"nathanalex66": 42}');
money.admin.remove("nathanalex66", 3); // Removes 3 currency from "nathanalex66"
money.admin.add("nathanalex66", 46); // Adds 46 currency to "nathanalex66"
money.admin.set("nathanalex66", 1337); // Sets the balance of "nathanalex66" to 1337 currency.
That should be all the documentation so far. Please email me at nathanalex66@gmail.com if you have any problems with this script using the following format.
Module: nekrawsd-money-api
Problem: Describe your problem here...
Reproduction: Describe how to reproduce the problem...
Any addition information can go down here...