Giter VIP home page Giter VIP logo

jshelpers's Introduction

JavaScript Helpers

  • es6
    • in_array(needle, haystack, argStrict); // boolean
    • throw new ResultError('error message'); // exception
    • scrollToBlock(selector); // search block and scroll
    • serialize(array); // string
    • unserialize(string); // array
    • sleep(ms); // delay
    • startFunc(name); // start function from string
    • array_count(arr); // integer
    • rand(min=0,max=99999); // integer
    • 'you string'.replacer(replaceObject); // string
    • number_format(number, decimals=2, dec_point=".", thousands_sep=" "); // number
    • empty(variable); // boolean
  • es5
    • throw new ResultError('error message'); // exception
  • jquery
    • $(selector).alignSize(params, modify); // if no flexbox. align size DOM-elements
    • $(form).serializeObject(); // object

How to use es5 from es6?

  1. Copy file
  2. Remove word export and let/const
  3. Use webpack or gulp or babel or etc.

How to use?

import {#method_name1#,#method_name2#} from '#path_to_file#'

Check empty (javascript)

import {empty} from "darkfriend/jshelpers/empty.js";
let variable;
empty(variable); // true

// check empty Object
variable = {};
empty(variable); // true
empty(variable.param); // true (no throw exception)
empty(variable['param']); // true (no throw exception)
empty(variable.param.subParam); // throw exception!

variable = {a:0};
empty(variable.a); // true

// check empty Array
variable = [];
empty(variable); // true
empty(variable[1]); // true

variable = [0];
empty(variable); // false
empty(variable[0]); // true

// check empty String
variable = '';
empty(variable); // true

variable = '0';
empty(variable); // true

// check empty Number
variable = 0;
empty(variable); // true

jshelpers's People

Contributors

darkfriend avatar

Watchers

James Cloos avatar

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.