util4js

The util4js library contains JavaScript utilities.

npm install util4js
36 downloads in the last month

util4js

The util4js module contains JavaScript utilities. util4js is free software distributed under the terms of the GNU General Public License version 3 and can be used with node.js, modern web browsers and even with PhantomJS.

Installation

npm install util4js

API

  • Object
  • Event
    • Component
  • Exception
    • ArgumentException
    • ArgumentNullException
    • IndexOutOfRangeException
  • Iterator
  • Containers
    • List
    • Dictionary
    • Set
    • Stack
    • Queue

Object

Object is a root class. Object class containts getHashCode and equals methods.

Example

"use strict";

var class4js = require("class4js");
var util4js = require("util4js.js");

var obj1 = new util4js.Object();
console.log(obj1.getHashCode());

var obj2 = new util4js.Object();
console.log(obj2.getHashCode());

console.log(util4js.Object.equals(obj1, obj2));
console.log(util4js.Object.equals(obj1, obj1));
console.log(obj1.equals(obj1));

Exception

Exception class is the base class for all exceptions.

Example

"use strict";

var class4js = require("class4js");
var util4js = require("util4js.js");

var CustomException = $class({
  __construct__: function () {
    this.name = "CustomException"; 
  }
}, util4js.Exception);

try {
  throw new CustomException({ message: "Exception was raised" });
} catch (ex) {
  console.log(ex.toString());
}

Iterator

An iterator over a collection.

Example

"use strict";

var class4js = require("class4js");
var util4js = require("util4js.js");

var iterator = new util4js.Iterator(["1", "2", "3"]);
console.log(iterator);
while (iterator.hasNext()) {
  console.log(iterator.next());
}

List

Example

var class4js = require("class4js");
var util4js = require("../../lib/util4js.js");

var list = new util4js.List(["One", "Two", "Three"]);

list.insert(0, "Zero");
list.add("Four");

for (var i = 0;i < list.count; i++) {
  console.log(list.indexOf(list.get(i)) + " " + list.get(i) + " " + list.contains(list.get(i)));
}

list.clear();

PhantomJS

PhantomJS is very similar to the Node.js. util4js package dedicated for Node.js can be taken and used in PhantomJS without any modifications.

License

This software is distributed under the terms of the GNU General Public License, version 3 (GPL-3.0).

npm loves you