Git Product home page Git Product logo

util.js's Introduction

Init

const u = new Util();

Format

console.log(u.format('Hi {0}. Did you see the {1}?', ['Pikachu', 'Meow']));
console.log(u.format('Hi {Pikachu}. Did you see the {Boss}?', {'Pokemon': 'Pikachu', 'Boss': 'Meow'}));

Includes

console.log(u.includes('Ali Baba', 'Baba'))

Is Validation

console.log(u.is([1, 2, 3], u.Array));

console.log(u.is({'a': 'v'}, u.Object))

console.log(u.is(5.1, u.Integer));

console.log(u.is(3.2, u.Double));

console.log(u.is('Ali' + 123, u.String));

console.log(u.is(a = (d) => {}, u.Function));
console.log(u.is(function a (d) {}, u.Function));

console.log(u.is(class b {}, u.Class));

console.log(u.is('#button', 'visible'));

console.log(u.is("#chk", 'checked'));

console.log(u.is("#rdb", 'checked'));

let t = '';
let b = ' ';
console.log(u.is(t, u.Empty));

console.log(u.is(b, u.Blank));

let anElement = '';

console.log(u.is(anElement, u.Element));

anElement = document.querySelector("button");

console.log(u.is(anElement, u.Element));

console.log(u.is('[email protected]', u.Email));

console.log(u.is('tchİŞ@hotmaıl.com', u.Email));

console.log(u.is('tchİŞ@hotmaıl.', u.Email));

console.log(u.is('https://aligoren.com', u.Url));

console.log(u.is('ftp://github.com', u.Url));

console.log(u.is('http://localhost', u.Url));

console.log(u.is('www.google.com', u.Url));

Count

Word Count:

console.log(u.count('My name is no name when I do not like names. What is your name? Can u say your naming conversion', 'name'));

Letter Count:

console.log(u.count('😚 You now I\'ll be happy', u.Letter));

Array Count:

console.log(u.count([1, 2, 3], u.Array));

Object Key Count:

console.log(u.count({'w': 't', 'w2': 't2', 'wf': 'wf', 'wfs': 'wfs2'}, u.Object));

Url

All

Values: ['hash', 'host', 'hostname', 'href', 'origin', 'pathname', 'port', 'protocol', 'search']

console.log(u.url(null, true));

Single

console.log(u.url('pathname'));

Page

Get Title

console.log(u.page('title'));

Set Title

u.page('title', 'New Page title');

Get Charset

console.log(u.page('charset'));

Set Charset

console.log(u.page('charset', 'UTF-8'));

Get Doc Type

console.log(u.page('doctype'));

Get Location

console.log(u.page('location'));

Set Location

console.log(u.page('location', 'https://www.google.com.tr'));

Get Design Mode Status

console.log(u.page('design'));

Set Design Mode Status

Values must be on or off

console.log(u.page('design', 'on'));

Get Scripts Src

console.log(u.page('scripts'));

Get Style Links

console.log(u.page('styles'));

Get Document Referrer

console.log(u.page('referrer'));

Get Modified Date

console.log(u.page('modified'));

When

Click etc. Events

u.when('button', 'click', (data) => {
    console.log(data.event);
    console.log(data.index);
    console.log(data.text);
    console.log(data.html);
});

u.when('document', 'click', (data) => {
    console.log(data.event);
    console.log(data.index);
    console.log(data.text);
    console.log(data.html);
});

Page Load Events

u.when('document', 'DOMContentLoaded', (data) => {
    console.log(data); // from event
});

u.when('document', 'load', (data) => {
    console.log(data); // from event
});

Where

const arr = [
    {
        name: 'test',
        surname: 'test1'
    },
    {
        name: 'test23',
        surname: 'newsname'
    },
    {
        name: 'test23',
        surname: 'newsname'
    }
]

console.log(u.where(arr, 'surname', 'newsname'));

util.js's People

Contributors

aligoren 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.