Giter VIP home page Giter VIP logo

orcorum's Introduction

orcorum NPM Version

Helper library for JavaScript

Installing

npm install orcorum

Running the tests

npm test

API

orcorum.classes

extend(properties[, statics])

To create a class of your own base class, you extend your base class and provide instance properties, as well as optional statics to be attached directly to the constructor function.

function Animal(name) {
    this.name = name;
}

Animal.prototype.getName = function() {
    return this.name;
};

Animal.extend = orcorum.classes.extend;

// ...

var Dog = Animal.extend({
    bark: function() {
        return 'GUAUUU!!!'
    }
});

var dog = new Dog('pepito');

console.log(dog.name); // => pepito

console.log(dog.bark()); // => GUAUUU!!!

orcorum.object

get(target, keys[, defaultValue])

Get property of target.

orcorum.object.get({
    name: 'pepito',
    age: 3
}, 'age'); // => 3

orcorum.object.get({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, ['name', 'first']); // => pepito

orcorum.object.get({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, ['name', 'alias'], 'pepe'); // => pepe

orcorum.object.get({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, ['works', 'first', 'beginDate']); // => undefined

set(target, keys, value)

Set property in target.

orcorum.object.set({
    name: 'pepito',
    age: 3
}, 'name', 'josecito'); // => {name: 'josecito', age: 3}

orcorum.object.set({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, ['name', 'first'], 'josecito'); // => {name: {first: 'josecito', last: 'roman'}, age: 3}

orcorum.object.set({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, ['name', 'alias'], 'pepe'); // => {name: {first: 'pepito', last: 'roman', alias: 'pepe'}, age: 3}

extend(target, *sources)

Override properties of target with the all properties in the source objects (in-order), and return the target object.

orcorum.object.extend({
    name: 'pepito',
    age: 3
}, {
    age: 4
}); // => {name: 'pepito', age: 4}

orcorum.object.extend({
    name: {
        first: 'pepito',
        last: 'roman'
    },
    age: 3
}, {
    name: {
        last: 'robin'
    }
}); // => {name: {first: 'pepito', last: 'robin'}, age: 3}

orcorum.url

normalize(url)

Normalize url path.

console.log(orcorum.url.normalize('')); // => Client size '' - Server side '/'
console.log(orcorum.url.normalize('/path/to')); // => /path/to
console.log(orcorum.url.normalize('/path/to/')); // => /path/to
console.log(orcorum.url.normalize('http://www.mysite.com')); // => http://www.mysite.com

params(url, key, value)

Add or return url params.

console.log(orcorum.url.params('')); // => {}
console.log(orcorum.url.params('/path/to?search=auto')); // => {search: 'auto'}
console.log(orcorum.url.params('/path/to?search=auto&country=ar', 'country')); // => ar
console.log(orcorum.url.params('/path/to?search=auto&country=ar', 'country', 'en')); // => /path/to?search=auto&country=en
console.log(orcorum.url.params('/path/to', {
    search: 'auto',
    country: 'ar'
})); // => /path/to?search=auto&country=ar

removeParams(url, key)

Remove url params.

console.log(orcorum.url.removeParams('/path/to?search=auto&country=ar', 'country')); // => /path/to?search=auto
console.log(orcorum.url.removeParams('/path/to?search=auto', 'search')); // => /path/to

cleanParams(url)

Remove all url params.

console.log(orcorum.url.cleanParams('/path/to?search=auto&country=ar')); // => /path/to
console.log(orcorum.url.cleanParams('/path/to?search=auto')); // => /path/to

orcorum.time

SECONDS, MINUTE, HOUR, DAY, MONTH and YEAR

Time in milliseconds.

console.log(orcorum.time.SECOND); // => 1000
console.log(orcorum.time.MINUTE); // => 60000
console.log(orcorum.time.HOUR);   // => 3600000
console.log(orcorum.time.DAY);    // => 86400000
console.log(orcorum.time.MONTH);  // => 2592000000
console.log(orcorum.time.YEAR);   // => 31104000000

orcorum.http

method, status and type

Time in milliseconds.

console.log(orcorum.http.method.GET); // => 'get'
console.log(orcorum.http.method.POST); // => 'post'
// ...
console.log(orcorum.http.status.OK); // => 200
console.log(orcorum.http.status.SUCCESS); // => 200
console.log(orcorum.http.status.NO_CONTENT); // => 204
// ...
console.log(orcorum.http.type.FORM);   // => 'application/x-www-form-urlencoded'
console.log(orcorum.http.type.MULTIPART);   // => 'multipart/form-data'
// ...

orcorum.fs

requiredirSync(dirname[, options])

Requires all files in a directory into an object with the same structure.

Options
  • excludes Files excludes. Defaults to ['index'].
  • extension Files extension. Only require the file match with this extension. Defaults to '.js'].
orcorum.fs.requiredirSync(__dirname);

// Or 
orcorum.fs.requiredirSync(__dirname, {
    excludes: ['my_exclude_file']
});

// Or 
orcorum.fs.requiredirSync(__dirname, {
    extension: '.json'
});

orcorum's People

Contributors

comodinx avatar nmolina-umewin avatar

Watchers

James Cloos avatar  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.