Overview

License


The MIT License (MIT)

Copyright (c) 2013 Bradley Workman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Util Library


The goal of this utility library is to provide tested and reviewed JavaScript functions for re-use in production environments. All public functions are contained within the "namespace" fox.util. Finally, the last goal of this project is to be written in such a way as to allow it to be split up easily into multiple files.

Functions:

  • fox.util.uuid()
  • fox.util.hash(obj)
  • fox.util.cache.read(key)
  • fox.util.cache.write(key,val,ttl)
  • fox.util.cache.erase(key)

See the source for comments on behavior.

note: all code is commented via robodoc

Examples


ex. 1

    var uuid = fox.util.uuid();
    var cache = fox.util.cache;

    var key = cache.write(uuid(), {property:"value"});
    var obj = cache.read(key);

    // object exists
    alert(JSON.stringify(obj));

    cache.erase(key);
    obj = cache.read(key);

    // object is null;
    alert(JSON.stringify(obj));

fox.util.uuid produces valid version 4 UUIDs

ex. 2

    var hash = fox.util.hash;

    var obj1 = {property="value"};
    alert(hash(obj1) == hash(obj1));

    var obj2 = {property=null};
    alert(hash(obj1) == hash(obj2));

fox.util.hash is a simple hash (ie not cryptographic)