Skip to content

dabanlee/just-do

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Just - Just do one thing.

Packages

Usage

type checking.

import type from 'just-type';

function hello() {
    console.log('hello type');
}

type(); // undefined
type(undefined); // undefined
type(null); // null
type(''); // string
type('hello'); // string
type(0); // number
type(true); // boolean
type({}); // object
type([]); // array
type(hello); // function
type(/\./); // regexp

transform strings to camel case.

import camelize from 'just-camelize';

camelize('_hello_world'); // HelloWorld
camelize('_hello-world'); // HelloWorld
camelize('-hello_world'); // HelloWorld
camelize('-hello-world'); // HelloWorld

objects extend.

import extend from 'just-extend-it';

let source = {
    just: 'just',
};

extend(source); // { just: 'just', }

extend(source, {
    hello: 'hello',
}); // { just: 'just', hello: 'hello', }

extend(source, {
    hello: 'hello',
}, {
    world: 'world',
}); // { just: 'just', hello: 'hello', world: 'world', }

extend(true, source, {
    hello: 'hello',
}); // { just: 'just', hello: 'hello', }

extend(true, source, {
    hello: {
        world: 'world',
    },
}); // { just: 'just', hello: { world: 'world', }, }

extend(true, source, {
    hello: {
        world: 'world',
    }, {
        hello: {
            hi: 'hi',
        },
    },
});// { just: 'just', hello: { world: 'world', hi: 'hi', }, }

extend(source, {
    hello: {
        world: 'world',
    },
}, {
    hello: {
        hi: 'hi',
    },
}); // { just: 'just', hello: { hi: 'hi', }, }

find key or value in object.

import find from 'just-find';

let object = {
    hello: 'hello',
    onClick: 'onClick',
    onTouch: 'onTouch',
    just: null,
    a: 0,
    b: 5,
    c: 7,
    d: 6,
    e: 8,
};

find(object, function (key, value) {
    return key === 'hello';
}); // { hello: 'hello', }

find(object, function (key, value) {
    return typeof value === 'number';
}); // { a: 0, b: 5, c: 7, d: 6, e: 8, }

find(object, function (key, value) {
    return key.slice(0, 2) === 'on';
}); // { onClick: 'onClick', onTouch: 'onTouch', }

find(object, function (key, value) {
    return value > 0 && value < 8;
}); // { b: 5, c: 7, d: 6, }

map object.

import map from 'just-map-it';

let object = {
    a: 0,
    b: 5,
    c: 7,
    d: 6,
    e: 8,
};

map(object, function (key, value) {
    return value * value;
}); // { a: 0, b: 25, c: 49, d: 36, e: 64, }

get url query.

import getQuery from 'just-get-query';

let search = location.search; // https://just-do.io?hello=hello&world=world

// null
getQuery('hello')
getQuery('hello', '')
getQuery('just', search)
getQuery('just', '?' + search)
getQuery('just', '??' + search)

// hello
getQuery('hello', search)
getQuery('hello', '?' + search)
getQuery('hello', '??' + search)

// world
getQuery('world', search)
getQuery('world', '?' + search)
getQuery('world', '??' + search)

just-ajax

ajax request.

import ajax from 'just-ajax';

ajax({
    url: 'http://api.hello.com/',
    type: 'POST',
    data: {
        username: 'hello',
        password: 'world',
    },
    success: function (response) {
        console.log(response);
    },
    error: function (error) {
        console.log(error);
    },
});

About

Just do one thing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published