utilxi

UtilXI, a utility library extends underscore.

  __      __                                            __   __   ______
 /\ \  __/\ \                                          /\ \ /\ \ /\__  _\
 \ \ \/\ \ \ \     __     __     _____     ___     ___ \ `\`\/'/'\/_/\ \/
  \ \ \ \ \ \ \  /'__`\ /'__`\  /\ '__`\  / __`\ /' _ `\`\/ > <     \ \ \
   \ \ \_/ \_\ \/\  __//\ \L\.\_\ \ \L\ \/\ \L\ \/\ \/\ \  \/'/\`\   \_\ \__
    \ `\___x___/\ \____\ \__/.\_\\ \ ,__/\ \____/\ \_\ \_\ /\_\\ \_\ /\_____\
     '\/__//__/  \/____/\/__/\/_/ \ \ \/  \/___/  \/_/\/_/ \/_/ \/_/ \/_____/
                                   \ \_\
                                    \/_/
         __         ___
        /\ \__  __ /\_ \           __
  __  __\ \ ,_\/\_\\//\ \    __  _/\_\
 /\ \/\ \\ \ \/\/\ \ \ \ \  /\ \/'\/\ \
 \ \ \_\ \\ \ \_\ \ \ \_\ \_\/>  </\ \ \                                     
  \ \____/ \ \__\\ \_\/\____\/\_/\_\\ \_\
   \/___/   \/__/ \/_/\/____/\//\/_/ \/_/

UtilXI

UtilXI, a utility library extends underscore.

[Back To Top]

UtilXI works with Node >= 0.8

npm install utilxi --save
git clone git://github.com/aponxi/npm-utilxi.git

To Install dependencies go to directory you cloned the repository to and :

npm install
npm test

or

grunt test

After installing from npm just require utilxi via:

var _ = require("utilxi")

After downloading the code, you only need lib/utilxi.js file to be on your website dir. Just add the script on your html file:

 <script src="wherever/utilxi.js"></script> 

then do:

<script type="text/javascript">
= require("/src/utilxi.coffee");
</script> 

[Back To Top]

There are two types of functions, ones that are available for client-side [web] and server-side [node]. The ones for client-side are also available for server-side.

Underscore Functions and these:

String capitalize ( String word) [web]

Capitalizes the first letter of string. Takes word argument as String and returns capitalized String.

Usage:

  console.log(_.capitalize("fabio"));
  // Fabio 

String contrastingColor ( String or Array color) [web]

This was also taken from somewhere on web... Gosh I wish I've saved the urls for reference... This function tells if you should use black or white on the background color. Takes the color argument as String or Array and color can be a hex String or an Array of RGB values 0-255 such as [255, 255, 255]. Returns "000" or "fff" for black or white.

Usage

# can either use "fff" or "ffffff" 
background = "ffffff" # white background should get black 
 
result = _.contrastingColor("ffffff") # result is "000" 
console.log result # "000" 
 

Array hexToRGBArray (String color) [web]

Taken from somewhere on web I can't recall, this function converts hex color to RGB color Array. The argument should be a 3 digit or 6 digit hex color as String. Returns an Array with Red Green Blue values as integer.

Usage:

  hex = "f5664c"
  result = _.hexToRGBArray hex
  console.dir result # [245,102, 76] 

Object merge( Object left, Object right) [web]

Taken from deepmerge package by nrf110, a function that deeply merges objects. Function returns the merged Object. Takes two arguments, left Object and right Object. Right side overwrites left side.

// Usage 
var x = { foo: { bar: 3 },
  array: [ { does: 'work', too: [ 1, 2, 3 ] },{ really: 'yes' } ] }
var y = { foo: { baz: 4 },
  quux: 5,
  array: [ { does: 'work', too: [ 3,4, 5, 6 ] }, { really: 'ysee' } ] }
 
  _.merge(x,y)
// would result 
{
    "foo": {
        "bar": 3,
        "baz": 4
    },
    "array": [
        {
            "does": "work",
            "too": [
                1,
                2,
                3,
                3,
                4,
                5,
                6
            ]
        },
        {
            "really": "ysee"
        }
    ],
    "quux": 5
}

String root() [node]

Gives the root directory of the node project, absolutely. Takes no arguments and returns the directory as String.

Usage:

console.log(_.root());
// /home/logan/projects/npm-utilxi 

void urlGetStatusCode ( String url, function callback( int responseCode)) [node]

Makes a request to the web address and calls the callback function with the http response code.

Usage:

    _.urlGetStatusCode "http://www.google.com/index.html"(code)->
        console.log code #200 
    _.urlGetStatusCode "http://www.google.com/indexaaaa.html"(code)->
        console.log code #404 

void urlGetStatusCodeReadable ( String url, function callback( String responseString)) [node]

Makes a request to the web address and calls the callback function with the http response code.

Usage:

    _.urlGetStatusCodeReadable "http://www.google.com/index.html"(code)->
        console.log code #OK 
    _.urlGetStatusCodeReadable "http://www.google.com/indexaaaa.html"(code)->
        console.log code #Not Found 

[Back To Top]

You can find all the changelogs here.

  • Added url functions
  • can get response code of the url in readable format or integer like 404 for Not Found
  • Added documentation
  • Removed browserify and other packages to make it node-only plug-in

[Back To Top]

Copyright © 2013 aponxi info@weaponxi.com

This software is licensed under MIT License.


_This readme has been automatically generated by readme generator on Tue Jul 02 2013 08:33:20 GMT-0400 (EDT)._