1.2.18 • Published 7 years ago

minin-api-additionalfunctions v1.2.18

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

minin-api-additionalFunctions WIKI

Import

To install this API, type this into the command prompt;

npm init
npm i minin-api-additionalfunctions

The npm init part can be ignored if you aren't making a new project.

To import this API type this, you can replace the af for any other name.

const af = require(minin-api-additionalfunctions);

Now to run a function you have to put af behind it.

Functions

removeArrayObject()

Credits

Original code by qwertymk, modified by Minin Productions

Raw Code

function removeArrayObject(arr, what) {
    var found = arr.indexOf(what);

    while (found !== -1) {
        arr.splice(found, 1);
        found = arr.indexOf(what);
    }
    console.log("REMOVED OBJECT " + what + " FROM ARRAY");
}

Usage

Let's say myArray has 5 items in it, all titled object1, object2, object3, ect... Now, if you run this code object3 would be missing.

var myArray = ['object1', 'object2', 'object3', 'object4', 'object5'];
removeArrayObject(myArray, 'object3');
console.log(myArray);

The output should be;

object1, object2, object4, object5

randomInt()

Credits

Original code by Minin Productions

Raw Code

function randomInt(minimum, maximum) {
    var random = Math.floor(Math.random() * maximum) + minimum;
    return random;
}

Usage

The randomInt() function works by an input of a minimum and maximum number and it will return a value in between those numbers.

var myInt = randomInt(1, 6);
console.log(myInt);

The output should be a random number from 1 to 6.

randomString()

Credits

Original code by csharptest.net, modified by Minin Productions

Raw Code

function randomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    for( var i=0; i < length; i++ )
        text += possible.charAt(random(0,possible.length));

    return text;
}

Usage

The randomInt() get an input of a number which will be the length of the string and picks one and adds it to a variable and repeats it for the number you put in, and it will return that string.

You can adapt this for your own projects since you just need you add/remove characters from the variable named possible.

var myString = randomString(6);
console.log(myString);

The output should be a random, 6 letter string.

log()

Credits

Original code by Minin Productions

Raw Code

function log(content, id) {
    let node = document.createElement("div");
    let textnode = document.createTextNode(content);
    node.appendChild(textnode);
    document.getElementById(id).appendChild(node);
}

Usage

This is if you are making a website hosted/using Node.js This takes in two arguments, what you want to log, and where to log it to. This is like console.log() but without having to open the developer console so instead it outputs to HTML.

<body>
    <button onClick="af.log('Hello World!', 'pageContent')">Click Me</button>
    <p id="pageContent">Click the Button.</p>
</body>

Should be a button, when you press it the paragraph should grow from

Click the Button.

To

Click the Button.
Hello World!

formatSecs()

Credits

Original code by XerXis (on NeoWin), modified by Minin Productions

Raw Code

formatSecs(seconds) {
    // Get Days/Hours/Minutes/Seconds
    var numdays = Math.floor(seconds / 86400);
    var numhours = Math.floor((seconds % 86400) / 3600);
    var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
    var numseconds = ((seconds % 86400) % 3600) % 60;

    // Format Calculations
    var result = numdays + ":" + numhours + ":" + numminutes + ":" + numseconds;

    // Return Result
    return result;
}

Usage

This formats seconds into days, hours, minutes and seconds. This takes a single argument, the amount of seconds you would like to format.

console.log(af.formatSecs(3064));

The output should be this, but it may differ dependending on what you input;

0:0:51:4
1.2.18

7 years ago

1.2.17

7 years ago

1.2.16

7 years ago

1.2.15

7 years ago

1.2.14

7 years ago

1.2.13

7 years ago

1.2.12

7 years ago

1.2.11

7 years ago

1.2.10

7 years ago

1.2.9

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.0

7 years ago