(http://fleegix.org)",
"main": "./lib/index.js",
"scripts": {
"test": "jake test"
},
"repository": {
"type": "git",
"url": "git://github.com/mde/utilities.git"
},
"devDependencies": {
"jake": "latest"
},
"engines": {
"node": "*"
}
}
utilities-1.0.6/test/ 0000775 0000000 0000000 00000000000 14237004417 0014512 5 ustar 00root root 0000000 0000000 utilities-1.0.6/test/array.js 0000664 0000000 0000000 00000003724 14237004417 0016174 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var assert = require('assert')
, array = require('../lib/array')
, tests;
tests = {
'test basic humanize for array': function () {
var actual = array.humanize(["array", "array", "array"])
, expected = "array, array and array";
assert.equal(expected, actual);
}
, 'test humanize with two items for array': function () {
var actual = array.humanize(["array", "array"])
, expected = "array and array";
assert.equal(expected, actual);
}
, 'test humanize with a single item for array': function () {
var actual = array.humanize(["array"])
, expected = "array";
assert.equal(expected, actual);
}
, 'test humanize with no items for array': function () {
var actual = array.humanize([])
, expected = "";
assert.equal(expected, actual);
}
, 'test basic include for array': function () {
var test = ["array"]
, actual = array.include(test, "array");
assert.equal(true, actual);
}
, 'test false include for array': function () {
var test = ["array"]
, actual = array.include(test, 'nope');
assert.equal(false, actual);
}
, 'test false boolean include for array': function () {
var test = ["array", false]
, actual = array.include(test, false);
assert.equal(true, actual);
}
};
module.exports = tests;
utilities-1.0.6/test/core.js 0000664 0000000 0000000 00000005161 14237004417 0016003 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var assert = require('assert')
, core = require('../lib/core')
, tests;
tests = {
'simple mixin for core': function () {
var expected = {secret: 'asdf', geddy: 'geddyKey'}
, result = core.mixin({secret: 'asdf'}, {geddy: 'geddyKey'});
assert.deepEqual(expected, result);
}
, 'mixin with overiding key for core': function () {
var expected = {secret: 'geddySecret', geddy: 'geddyKey'}
, result = core.mixin({secret: 'asdf'}, {geddy: 'geddyKey', secret: 'geddySecret'});
assert.deepEqual(expected, result);
}
, 'simple enhance for core': function () {
var expected = {secret: 'asdf', geddy: 'geddyKey'}
, result = core.enhance({secret: 'asdf'}, {geddy: 'geddyKey'});
assert.deepEqual(expected, result);
}
, 'enhance with overiding key for core': function () {
var expected = {secret: 'geddySecret', geddy: 'geddyKey'}
, result = core.enhance({secret: 'asdf'}, {geddy: 'geddyKey', secret: 'geddySecret'});
assert.deepEqual(expected, result);
}
, 'isEmpty, empty string (true)': function () {
assert.ok(core.isEmpty(''));
}
, 'isEmpty, null (true)': function () {
assert.ok(core.isEmpty(null));
}
, 'isEmpty, undefined (true)': function () {
assert.ok(core.isEmpty(null));
}
, 'isEmpty, NaN (true)': function () {
assert.ok(core.isEmpty(NaN));
}
, 'isEmpty, invalid Date (true)': function () {
assert.ok(core.isEmpty(new Date(NaN)));
}
, 'isEmpty, zero (false)': function () {
assert.ok(!core.isEmpty(0));
}
,
'bind': function () {
function bar() {}
function foo() {
assert.equal(this.name, 'bar');
}
var fooBoundToBar = core.bind(bar, foo);
fooBoundToBar();
}
,
'bind, arguments': function () {
function bar() {}
function foo(arg) {
assert.equal(this.name, 'bar');
assert.equal(arg, 'cats');
}
var fooBoundToBarWithCats = core.bind(bar, foo, 'cats');
fooBoundToBarWithCats();
}
};
module.exports = tests;
utilities-1.0.6/test/date.js 0000664 0000000 0000000 00000004642 14237004417 0015773 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var date = require('../lib/date')
, assert = require('assert')
, tests = {}
, _date = new Date();
tests = {
'test strftime for date': function () {
var data = date.strftime(_date, "%w")
, actual = _date.getDay();
assert.equal(actual, data);
}
, 'test calcCentury using current year for date': function () {
var data = date.calcCentury()
, actual = '21';
assert.equal(actual, data);
}
, 'test calcCentury using 20th century year for date': function () {
var data = date.calcCentury(2000)
, actual = '20';
assert.equal(actual, data);
}
, 'test calcCentury using 1st century year for date': function () {
var data = date.calcCentury(10)
, actual = '1';
assert.equal(actual, data);
}
, 'test getMeridiem for date': function () {
var data = date.getMeridiem(_date.getHours())
, actual = (_date.getHours() > 11) ? 'PM' : 'AM';
assert.equal(actual, data);
}
, 'test parse UTC': function () {
var dt = date.parse('1970-01-01T00:00:00Z');
assert.equal(0, dt.getTime());
}
, 'test parse with offset basic': function () {
var dt;
dt = date.parse('1970-01-01T00:00:00-0100');
assert.equal(3600000, dt.getTime());
dt = date.parse('1970-01-01T00:00:00+0100');
assert.equal(-3600000, dt.getTime());
}
, 'test parse with offset extended': function () {
var dt;
dt = date.parse('1970-01-01T00:00:00-01:00');
assert.equal(3600000, dt.getTime());
dt = date.parse('1970-01-01T00:00:00+01:00');
assert.equal(-3600000, dt.getTime());
}
, 'test parse floating (i.e., local offset)': function () {
var dt;
dt = date.parse('1970-01-01T00:00:00');
assert.equal(dt.getTime() / 1000 / 60, dt.getTimezoneOffset());
}
};
module.exports = tests;
utilities-1.0.6/test/event_buffer.js 0000664 0000000 0000000 00000002607 14237004417 0017527 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var Stream = require('stream').Stream
, EventEmitter = require('events').EventEmitter
, EventBuffer = require('../lib/event_buffer.js').EventBuffer
, assert = require('assert')
, tests;
tests = {
'test basic event buffer functionality': function () {
var source = new Stream()
, dest = new EventEmitter()
, buff = new EventBuffer(source)
, data = '';
dest.on('data', function (d) { data += d; });
source.writeable = true;
source.readable = true;
source.emit('data', 'abcdef');
source.emit('data', '123456');
buff.sync(dest);
assert.equal('abcdef123456', data);
source.emit('data', '---');
assert.equal('abcdef123456---', data);
}
};
module.exports = tests;
utilities-1.0.6/test/file.js 0000664 0000000 0000000 00000024566 14237004417 0016004 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var assert = require('assert')
, fs = require('fs')
, path = require('path')
, file = require('../lib/file')
, existsSync = fs.existsSync || path.existsSync
, tests;
tests = {
'before': function () {
process.chdir('./test');
}
, 'after': function () {
process.chdir('../');
}
, 'test mkdirP': function () {
var expected = [
['foo']
, ['foo', 'bar']
, ['foo', 'bar', 'baz']
, ['foo', 'bar', 'baz', 'qux']
]
, res;
file.mkdirP('foo/bar/baz/qux');
res = file.readdirR('foo');
for (var i = 0, ii = res.length; i < ii; i++) {
assert.equal(path.join.apply(path, expected[i]), res[i]);
}
file.rmRf('foo', {silent: true});
}
, 'test rmRf': function () {
file.mkdirP('foo/bar/baz/qux', {silent: true});
file.rmRf('foo/bar', {silent: true});
res = file.readdirR('foo');
assert.equal(1, res.length);
assert.equal('foo', res[0]);
fs.rmdirSync('foo');
}
, 'test rmRf with symlink subdir': function () {
file.mkdirP('foo');
file.mkdirP('bar');
fs.writeFileSync('foo/hello.txt', 'hello, it\'s me');
fs.symlinkSync('../foo', 'bar/foo');
file.rmRf('bar', {silent: true});
// Make sure the bar directory was successfully deleted
var barDeleted = false;
try {
var stat = fs.statSync('bar');
} catch(err) {
if(err.code == 'ENOENT') {
barDeleted = true;
}
}
assert.equal(true, barDeleted);
// Make sure that the file inside the linked folder wasn't deleted
res = fs.readdirSync('foo');
assert.equal(1, res.length);
assert.equal('hello.txt', res[0]);
// Cleanup
fs.unlinkSync('foo/hello.txt');
fs.rmdirSync('foo');
}
, 'test rmRf with symlinked dir': function () {
file.mkdirP('foo');
fs.writeFileSync('foo/hello.txt', 'hello!');
fs.symlinkSync('foo', 'bar');
file.rmRf('bar', {silent: true});
// Make sure the bar directory was successfully deleted
var barDeleted = false;
try {
var stat = fs.statSync('bar');
} catch(err) {
if(err.code == 'ENOENT') {
barDeleted = true;
}
}
assert.equal(true, barDeleted);
// Make sure that the file inside the linked folder wasn't deleted
res = fs.readdirSync('foo');
assert.equal(1, res.length);
assert.equal('hello.txt', res[0]);
// Cleanup
fs.unlinkSync('foo/hello.txt');
fs.rmdirSync('foo');
}
, 'test cpR with same name and different directory': function () {
file.mkdirP('foo', {silent: true});
fs.writeFileSync('foo/bar.txt', 'w00t');
file.cpR('foo', 'bar', {silent: true});
assert.ok(existsSync('bar/bar.txt'));
file.rmRf('foo', {silent: true});
file.rmRf('bar', {silent: true});
}
, 'test cpR with same to and from will throw': function () {
assert.throws(function () {
file.cpR('foo.txt', 'foo.txt', {silent: true});
});
}
, 'test cpR rename via copy in directory': function () {
file.mkdirP('foo', {silent: true});
fs.writeFileSync('foo/bar.txt', 'w00t');
file.cpR('foo/bar.txt', 'foo/baz.txt', {silent: true});
assert.ok(existsSync('foo/baz.txt'));
file.rmRf('foo', {silent: true});
}
, 'test cpR rename via copy in base': function () {
fs.writeFileSync('bar.txt', 'w00t');
file.cpR('bar.txt', 'baz.txt', {silent: true});
assert.ok(existsSync('baz.txt'));
file.rmRf('bar.txt', {silent: true});
file.rmRf('baz.txt', {silent: true});
}
, 'test cpR keeps file mode': function () {
fs.writeFileSync('bar.txt', 'w00t', {mode: 0750});
fs.writeFileSync('bar1.txt', 'w00t!', {mode: 0744});
file.cpR('bar.txt', 'baz.txt', {silent: true});
file.cpR('bar1.txt', 'baz1.txt', {silent: true});
assert.ok(existsSync('baz.txt'));
assert.ok(existsSync('baz1.txt'));
var bazStat = fs.statSync('baz.txt');
var bazStat1 = fs.statSync('baz1.txt');
assert.equal(0750, bazStat.mode & 07777);
assert.equal(0744, bazStat1.mode & 07777);
file.rmRf('bar.txt', {silent: true});
file.rmRf('baz.txt', {silent: true});
file.rmRf('bar1.txt', {silent: true});
file.rmRf('baz1.txt', {silent: true});
}
, 'test cpR keeps file mode when overwriting with preserveMode': function () {
fs.writeFileSync('bar.txt', 'w00t', {mode: 0755});
fs.writeFileSync('baz.txt', 'w00t!', {mode: 0744});
file.cpR('bar.txt', 'baz.txt', {silent: true, preserveMode: true});
assert.ok(existsSync('baz.txt'));
var bazStat = fs.statSync('baz.txt');
assert.equal(0755, bazStat.mode & 07777);
file.rmRf('bar.txt', {silent: true});
file.rmRf('baz.txt', {silent: true});
}
, 'test cpR does not keep file mode when overwriting': function () {
fs.writeFileSync('bar.txt', 'w00t', {mode: 0766});
fs.writeFileSync('baz.txt', 'w00t!', {mode: 0744});
file.cpR('bar.txt', 'baz.txt', {silent: true});
assert.ok(existsSync('baz.txt'));
var bazStat = fs.statSync('baz.txt');
assert.equal(0744, bazStat.mode & 07777);
file.rmRf('bar.txt', {silent: true});
file.rmRf('baz.txt', {silent: true});
}
, 'test cpR copies file mode recursively': function () {
fs.mkdirSync('foo');
fs.writeFileSync('foo/bar.txt', 'w00t', {mode: 0740});
file.cpR('foo', 'baz', {silent: true});
assert.ok(existsSync('baz'));
var barStat = fs.statSync('baz/bar.txt');
assert.equal(0740, barStat.mode & 07777);
file.rmRf('foo');
file.rmRf('baz');
}
, 'test cpR keeps file mode recursively': function () {
fs.mkdirSync('foo');
fs.writeFileSync('foo/bar.txt', 'w00t', {mode: 0740});
fs.mkdirSync('baz');
fs.mkdirSync('baz/foo');
fs.writeFileSync('baz/foo/bar.txt', 'w00t!', {mode: 0755});
file.cpR('foo', 'baz', {silent: true, preserveMode: true});
assert.ok(existsSync('baz'));
var barStat = fs.statSync('baz/foo/bar.txt');
assert.equal(0740, barStat.mode & 07777);
file.rmRf('foo');
file.rmRf('baz');
}
, 'test cpR copies directory mode recursively': function () {
fs.mkdirSync('foo', 0755);
fs.mkdirSync('foo/bar', 0700);
file.cpR('foo', 'bar');
assert.ok(existsSync('foo'));
var fooBarStat = fs.statSync('bar/bar');
assert.equal(0700, fooBarStat.mode & 07777);
file.rmRf('foo');
file.rmRf('bar');
}
, 'test readdirR': function () {
var expected = [
['foo']
, ['foo', 'bar']
, ['foo', 'bar', 'baz']
, ['foo', 'bar', 'baz', 'qux']
]
, res;
file.mkdirP('foo/bar/baz/qux', {silent: true});
res = file.readdirR('foo');
for (var i = 0, ii = res.length; i < ii; i++) {
assert.equal(path.join.apply(path, expected[i]), res[i]);
}
file.rmRf('foo', {silent: true});
}
, 'test isAbsolute with Unix absolute path': function () {
var p = '/foo/bar/baz';
assert.equal('/', file.isAbsolute(p));
}
, 'test isAbsolute with Unix relative path': function () {
var p = 'foo/bar/baz';
assert.equal(false, file.isAbsolute(p));
}
, 'test isAbsolute with Win absolute path': function () {
var p = 'C:\\foo\\bar\\baz';
assert.equal('C:\\', file.isAbsolute(p));
}
, 'test isAbsolute with Win relative path': function () {
var p = 'foo\\bar\\baz';
assert.equal(false, file.isAbsolute(p));
}
, 'test absolutize with Unix absolute path': function () {
var expected = '/foo/bar/baz'
, actual = file.absolutize('/foo/bar/baz');
assert.equal(expected, actual);
}
, 'test absolutize with Win absolute path': function () {
var expected = 'C:\\foo\\bar\\baz'
, actual = file.absolutize('C:\\foo\\bar\\baz');
assert.equal(expected, actual);
}
, 'test absolutize with relative path': function () {
var expected = process.cwd()
, actual = '';
// We can't just create two different tests here
// because file.absolutize uses process.cwd()
// to get absolute path which is platform
// specific
if (process.platform === 'win32') {
expected += '\\foo\\bar\\baz'
actual = file.absolutize('foo\\bar\\baz')
}
else {
expected += '/foo/bar/baz'
actual = file.absolutize('foo/bar/baz');
}
assert.equal(expected, actual);
}
, 'test basedir with Unix absolute path': function () {
var p = '/foo/bar/baz';
assert.equal('/foo/bar', file.basedir(p));
}
, 'test basedir with Win absolute path': function () {
var p = 'C:\\foo\\bar\\baz';
assert.equal('C:\\foo\\bar', file.basedir(p));
}
, 'test basedir with Unix root path': function () {
var p = '/';
assert.equal('/', file.basedir(p));
}
, 'test basedir with Unix absolute path and double-asterisk': function () {
var p = '/**/foo/bar/baz';
assert.equal('/', file.basedir(p));
}
, 'test basedir with leading double-asterisk': function () {
var p = '**/foo';
assert.equal('.', file.basedir(p));
}
, 'test basedir with leading asterisk': function () {
var p = '*.js';
assert.equal('.', file.basedir(p));
}
, 'test basedir with leading dot-slash and double-asterisk': function () {
var p = './**/foo';
assert.equal('.', file.basedir(p));
}
, 'test basedir with leading dirname and double-asterisk': function () {
var p = 'a/**/*.js';
assert.equal('a', file.basedir(p));
}
, 'test basedir with leading dot-dot-slash and double-asterisk': function () {
var p = '../../test/**/*.js';
assert.equal('../../test', file.basedir(p));
}
, 'test basedir with single-asterisk in dirname': function () {
var p = 'a/test*/file';
assert.equal('a', file.basedir(p));
}
, 'test basedir with single filename': function () {
var p = 'filename';
assert.equal('.', file.basedir(p));
}
, 'test basedir with empty path': function () {
var p = '';
assert.equal('.', file.basedir(p));
assert.equal('.', file.basedir());
}
};
module.exports = tests;
utilities-1.0.6/test/i18n.js 0000664 0000000 0000000 00000003307 14237004417 0015632 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var i18n = require('../lib/i18n')
, assert = require('assert')
, tests
, inst = {};
tests = {
'before': function () {
i18n.loadLocale('en-us', {foo: 'FOO', bar: 'BAR', baz: 'BAZ'});
i18n.loadLocale('ja-jp', {foo: 'フー', bar: 'バー'});
inst.en = new i18n.I18n('en-us');
inst.jp = new i18n.I18n('ja-jp');
inst.de = new i18n.I18n('de-de');
}
, 'test default-locale fallback, defined strings': function () {
var expected = 'BAZ'
, actual = inst.jp.t('baz');
assert.equal(expected, actual);
}
, 'test default-locale fallback, no defined strings': function () {
var expected = 'BAZ'
, actual = inst.de.t('baz');
assert.equal(expected, actual);
}
, 'test key lookup, default-locale': function () {
var expected = 'FOO'
, actual = inst.en.t('foo');
assert.equal(expected, actual);
}
, 'test key lookup, non-default-locale': function () {
var expected = 'フー'
, actual = inst.jp.t('foo');
assert.equal(expected, actual);
}
};
module.exports = tests;
utilities-1.0.6/test/inflection.js 0000664 0000000 0000000 00000033360 14237004417 0017207 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var inflection = require('../lib/inflection')
, assert = require('assert')
, esInflections
, sInflections
, iesInflections
, vesInflections
, icesInflections
, renInflections
, oesInflections
, iInflections
, genInflections
, irregularInflections
, noInflections
, tests;
/**
* Most test inflections are from Ruby on Rails:
* https://github.com/rails/rails/blob/master/activesupport/test/inflector_test_cases.rb
*
* Ruby on Rails is MIT licensed: http://www.opensource.org/licenses/MIT
*/
esInflections = [
["search", "searches"]
, ["switch", "switches"]
, ["fix", "fixes"]
, ["box", "boxes"]
, ["process", "processes"]
, ["address", "addresses"]
, ["wish", "wishes"]
, ["status", "statuses"]
, ["alias", "aliases"]
, ["basis", "bases"]
, ["diagnosis", "diagnoses"]
, ["bus", "buses"]
];
sInflections = [
["stack", "stacks"]
, ["shoe", "shoes"]
, ["status_code", "status_codes"]
, ["case", "cases"]
, ["edge", "edges"]
, ["archive", "archives"]
, ["experience", "experiences"]
, ["day", "days"]
, ["comment", "comments"]
, ["foobar", "foobars"]
, ["newsletter", "newsletters"]
, ["old_news", "old_news"]
, ["perspective", "perspectives"]
, ["diagnosis_a", "diagnosis_as"]
, ["horse", "horses"]
, ["prize", "prizes"]
];
iesInflections = [
["category", "categories"]
, ["query", "queries"]
, ["ability", "abilities"]
, ["agency", "agencies"]
];
vesInflections = [
["wife", "wives"]
, ["safe", "saves"]
, ["half", "halves"]
, ["elf", "elves"]
, ["dwarf", "dwarves"]
];
icesInflections = [
["index", "indices"]
, ["vertex", "vertices"]
, ["matrix", "matrices"]
];
renInflections = [
["node_child", "node_children"]
, ["child", "children"]
];
oesInflections = [
["buffalo", "buffaloes"]
, ["tomato", "tomatoes"]
];
iInflections = [
["octopus", "octopi"]
, ["virus", "viri"]
];
genInflections = [
["salesperson", "salespeople"]
, ["person", "people"]
, ["spokesman", "spokesmen"]
, ["man", "men"]
, ["woman", "women"]
];
irregularInflections = [
["datum", "data"]
, ["medium", "media"]
, ["ox", "oxen"]
, ["cow", "kine"]
, ["mouse", "mice"]
, ["louse", "lice"]
, ["axis", "axes"]
, ["testis", "testes"]
, ["crisis", "crises"]
, ["analysis", "analyses"]
, ["quiz", "quizzes"]
];
noInflections = [
["fish", "fish"]
, ["news", "news"]
, ["series", "series"]
, ["species", "species"]
, ["rice", "rice"]
, ["information", "information"]
, ["equipment", "equipment"]
];
tests = {
'test es plural words for inflection': function () {
var i = esInflections.length
, value;
while (--i >= 0) {
value = esInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test es singular words for inflection': function () {
var i = esInflections.length
, value;
while (--i >= 0) {
value = esInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test es plural words for inflection consistency': function() {
var i = esInflections.length
, value;
while (--i >= 0) {
value = esInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test es singular words for inflection consistency': function() {
var i = esInflections.length
, value;
while (--i >= 0) {
value = esInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test s plural words for inflection': function () {
var i = sInflections.length
, value;
while (--i >= 0) {
value = sInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test s singular words for inflection': function () {
var i = sInflections.length
, value;
while (--i >= 0) {
value = sInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test s plural words for inflection consistency': function () {
var i = sInflections.length
, value;
while (--i >= 0) {
value = sInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test s singular words for inflection consistency': function () {
var i = sInflections.length
, value;
while (--i >= 0) {
value = sInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test ies plural words for inflection': function () {
var i = iesInflections.length
, value;
while (--i >= 0) {
value = iesInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test ies singular words for inflection': function () {
var i = iesInflections.length
, value;
while (--i >= 0) {
value = iesInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test ies plural words for inflection consistency': function () {
var i = iesInflections.length
, value;
while (--i >= 0) {
value = iesInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test ies singular words for inflection consistency': function () {
var i = iesInflections.length
, value;
while (--i >= 0) {
value = iesInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test ves plural words for inflection': function () {
var i = vesInflections.length
, value;
while (--i >= 0) {
value = vesInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test ves singular words for inflection': function () {
var i = vesInflections.length
, value;
while (--i >= 0) {
value = vesInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test ves plural words for inflection consistency': function () {
var i = vesInflections.length
, value;
while (--i >= 0) {
value = vesInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test ves singular words for inflection consistency': function () {
var i = vesInflections.length
, value;
while (--i >= 0) {
value = vesInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test ices plural words for inflection': function () {
var i = icesInflections.length
, value;
while (--i >= 0) {
value = icesInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test ices singular words for inflection': function () {
var i = icesInflections.length
, value;
while (--i >= 0) {
value = icesInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test ices plural words for inflection consistency': function () {
var i = icesInflections.length
, value;
while (--i >= 0) {
value = icesInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test ices singular words for inflection consistency': function () {
var i = icesInflections.length
, value;
while (--i >= 0) {
value = icesInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test ren plural words for inflection': function () {
var i = renInflections.length
, value;
while (--i >= 0) {
value = renInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test ren singular words for inflection': function () {
var i = renInflections.length
, value;
while (--i >= 0) {
value = renInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test ren plural words for inflection consistency': function () {
var i = renInflections.length
, value;
while (--i >= 0) {
value = renInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test ren singular words for inflection consistency': function () {
var i = renInflections.length
, value;
while (--i >= 0) {
value = renInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test oes plural words for inflection': function () {
var i = oesInflections.length
, value;
while (--i >= 0) {
value = oesInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test oes singular words for inflection': function () {
var i = oesInflections.length
, value;
while (--i >= 0) {
value = oesInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test oes plural words for inflection consistency': function () {
var i = oesInflections.length
, value;
while (--i >= 0) {
value = oesInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test oes singular words for inflection consistency': function () {
var i = oesInflections.length
, value;
while (--i >= 0) {
value = oesInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test i plural words for inflection': function () {
var i = iInflections.length
, value;
while (--i >= 0) {
value = iInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test i singular words for inflection': function () {
var i = iInflections.length
, value;
while (--i >= 0) {
value = iInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test i plural words for inflection consistency': function () {
var i = iInflections.length
, value;
while (--i >= 0) {
value = iInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test i singular words for inflection consistency': function () {
var i = iInflections.length
, value;
while (--i >= 0) {
value = iInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test gender and people plural words for inflection': function () {
var i = genInflections.length
, value;
while (--i >= 0) {
value = genInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test gender and people singular words for inflection': function () {
var i = genInflections.length
, value;
while (--i >= 0) {
value = genInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test gender and people plural words for inflection consistency': function () {
var i = genInflections.length
, value;
while (--i >= 0) {
value = genInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test gender and people singular words for inflection consistency': function () {
var i = genInflections.length
, value;
while (--i >= 0) {
value = genInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test irregular plural words for inflection': function () {
var i = irregularInflections.length
, value;
while (--i >= 0) {
value = irregularInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test irregular singular words for inflection': function () {
var i = irregularInflections.length
, value;
while (--i >= 0) {
value = irregularInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test irregular plural words for inflection consistency': function () {
var i = irregularInflections.length
, value;
while (--i >= 0) {
value = irregularInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test irregular singular words for inflection consistency': function () {
var i = irregularInflections.length
, value;
while (--i >= 0) {
value = irregularInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
, 'test no change plural words for inflection': function () {
var i = noInflections.length
, value;
while (--i >= 0) {
value = noInflections[i];
assert.equal(value[1], inflection.pluralize(value[0]))
}
}
, 'test no change singular words for inflection': function () {
var i = noInflections.length
, value;
while (--i >= 0) {
value = noInflections[i];
assert.equal(value[0], inflection.singularize(value[1]))
}
}
, 'test no change plural words for inflection consistency': function () {
var i = noInflections.length
, value;
while (--i >= 0) {
value = noInflections[i];
assert.equal(value[1], inflection.pluralize(value[1]))
}
}
, 'test no change singular words for inflection consistency': function () {
var i = noInflections.length
, value;
while (--i >= 0) {
value = noInflections[i];
assert.equal(value[0], inflection.singularize(value[0]))
}
}
};
module.exports = tests;
utilities-1.0.6/test/logging.js 0000664 0000000 0000000 00000003477 14237004417 0016511 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var assert = require('assert')
, logger = require('../lib/log')
, tests;
tests = {
'test basic logging': function () {
var oldLog = console.log;
console.log = function (str) {
assert.equal(str, "basic log");
};
logger.log("basic log");
console.log = oldLog;
}
, 'test info logging': function () {
var oldinfoLog = console.info;
console.info = function (str) {
assert.equal(str, "info log");
};
logger.info("info log");
console.info = oldinfoLog;
}
, 'test warning logging': function () {
var oldwarnLog = console.warn;
console.warn = function (str) {
assert.equal(str, "warn log");
};
logger.warn("warn log");
console.warn = oldwarnLog;
}
, 'test error logging': function () {
var oldErrorLog = console.error;
console.error = function (str) {
assert.equal(str, "error log");
};
logger.error("error log");
console.error = oldErrorLog;
}
}
module.exports = tests; utilities-1.0.6/test/object.js 0000664 0000000 0000000 00000005161 14237004417 0016321 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var object = require('../lib/object')
, array = require('../lib/array')
, assert = require('assert')
, tests = {}
, checkObjects;
tests = {
'test merge in object': function () {
var expected = {user: 'geddy', key: 'key'}
, actual = object.merge({user: 'geddy'}, {key: 'key'});
assert.deepEqual(actual, expected);
}
, 'test merge with overwriting keys in object': function () {
var expected = {user: 'geddy', key: 'key'}
, actual = object.merge({user: 'geddy', key: 'geddyKey'}, {key: 'key'});
assert.deepEqual(actual, expected);
}
, 'test merge with objects as keys': function () {
var expected = {user: {name: 'geddy', password: 'random', key: 'key'}, key: 'key'}
, actual = object.merge({key: 'key'}, {user: {name: 'geddy', password: 'random', key: 'key'}});
assert.deepEqual(actual, expected);
}
, 'test reverseMerge in object': function () {
var expected = {user: 'geddy', key: 'key'}
, actual = object.reverseMerge({user: 'geddy'}, {key: 'key'});
assert.deepEqual(actual, expected);
}
, 'test reverseMerge with keys overwriting default in object': function () {
var expected = {user: 'geddy', key: 'geddyKey'}
, actual = object.reverseMerge({user: 'geddy', key: 'geddyKey'}, {key: 'key'});
assert.deepEqual(actual, expected);
}
, 'test reverseMerge with objects as keys': function () {
var expected = {user: {name: 'geddy', password: 'random', key: 'key'}, key: 'key'}
, actual = object.merge({user: {name: 'geddy', password: 'random', key: 'key'}}, {key: 'key'});
assert.deepEqual(actual, expected);
}
, 'test isEmpty with non empty object in object': function () {
var expected = false
, actual = object.isEmpty({user: 'geddy'});
assert.equal(actual, expected);
}
, 'test isEmpty with empty object in object': function () {
var expected = true
, actual = object.isEmpty({});
assert.equal(actual, expected);
}
};
module.exports = tests;
utilities-1.0.6/test/sorted_collection.js 0000664 0000000 0000000 00000006306 14237004417 0020570 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var SortedCollection = require('../lib/sorted_collection').SortedCollection
, assert = require('assert')
, tests;
tests = {
'test no default value': function () {
// Set up a collection, no default value for new items
var c = new SortedCollection();
// Add some items
c.addItem('testA', 'AAAA');
c.addItem('testB', 'BBBB');
c.addItem('testC', 'CCCC');
// Test count
assert.equal(3, c.count);
// Test getItem by string key
var item = c.getItem('testC');
assert.equal('CCCC', item);
// Test getItem by index number
var item = c.getItem(1);
assert.equal('BBBB', item);
// Test setItem by string key
c.setItem('testA', 'aaaa');
var item = c.getItem('testA');
assert.equal('aaaa', item);
// Test setItem by index number
c.setItem(2, 'cccc');
var item = c.getItem(2);
assert.equal('cccc', item);
}
, 'test default value': function () {
// Set up a collection, default value for new items is 'foo'
var c = new SortedCollection('foo');
// Add an item with no value -- should get
// default value
c.addItem('testA');
// Add some items with empty/falsey values --
// should be set to desired values
c.addItem('testB', null);
c.addItem('testC', false);
// Test getItem for default value
var item = c.getItem('testA');
assert.equal('foo', item);
var item = c.getItem('testB');
assert.equal(null, item);
var item = c.getItem('testC');
assert.equal(false, item);
}
, 'test each': function () {
var c = new SortedCollection()
, str = '';
// Add an item with no value -- should get
// default value
c.addItem('a', 'A');
c.addItem('b', 'B');
c.addItem('c', 'C');
c.addItem('d', 'D');
c.each(function (val, key) {
str += val + key;
});
assert.equal('AaBbCcDd', str);
}
, 'test removing an item': function () {
var c = new SortedCollection()
, str = '';
// Add an item with no value -- should get
// default value
c.addItem('a', 'A');
c.addItem('b', 'B');
c.addItem('c', 'C');
c.addItem('d', 'D');
assert.equal(4, c.count);
omg = c.removeItem('c');
assert.equal(3, c.count);
c.each(function (val, key) {
str += val + key;
});
assert.equal('AaBbDd', str);
}
, 'test clone': function () {
var c = new SortedCollection()
, copy;
c.addItem('a', 'A');
c.addItem('b', 'B');
copy = c.clone();
assert.equal(2, copy.count);
assert.equal('A', copy.getItem('a'));
}
};
module.exports = tests;
utilities-1.0.6/test/string.js 0000664 0000000 0000000 00000030305 14237004417 0016357 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var assert = require('assert')
, string = require('../lib/string')
, tests;
tests = {
'test basic escapeXML for string': function () {
var expected = '<html></html>'
, actual = string.escapeXML('');
assert.equal(expected, actual);
}
, 'test all escape characters for escapeXML': function () {
var expected = '<>&"''
, actual = string.escapeXML('<>&"\'');
assert.equal(expected, actual);
}
, 'test no escape characters with string for escapeXML': function () {
var expected = 'Geddy'
, actual = string.escapeXML('Geddy');
assert.equal(expected, actual);
}
, 'test no escape characters with numbers for escapeXML': function () {
var expected = 05
, actual = string.escapeXML(05);
assert.equal(expected, actual);
}
, 'test basic unescapeXML for string': function () {
var expected = ''
, actual = string.unescapeXML('<html></html>');
assert.equal(expected, actual);
}
, 'test all escape characters for unescapeXML': function () {
var expected = '<>&"\''
, actual = string.unescapeXML('<>&"'');
assert.equal(expected, actual);
}
, 'test no escape characters with string for unescapeXML': function () {
var expected = 'Geddy'
, actual = string.unescapeXML('Geddy');
assert.equal(expected, actual);
}
, 'test no escape characters with numbers for unescapeXML': function () {
var expected = 05
, actual = string.unescapeXML(05);
assert.equal(expected, actual);
}
, 'test basic needsEscape for string': function () {
var expected = true
, actual = string.needsEscape('Geddy>');
assert.equal(expected, actual);
}
, 'test basic needsEscape thats false for string': function () {
var expected = false
, actual = string.needsEscape('Geddy');
assert.equal(expected, actual);
}
, 'test basic needsUnescape for string': function () {
var expected = true
, actual = string.needsEscape('"Geddy"');
assert.equal(expected, actual);
}
, 'test basic needsUnescape thats false for string': function () {
var expected = false
, actual = string.needsEscape('Geddy');
assert.equal(expected, actual);
}
, 'test escapeRegExpCharacters': function () {
var expected = '\\^\\/\\.\\*\\+\\?\\|\\(\\)\\[\\]\\{\\}\\\\'
actual = string.escapeRegExpChars('^/.*+?|()[]{}\\');
assert.equal(expected, actual);
}
, 'test toArray for string': function () {
var data = string.toArray('geddy')
, expected = ['g', 'e', 'd', 'd', 'y'];
// Loop through each item and check
// if not, then the arrays aren't _really_ the same
var i = expected.length;
while (--i >= 0) {
assert.equal(expected[i], data[i]);
}
}
, 'test reverse for string': function () {
var data = string.reverse('yddeg')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test basic ltrim for string': function () {
var data = string.ltrim(' geddy')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test custom char ltrim for string': function () {
var data = string.ltrim('&&geddy', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test basic rtrim for string': function () {
var data = string.rtrim('geddy ')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test custom char rtrim for string': function () {
var data = string.rtrim('geddy&&', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test basic trim for string': function () {
var data = string.trim(' geddy ')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test custom char trim for string': function () {
var data = string.trim('&geddy&&', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test chop special-case line-ending': function () {
var expected = 'geddy'
, actual = string.chop('geddy\r\n');
assert.equal(expected, actual);
}
, 'test chop not actual special-case line-ending': function () {
var expected = 'geddy\n'
, actual = string.chop('geddy\n\r');
assert.equal(expected, actual);
}
, 'test chop normal line-ending': function () {
var expected = 'geddy'
, actual = string.chop('geddy\n');
assert.equal(expected, actual);
}
, 'test chop whatever character': function () {
var expected = 'gedd'
, actual = string.chop('geddy');
assert.equal(expected, actual);
}
, 'test chop empty string': function () {
var expected = ''
, actual = string.chop('');
assert.equal(expected, actual);
}
, 'test basic lpad for string': function () {
var data = string.lpad('geddy', '&', 7)
, expected = '&&geddy';
assert.equal(expected, data);
}
, 'test lpad without width for string': function () {
var data = string.lpad('geddy', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test lpad without width of char for string': function () {
var data = string.lpad('geddy')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test basic rpad for string': function () {
var data = string.rpad('geddy', '&', 7)
, expected = 'geddy&&';
assert.equal(expected, data);
}
, 'test rpad without width for string': function () {
var data = string.rpad('geddy', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test rpad without width of char for string': function () {
var data = string.rpad('geddy')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test basic pad for string': function () {
var data = string.pad('geddy', '&', 7)
, expected = '&geddy&';
assert.equal(expected, data);
}
, 'test pad without width for string': function () {
var data = string.pad('geddy', '&')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test pad without width of char for string': function () {
var data = string.pad('geddy')
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test single tags in truncateHTML': function () {
var str = string.truncateHTML('Once upon a time in a world
', { length: 10 });
assert.equal(str, 'Once up...
');
}
, 'test multiple tags in truncateHTML': function () {
var str = string.truncateHTML('Once upon a time in a world
', { length: 10 });
assert.equal(str, 'Once up...in a wo...
');
}
, 'test multiple tags but only truncate once in truncateHTML': function () {
var str = string.truncateHTML('Once upon a time in a world
', { length: 10, once: true });
assert.equal(str, 'Once up...in a world
');
}
, 'test standard truncate': function () {
var str = string.truncate('Once upon a time in a world', { length: 10 });
assert.equal(str, 'Once up...');
}
, 'test custom omission in truncate': function () {
var str = string.truncate('Once upon a time in a world', { length: 10, omission: '///' });
assert.equal(str, 'Once up///');
}
, 'test regex seperator in truncate': function () {
var str = string.truncate('Once upon a time in a world', { length: 15, seperator: /\s/ });
assert.equal(str, 'Once upon a...');
}
, 'test string seperator in truncate': function () {
var str = string.truncate('Once upon a time in a world', { length: 15, seperator: ' ' });
assert.equal(str, 'Once upon a...');
}
, 'test unsafe html in truncate': function () {
var str = string.truncate('Once upon a time in a world
', { length: 20 });
assert.equal(str, 'Once upon a ti...');
}
, 'test nl2br for string': function () {
var data = string.nl2br("geddy\n")
, expected = 'geddy
';
assert.equal(expected, data);
}
, 'test snakeize for string': function () {
var data = string.snakeize("geddyJs")
, expected = 'geddy_js';
assert.equal(expected, data);
}
, 'test snakeize with beginning caps for string': function () {
var data = string.snakeize("GeddyJs")
, expected = 'geddy_js';
assert.equal(expected, data);
}
, 'test camelize for string': function () {
var data = string.camelize("geddy_js")
, expected = 'geddyJs';
assert.equal(expected, data);
}
, 'test camelize with initialCap for string': function () {
var data = string.camelize("geddy_js", {initialCap: true})
, expected = 'GeddyJs';
assert.equal(expected, data);
}
, 'test camelize with leadingUnderscore with no underscore for string': function () {
var data = string.camelize("geddy_js", {leadingUnderscore: true})
, expected = 'geddyJs';
assert.equal(expected, data);
}
, 'test camelize with leadingUnderscore with underscore for string': function () {
var data = string.camelize("_geddy_js", {leadingUnderscore: true})
, expected = '_geddyJs';
assert.equal(expected, data);
}
, 'test decapitalize for string': function () {
var data = string.decapitalize("Geddy")
, expected = 'geddy';
assert.equal(expected, data);
}
, 'test capitalize for string': function () {
var data = string.capitalize("geddy")
, expected = 'Geddy';
assert.equal(expected, data);
}
, 'test dasherize for string': function () {
var data = string.dasherize("geddyJs")
, expected = 'geddy-js';
assert.equal(expected, data);
}
, 'test dasherize with custom replace char for string': function () {
var data = string.dasherize("geddyJs", "_")
, expected = 'geddy_js';
assert.equal(expected, data);
}
, 'test underscorize for string': function () {
var data = string.underscorize("geddyJs")
, expected = 'geddy_js';
assert.equal(expected, data);
}
, 'test include for string with included string': function () {
assert.ok(string.include('foobarbaz', 'foo'));
}
, 'test include for string with not included string': function () {
assert.ok(!string.include('foobarbaz', 'qux'));
}
, 'test getInflections for string': function () {
var actual = string.getInflections("string")
, expected = {
filename: {
normal: "string"
, singular: "string"
, plural: "strings"
},
constructor: {
normal: "String"
, singular: "String"
, plural: "Strings"
},
property: {
normal: "string"
, singular: "string"
, plural: "strings"
},
};
assert.deepEqual(expected, actual);
}
, 'test inflection with odd name for string': function () {
var actual = string.getInflections("snow_dog")
, expected = {
filename: {
normal: "snow_dog"
, singular: "snow_dog"
, plural: "snow_dogs"
},
constructor: {
normal: "SnowDog"
, singular: "SnowDog"
, plural: "SnowDogs"
},
property: {
normal: "snowDog"
, singular: "snowDog"
, plural: "snowDogs"
},
};
assert.deepEqual(expected, actual);
}
, 'test uuid length for string': function () {
var data = string.uuid(5).length
, expected = 5;
assert.equal(expected, data);
}
, 'test stripTags': function () {
var html = '
foo
bar
wooby
'
, expected = 'foobarwooby';
assert.equal(string.stripTags(html), expected);
}
, 'test stripTags with allowed
': function () {
var html = 'foo
bar
wooby
'
, expected = 'foobar
wooby';
assert.equal(string.stripTags(html, '
'), expected);
}
};
module.exports = tests;
utilities-1.0.6/test/uri.js 0000664 0000000 0000000 00000010377 14237004417 0015657 0 ustar 00root root 0000000 0000000 /*
* Utilities: A classic collection of JavaScript utilities
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
var uri = require('../lib/uri')
, array = require('../lib/array')
, assert = require('assert')
, tests = {};
tests = {
'test getFileExtension for uri': function () {
var data = uri.getFileExtension('users.json')
, actual = 'json';
assert.equal(actual, data);
}
, 'test paramify for uri': function () {
var data = uri.paramify({username: 'user', token: 'token', secret: 'secret'})
, actual = 'username=user&token=token&secret=secret';
assert.equal(actual, data);
}
, 'test paramify with conslidate option for uri': function () {
var data = uri.paramify({username: 'user', auth: ['token', 'secret']}, {conslidate: true})
, actual = 'username=user&auth=token&auth=secret';
assert.equal(actual, data);
}
, 'test paramify with includeEmpty option for uri': function () {
var data = uri.paramify({username: 'user', token: ''}, {includeEmpty: true})
, actual = 'username=user&token=';
assert.equal(actual, data);
}
, 'test paramify with includeEmpty as 0 option for uri': function () {
var data = uri.paramify({username: 'user', token: 0}, {includeEmpty: true})
, actual = 'username=user&token=0';
assert.equal(actual, data);
}
, 'test paramify with includeEmpty as null option for uri': function () {
var data = uri.paramify({username: 'user', token: null}, {includeEmpty: true})
, actual = 'username=user&token=';
assert.equal(actual, data);
}
, 'test paramify with includeEmpty as undefined option for uri': function () {
var data = uri.paramify({username: 'user', token: undefined}, {includeEmpty: true})
, actual = 'username=user&token=';
assert.equal(actual, data);
}
, 'test paramify with snakeize option for uri': function () {
var data = uri.paramify({username: 'user', authToken: 'token'}, {snakeize: true})
, actual = 'username=user&auth_token=token';
assert.equal(actual, data);
}
, 'test paramify with escapeVals option for uri': function () {
var data = uri.paramify({username: 'user', token: '