Giter Club home page Giter Club logo

coolfeatures-js's Introduction

coolfeatures-js

Cool features missing in JavaScript

Features

Coolfeatures.getRandomArrayValue()

The getRandomArrayValue() method returns a random value from the given array.

Demo

const array1 = [1, 2, 3, 4];

console.log(Coolfeatures.getRandomArrayValue(array1));
// expected output: 1, 2, 3, or 4

Syntax

var randomElement = Coolfeatures.getRandomArrayValue(array)

Parameters

array
The array where a random element should be selected from.

Return value

A random selected element from array.


Coolfeatures.filterObject()

The Coolfeatures.filterObject() method creates a new object with all elements that pass the test implemented by the provided function.

Demo

const personAges = {
    hans: 45,
    peter: 33,
    jens: 68,
    mike: 21
};

console.log(Coolfeatures.filterObject(personAges, age => age < 40));
// expected output: {peter: 33, mike: 21}

Syntax

var newObject = Coolfeatures.filterObject(object, callback([element[, key[, object]]]))

Parameters

object
The object to filter.

callback
Function is a predicate, to test each element of the object. Return true to keep the element, false otherwise. It accepts three arguments:

element
 The current element being processed in the object.

key
 The key of the current element being processed in the object.

object
 The object Coolfeatures.filterObject was provided with.

Return value

A new object with the elements that pass the test. If no elements pass the test, an empty object will be returned.


Coolfeatures.isObjectEmpty()

The isObjectEmpty() checks an object for being empty.

Demo

const emptyObject = {};

console.log(Coolfeatures.isObjectEmpty(emptyObject));
// expected output: true

const filledObject = {empty: false};

console.log(Coolfeatures.isObjectEmpty(filledObject));
// expected output: false

Syntax

var objectIsEmpty = Coolfeatures.isObjectEmpty(object)

Parameters

object
The object to check for being empty.

Return value

true if the object is empty, otherwise false.


Coolfeatures.getRandomIntBetween()

The getRandomIntBetween() method returns a random number between two given numbers.

Demo

console.log(Coolfeatures.getRandomIntBetween(5, 10));
// expected output: a number between 5 and 10

Syntax

var randomInt = Coolfeatures.getRandomIntBetween(min, max)

Parameters

min
The lowest possible random-generated number.

max
The highest possible random-generated number.

Return value

A random number between the given min and max number.


Coolfeatures.htmlStringToElement()

The htmlStringToElement() method parses a HTML string to an Element.

Demo

const html = '<div id="my-div">Hello World!</div>'

console.log(Coolfeatures.htmlStringToElement(html));
// expected output: a new HTMLDivElement whose outerHTML is like html

Syntax

var element = Coolfeatures.htmlStringToElement(htmlString)

Parameters

htmlString
The HTML string to convert to an element.

Return value

A new Element that got parsed from htmlString.

coolfeatures-js's People

Contributors

n-boerger avatar

coolfeatures-js's Issues

Is object empty

New function Coolfeatures.isObjectEmpty()

returns true if the given object is empty, otherwise false.

Syntax

var objectEmpty = Coolfeatures.isObjectEmpty(object)

HTML-String to Element

New function htmlStringToElement()

returns the representive element of the provided htmlString.

Syntax

var element = Coolfeatures.htmlStringToElement(htmlString)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.