npm.io
1.0.1 • Published 9 years ago

onyx-helper

Licence
ISC
Version
1.0.1
Deps
0
Vulns
0
Weekly
0

Welcome to ES7 Javascript Util Helper Onyx. A Gemstone In Your Project!

Awesome Open Source Love

Donation

To keep the repo live and kicking with good quality code we would more than happy if you could buy us a cup of coffe ;)

Gittip

Motivation

Hey guys, I started to write this repo from the reason that we over and over writing the same utils, and using libraries that have their own utils and it make kinda overkill in script size download. So we created the ES7 Javascript util helper. Extremely light and powerful library work for client and node js as one. A gemstoen at your js project ;) this one will be Onyx :).

Installation

The easiest way to get started is to clone the repository:

# Install util helper from npm registrey
npm install --save onyx-helper

# Get the latest snapshot
git clone --depth=1 https://github.com/sayeko/es7-javascript-util-helper.git myproject

# Change directory
cd myproject

# Install NPM dependencies
npm install

# Install gulp globally
npm i gulp -g

# Then simply start your app with the automation tool gulp
gulp

Usage Famous Is Methods

So you ask yourself what is so unique in that way.., We create all function above in a generic way so instead of writing and maintain 10 function. We have one function that do it for us. (expect to array and null)

Just call one of the function above with the is notation , isFunction(fn); and expect to get a boolean.

['Arguments', 'Function', 'String', 'Number', 'Object', 'Date', 'Error', 'Symbol', 'Undefined', 'HTMLDivElement', 'Array', 'Null'];

# Dynamic (is) function

// Valid function.
let fn = ()=> {return 'Test'};

let flag = Onyx.isFunction(fn); // return true;

Usage Parse

Heya, there is not developer who did not encounter this exception Uncaught SyntaxError: Unexpected token u in JSON at position 0 Invalid parsing json object or other parsing exception so we created cool and smooth error for js object parsing

we created a safeParseJSON that getting input for parse and a default value if the parsing failed good to know that this function in error parse not kill the execution context.
```bash # Parse safe json object.

let test = Onyx.safeParseJSON(undefined, {}); // return {};

Parse safe string to int

let num = Onyx.safeStringToInt('3', null); // Enter valid string to parse if there parsing error the function will return the default value.


<h5>Every developer in js encounter in the problem how to create clone of complex js object.</h5>

```bash
# Clone js object.

Onyx.clone(obj);

Window Facade

Most usage window function facades.

# Redirect

Onyx.redirect(url); // The name is kinda explanatory.

# Query string from url

Onyx.getQueryParametersByString(queryString..) // Get the query string as object.

# Refresh page (reload)

Onyx.reload();

# Fullscreen facades multi platform function works on any browser.

Onyx.fullScreen() // Kick in and change the user mode.

Onyx.isFullScreen() // Tell if the user is already in fullscreen mode. the fn above use this fn.

# Hostname domain

Onyx.hostname(); // google... etc..

# Protocol

Onyx.protocol(); // http, https, ftp , etc..

Async


# Load async script

Onyx.loadAsyncScript('src..' ,id , type); // Load async way script and append it to the end of the body tag, return Promise.

# Load async image

Onyx.loadAsyncImage(path, defaultPath) // Trying to load the path and if the path is not exist or error to load we loading the default path instead.

Contributors

Everyone is more than welcome to fork this repo upload issue or email me to make a suggestions. If you have cool and light facades please make a pull request. and help us to help the js developer community.

License

MIT Licence

Keywords