partial.js logo
Latest version
v1.3.1 (RC2)

FrameworkUtils


FrameworkUtils contain helper functions and important prototypes. FrameworkUtils are available in each node.js script according the keyword utils.method() (utils is a global variable):


// utils.[method]

utils.trim({ name: '  PETER SIRKA  ' });
utils.isEmpty({});

Methods


utils.combine([param..1], [param..2], [param..n])utils.copy(target, source)utils.distance(lat1, lon1, lat2, lon2)utils.download(url, callback, [headers], [method], [params], [encoding])utils.etag(text, [version])utils.extend(target, source, [rewrite])utils.getContentType(extension)utils.GUID([max])utils.htmlDecode(str)utils.htmlEncode(str)utils.httpStatus(code, [addCode])utils.isArray(value)utils.isDate(value)utils.isEmail(value)utils.isEmpty(obj)utils.isNullOrEmpty(str)utils.isRelative(url)utils.isURL(value)utils.ls(path, callback, [filter])utils.noop()utils.parseFloat(value)utils.parseInt(value)utils.path(url, [delimiter])utils.random([max], [min])utils.reduce(source, prop)utils.removeDiacritics(value)utils.request(url, method, data, callback, [headers], encoding, timeout)utils.send(name, stream, url, [callback], [headers], [method])utils.trim(obj)utils.validate(model, properties, prepare, [builder], [resource])
utils.combine([param..1], [param..2], [param..n]);
return String;

Combine paths.

utils.copy(target, source);
return Object;

Copy values between objects. Function return target object.

utils.distance(lat1, lon1, lat2, lon2);
return Number;

Get distance (KM) from two GPS coordinates.

utils.download(url, callback, [headers], [method], [params], [encoding]);
return Boolean;

Download content or file from an url address.

utils.etag(text, [version]);
internal
return String;

Create ETag from a text.

utils.extend(target, source, [rewrite]);
return Object;

Extend object. Function return extended target object.

utils.getContentType(extension);
internal
return String;

Get content type from file extension.

utils.GUID([max]);
return String;

Create an unique identifier.

utils.htmlDecode(str);
return String;

Decode string from HTML safe characters.

utils.htmlEncode(str);
return String;

Encode string to HTML safe characters.

utils.httpStatus(code, [addCode]);
return String;

Get HTTP status code description.

utils.isArray(value);
return Boolean;

Check if value is Array.

utils.isDate(value);
return Boolean;

Check if value is Date.

utils.isEmail(value);
return Boolean;

E-mail validation.

utils.isEmpty(obj);
return Boolean;

Is empty object?

utils.isNullOrEmpty(str);
return Boolean;

Is null or empty string?

utils.isRelative(url);
return Boolean;

Check if relative URL address.

utils.isURL(value);
return Boolean;

URL address validation.

utils.ls(path, callback, [filter]);
return undefined;

Lists the contents of a directory.

utils.noop();
return undefined;

Empty function.

utils.parseFloat(value);Default: 0
return Number;

Safe parsing float number.

utils.parseInt(value);Default: 0
return Number;

Safe parsing int number.

utils.path(url, [delimiter]);
internal
return String;

Correct an URL path. Function will add a delimiter to end of path - if not exist.

utils.random([max], [min]);
return Number;

Get a random number.

utils.reduce(source, prop);
return Object;

Reduce object properties by the array or object. This function is helpful for received model from a form.

utils.removeDiacritics(value);
return String;

Remove string diacritics.

utils.request(url, method, data, callback, [headers], encoding, timeout);
return Boolean;

Create a request (GET/POST/DELETE/PUT) to URL address with custom params and headers.

utils.send(name, stream, url, [callback], [headers], [method]);
return Boolean;

Send stream or file to an url address.

utils.trim(obj);
return Object;

TRIM all string properties in an object.

utils.validate(model, properties, prepare, [builder], [resource]);
return ErrorBuilder;

Validate an object model.
IMPORTANT: If 'properties' is string then properties read by the schema validation. Read more in Builders.SchemaBuilder.