├── component.json ├── src ├── number │ ├── MIN_INT.js │ ├── MAX_INT.js │ ├── MAX_UINT.js │ ├── sign.js │ ├── pad.js │ ├── rol.js │ ├── ror.js │ ├── toUInt.js │ ├── toInt.js │ ├── toUInt31.js │ └── enforcePrecision.js ├── lang │ ├── isNull.js │ ├── isDate.js │ ├── isNumber.js │ ├── isObject.js │ ├── isRegExp.js │ ├── isString.js │ ├── isUndefined.js │ ├── isBoolean.js │ ├── isFunction.js │ ├── isArray.js │ ├── isKind.js │ ├── defaults.js │ ├── ctorApply.js │ ├── isNaN.js │ ├── isArguments.js │ ├── inheritPrototype.js │ ├── kindOf.js │ ├── isFinite.js │ ├── createObject.js │ ├── isEmpty.js │ └── toArray.js ├── collection │ ├── some.js │ ├── every.js │ ├── reduce.js │ ├── forEach.js │ ├── contains.js │ ├── max.js │ ├── min.js │ ├── find.js │ ├── pluck.js │ ├── reject.js │ ├── size.js │ ├── filter.js │ ├── make_.js │ └── map.js ├── string │ ├── lowerCase.js │ ├── upperCase.js │ ├── repeat.js │ ├── contains.js │ ├── crop.js │ ├── pascalCase.js │ ├── lpad.js │ ├── rpad.js │ ├── rtrim.js │ ├── trim.js │ ├── ltrim.js │ ├── underscore.js │ ├── stripHtmlTags.js │ ├── escapeRegExp.js │ ├── unhyphenate.js │ ├── removeNonASCII.js │ ├── removeNonWord.js │ ├── unescapeUnicode.js │ ├── makePath.js │ ├── unCamelCase.js │ ├── hyphenate.js │ ├── interpolate.js │ ├── escapeHtml.js │ ├── normalizeLineBreaks.js │ ├── unescapeHtml.js │ ├── properCase.js │ ├── startsWith.js │ ├── endsWith.js │ ├── sentenceCase.js │ ├── truncate.js │ ├── escapeUnicode.js │ ├── typecast.js │ ├── camelCase.js │ └── slugify.js ├── math │ ├── clamp.js │ ├── loop.js │ ├── norm.js │ ├── isNear.js │ ├── floor.js │ ├── lerp.js │ ├── ceil.js │ ├── inRange.js │ ├── round.js │ ├── map.js │ └── countSteps.js ├── object │ ├── max.js │ ├── min.js │ ├── pluck.js │ ├── hasOwn.js │ ├── contains.js │ ├── has.js │ ├── reject.js │ ├── size.js │ ├── values.js │ ├── keys.js │ ├── set.js │ ├── get.js │ ├── every.js │ ├── find.js │ ├── map.js │ ├── some.js │ ├── namespace.js │ ├── filter.js │ ├── pick.js │ ├── fillIn.js │ ├── forOwn.js │ ├── unset.js │ ├── reduce.js │ ├── deepFillIn.js │ ├── mixIn.js │ └── merge.js ├── random │ ├── randBit.js │ ├── randSign.js │ ├── rand.js │ ├── randHex.js │ ├── choice.js │ ├── random.js │ ├── randInt.js │ └── guid.js ├── time.js ├── array │ ├── contains.js │ ├── pluck.js │ ├── union.js │ ├── compact.js │ ├── pick.js │ ├── remove.js │ ├── unique.js │ ├── removeAll.js │ ├── append.js │ ├── reject.js │ ├── filter.js │ ├── insert.js │ ├── map.js │ ├── invoke.js │ ├── join.js │ ├── zip.js │ ├── combine.js │ ├── find.js │ ├── shuffle.js │ ├── every.js │ ├── forEach.js │ ├── some.js │ ├── indexOf.js │ ├── difference.js │ ├── range.js │ ├── intersection.js │ ├── xor.js │ ├── lastIndexOf.js │ ├── split.js │ ├── max.js │ ├── min.js │ ├── reduce.js │ ├── reduceRight.js │ ├── toLookup.js │ └── flatten.js ├── time │ ├── now.js │ ├── parseMs.js │ └── toTimeString.js ├── function │ ├── func.js │ ├── prop.js │ ├── curry.js │ ├── series.js │ ├── compose.js │ ├── bind.js │ ├── debounce.js │ └── throttle.js ├── queryString │ ├── parse.js │ ├── contains.js │ ├── encode.js │ ├── getQuery.js │ ├── getParam.js │ ├── decode.js │ └── setParam.js ├── random.js ├── queryString.js ├── function.js ├── index.js ├── math.js ├── number.js └── collection.js ├── .travis.yml ├── _build ├── templates │ ├── spec │ │ ├── package.hbs │ │ └── default.hbs │ └── mod │ │ ├── index.hbs │ │ ├── pkg.hbs │ │ ├── collection.hbs │ │ └── default.hbs ├── config.js └── doc_template │ ├── doc.hbs │ ├── index.hbs │ ├── footer.hbs │ ├── header.hbs │ ├── sidebar.hbs │ └── assets_ │ └── js │ └── lib │ └── syntax-highlighter │ └── shBrushPlain.js ├── tests ├── spec │ ├── spec-time.js │ ├── src │ │ └── spec-math.js │ ├── number │ │ ├── spec-MIN_INT.js │ │ ├── spec-MAX_INT.js │ │ ├── spec-MAX_UINT.js │ │ ├── spec-rol.js │ │ ├── spec-ror.js │ │ ├── spec-pad.js │ │ ├── spec-sign.js │ │ ├── spec-toUInt31.js │ │ └── spec-toInt.js │ ├── string │ │ ├── spec-properCase.js │ │ ├── spec-trim.js │ │ ├── spec-ltrim.js │ │ ├── spec-rtrim.js │ │ ├── spec-removeNonWord.js │ │ ├── spec-sentenceCase.js │ │ ├── spec-unCamelCase.js │ │ ├── spec-stripHtmlTags.js │ │ ├── spec-escapeRegExp.js │ │ ├── spec-repeat.js │ │ ├── spec-removeNonASCII.js │ │ ├── spec-lpad.js │ │ ├── spec-replaceAccents.js │ │ ├── spec-rpad.js │ │ ├── spec-lowerCase.js │ │ ├── spec-upperCase.js │ │ ├── spec-escapeHtml.js │ │ ├── spec-unescapeHtml.js │ │ ├── spec-typecast.js │ │ ├── spec-unhyphenate.js │ │ ├── spec-escapeUnicode.js │ │ ├── spec-crop.js │ │ ├── spec-unescapeUnicode.js │ │ └── spec-endsWith.js │ ├── spec-random.js │ ├── function │ │ ├── spec-prop.js │ │ ├── spec-func.js │ │ ├── spec-curry.js │ │ ├── spec-compose.js │ │ └── spec-bind.js │ ├── array │ │ ├── spec-contains.js │ │ ├── spec-compact.js │ │ ├── spec-append.js │ │ ├── spec-shuffle.js │ │ ├── spec-unique.js │ │ ├── spec-combine.js │ │ ├── spec-find.js │ │ ├── spec-flatten.js │ │ ├── spec-union.js │ │ ├── spec-pluck.js │ │ ├── spec-max.js │ │ ├── spec-min.js │ │ ├── spec-pick.js │ │ ├── spec-xor.js │ │ ├── spec-zip.js │ │ ├── spec-join.js │ │ ├── spec-intersection.js │ │ ├── spec-removeAll.js │ │ ├── spec-insert.js │ │ ├── spec-difference.js │ │ ├── spec-toLookup.js │ │ └── spec-split.js │ ├── spec-function.js │ ├── spec-queryString.js │ ├── object │ │ ├── spec-contains.js │ │ ├── spec-pluck.js │ │ ├── spec-pick.js │ │ ├── spec-max.js │ │ ├── spec-min.js │ │ ├── spec-get.js │ │ ├── spec-reject.js │ │ ├── spec-some.js │ │ └── spec-every.js │ ├── math │ │ ├── spec-map.js │ │ ├── spec-countSteps.js │ │ ├── spec-floor.js │ │ ├── spec-lerp.js │ │ ├── spec-norm.js │ │ └── spec-isNear.js │ ├── queryString │ │ ├── spec-getQuery.js │ │ ├── spec-encode.js │ │ ├── spec-parse.js │ │ └── spec-contains.js │ ├── spec-math.js │ ├── time │ │ ├── spec-now.js │ │ └── spec-toTimeString.js │ ├── lang │ │ ├── spec-isNull.js │ │ ├── spec-isDate.js │ │ ├── spec-isArray.js │ │ ├── spec-isObject.js │ │ ├── spec-isString.js │ │ ├── spec-isArguments.js │ │ ├── spec-isRegExp.js │ │ ├── spec-isUndefined.js │ │ ├── spec-isFunction.js │ │ ├── spec-isNumber.js │ │ ├── spec-isBoolean.js │ │ ├── spec-defaults.js │ │ ├── spec-isKind.js │ │ ├── spec-ctorApply.js │ │ ├── spec-inheritPrototype.js │ │ └── spec-isNaN.js │ ├── spec-number.js │ ├── spec-collection.js │ ├── collection │ │ ├── spec-contains.js │ │ └── spec-forEach.js │ ├── spec-lang.js │ ├── spec-object.js │ ├── random │ │ └── spec-guid.js │ └── spec-array.js ├── runner.html └── lib │ └── jasmine │ └── MIT.LICENSE ├── updateDocs.sh ├── README.md ├── clean.sh ├── .npmignore ├── .gitignore └── doc ├── mdown └── time.md └── html └── assets_ └── js └── lib └── syntax-highlighter └── shBrushPlain.js /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "amd-utils", 3 | "version" : "0.10.0", 4 | "main" : "src/" 5 | } 6 | -------------------------------------------------------------------------------- /src/number/MIN_INT.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @constant Minimum 32-bit signed integer value (-2^31). 3 | * @version 0.1.1 (2012/02/17) 4 | */ 5 | define(function(){ 6 | return -2147483648; 7 | }); 8 | -------------------------------------------------------------------------------- /src/number/MAX_INT.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @constant Maximum 32-bit signed integer value. (2^31 - 1) 3 | * @version 0.1.1 (2012/02/17) 4 | */ 5 | define(function(){ 6 | return 2147483647; 7 | }); 8 | -------------------------------------------------------------------------------- /src/number/MAX_UINT.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @constant Maximum 32-bit unsigned integet value (2^32 - 1) 3 | * @version 0.1.1 (2012/02/17) 4 | */ 5 | define(function(){ 6 | return 4294967295; 7 | }); 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.8" 4 | script: 5 | - "npm test --coverage" 6 | - "node node_modules/.bin/istanbul check-coverage --functions 90 --statements 90 --branches 90 --lines 90" 7 | 8 | -------------------------------------------------------------------------------- /_build/templates/spec/package.hbs: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | {{#list modules}}'{{package}}/spec-{{name}}'{{/list}} 5 | ], function(){ 6 | //noop 7 | }); 8 | -------------------------------------------------------------------------------- /src/lang/isNull.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isNull(val){ 6 | return val === null; 7 | } 8 | return isNull; 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /_build/config.js: -------------------------------------------------------------------------------- 1 | 2 | exports.ENCODING = 'utf-8'; 3 | exports.SRC_FOLDER = 'src'; 4 | exports.SPEC_FOLDER = 'tests/spec'; 5 | exports.TEMPLATES_FOLDER = '_build/templates'; 6 | exports.SPEC_RUNNER_PATH = 'tests/runner.js'; 7 | 8 | -------------------------------------------------------------------------------- /src/collection/some.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/some', '../object/some'], function (make, arrSome, objSome) { 2 | 3 | /** 4 | * @version 0.1.0 (2012/11/13) 5 | */ 6 | return make(arrSome, objSome); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /src/collection/every.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/every', '../object/every'], function (make, arrEvery, objEvery) { 2 | 3 | /** 4 | * @version 0.1.0 (2012/11/03) 5 | */ 6 | return make(arrEvery, objEvery); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /src/lang/isDate.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isDate(val) { 6 | return isKind(val, 'Date'); 7 | } 8 | return isDate; 9 | }); 10 | -------------------------------------------------------------------------------- /_build/templates/mod/index.hbs: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | {{#list modules}}'{{name}}' : require('./{{name}}'){{/list}} 7 | }; 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/collection/reduce.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/reduce', '../object/reduce'], function (make, arrReduce, objReduce) { 2 | 3 | /** 4 | * @version 0.1.0 (2012/11/13) 5 | */ 6 | return make(arrReduce, objReduce); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /tests/spec/spec-time.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'time/spec-now', 5 | 'time/spec-parseMs', 6 | 'time/spec-toTimeString' 7 | ], function(){ 8 | //noop 9 | }); 10 | -------------------------------------------------------------------------------- /src/collection/forEach.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/forEach', '../object/forOwn'], function (make, arrForEach, objForEach) { 2 | 3 | /** 4 | * @version 0.1.1 (2012/10/30) 5 | */ 6 | return make(arrForEach, objForEach); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /src/lang/isNumber.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isNumber(val) { 6 | return isKind(val, 'Number'); 7 | } 8 | return isNumber; 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isObject.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isObject(val) { 6 | return isKind(val, 'Object'); 7 | } 8 | return isObject; 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isRegExp.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isRegExp(val) { 6 | return isKind(val, 'RegExp'); 7 | } 8 | return isRegExp; 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isString.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isString(val) { 6 | return isKind(val, 'String'); 7 | } 8 | return isString; 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isUndefined.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | var UNDEF; 3 | 4 | /** 5 | * @version 0.1.0 (2011/10/31) 6 | */ 7 | function isUndef(val){ 8 | return val === UNDEF; 9 | } 10 | return isUndef; 11 | }); 12 | -------------------------------------------------------------------------------- /_build/templates/mod/pkg.hbs: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | {{#list modules}}'{{name}}' : require('./{{package}}/{{name}}'){{/list}} 7 | }; 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isBoolean.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isBoolean(val) { 6 | return isKind(val, 'Boolean'); 7 | } 8 | return isBoolean; 9 | }); 10 | -------------------------------------------------------------------------------- /src/collection/contains.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/contains', '../object/contains'], function (make, arrContains, objContains) { 2 | 3 | /** 4 | * @version 0.1.0 (2012/11/13) 5 | */ 6 | return make(arrContains, objContains); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /src/lang/isFunction.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.1.0 (2011/10/31) 4 | */ 5 | function isFunction(val) { 6 | return isKind(val, 'Function'); 7 | } 8 | return isFunction; 9 | }); 10 | -------------------------------------------------------------------------------- /tests/spec/src/spec-math.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/src/math'], function(math){ 2 | 3 | describe('amd-utils/math', function(){ 4 | 5 | it('', function(){ 6 | expect( math() ).toBe({}); 7 | }); 8 | 9 | }); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /src/number/sign.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Get sign of the value. 5 | * @version 0.1.0 (2011/11/25) 6 | */ 7 | function sign(val) { 8 | return val < 0? -1 : 1; 9 | } 10 | 11 | return sign; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/lang/isArray.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | /** 3 | * @version 0.2.0 (2011/12/06) 4 | */ 5 | var isArray = Array.isArray || function (val) { 6 | return isKind(val, 'Array'); 7 | }; 8 | return isArray; 9 | }); 10 | -------------------------------------------------------------------------------- /updateDocs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # update gh-pages branch with latest doc files 3 | 4 | git checkout gh-pages 5 | rm *.html 6 | rm -r assets_/ 7 | git checkout master doc/html 8 | mv doc/html/* . 9 | rm -r doc/ 10 | git add -A 11 | git commit 12 | git checkout master 13 | -------------------------------------------------------------------------------- /_build/templates/mod/collection.hbs: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/{{name}}', '../object/{{name}}'], function (make, arr{{u_name}}, obj{{u_name}}) { 2 | 3 | /** 4 | * @version 0.1.0 ({{date}}) 5 | */ 6 | return make(arr{{u_name}}, obj{{u_name}}); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /src/string/lowerCase.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * "Safer" String.toLowerCase() 4 | * @version 0.1.0 (2011/10/19) 5 | */ 6 | function upperCase(str){ 7 | return (str || '').toLowerCase(); 8 | } 9 | return upperCase; 10 | }); 11 | -------------------------------------------------------------------------------- /src/string/upperCase.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * "Safer" String.toUpperCase() 4 | * @version 0.1.0 (2011/10/19) 5 | */ 6 | function upperCase(str){ 7 | return (str || '').toUpperCase(); 8 | } 9 | return upperCase; 10 | }); 11 | -------------------------------------------------------------------------------- /_build/templates/mod/default.hbs: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * @version 0.1.0 ({{date}}) 5 | */ 6 | function {{name}}(){ 7 | throw new Error('{{name}} wasn\'t implemented yet.'); 8 | } 9 | 10 | return {{name}}; 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /src/collection/max.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/max', '../object/max'], function (make, arrMax, objMax) { 2 | 3 | /** 4 | * Get maximum value inside collection 5 | * @version 0.1.0 (2012/11/13) 6 | */ 7 | return make(arrMax, objMax); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/collection/min.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/min', '../object/min'], function (make, arrMin, objMin) { 2 | 3 | /** 4 | * Get minimum value inside collection. 5 | * @version 0.1.0 (2012/11/13) 6 | */ 7 | return make(arrMin, objMin); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/math/clamp.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Clamps value inside range. 4 | * @version 0.1.0 (2011/08/09) 5 | */ 6 | function clamp(val, min, max){ 7 | return val < min? min : (val > max? max : val); 8 | } 9 | return clamp; 10 | }); 11 | -------------------------------------------------------------------------------- /src/math/loop.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Loops value inside range. 4 | * @version 0.1.0 (2011/08/09) 5 | */ 6 | function loop(val, min, max){ 7 | return val < min? max : (val > max? min : val); 8 | } 9 | 10 | return loop; 11 | }); 12 | -------------------------------------------------------------------------------- /src/math/norm.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Gets normalized ratio of value inside range. 4 | * @version 0.1.0 (2011/08/09) 5 | */ 6 | function norm(val, min, max){ 7 | return (val - min) / (max - min); 8 | } 9 | return norm; 10 | }); 11 | -------------------------------------------------------------------------------- /src/string/repeat.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | 3 | /** 4 | * Repeat string n times 5 | * @version 0.1.0 (2011/12/07) 6 | */ 7 | function repeat(str, n){ 8 | return (new Array(n + 1)).join(str); 9 | } 10 | 11 | return repeat; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/collection/find.js: -------------------------------------------------------------------------------- 1 | define(['./make_', '../array/find', '../object/find'], function(make, arrFind, objFind) { 2 | 3 | /** 4 | * Find value that returns true on iterator check. 5 | * @version 0.2.0 (2012/11/19) 6 | */ 7 | return make(arrFind, objFind); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/lang/isKind.js: -------------------------------------------------------------------------------- 1 | define(['./kindOf'], function (kindOf) { 2 | /** 3 | * Check if value is from a specific "kind". 4 | * @version 0.1.0 (2011/10/31) 5 | */ 6 | function isKind(val, kind){ 7 | return kindOf(val) === kind; 8 | } 9 | return isKind; 10 | }); 11 | -------------------------------------------------------------------------------- /src/math/isNear.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Check if value is close to target. 4 | * @version 0.1.0 (2011/08/09) 5 | */ 6 | function isNear(val, target, threshold){ 7 | return (Math.abs(val - target) <= threshold); 8 | } 9 | return isNear; 10 | }); 11 | -------------------------------------------------------------------------------- /src/object/max.js: -------------------------------------------------------------------------------- 1 | define(['../array/max', './values'], function(arrMax, values) { 2 | 3 | /** 4 | * Returns maximum value inside object. 5 | */ 6 | function max(obj, compareFn) { 7 | return arrMax(values(obj), compareFn); 8 | } 9 | 10 | return max; 11 | }); 12 | -------------------------------------------------------------------------------- /src/object/min.js: -------------------------------------------------------------------------------- 1 | define(['../array/min', './values'], function(arrMin, values) { 2 | 3 | /** 4 | * Returns minimum value inside object. 5 | */ 6 | function min(obj, iterator) { 7 | return arrMin(values(obj), iterator); 8 | } 9 | 10 | return min; 11 | }); 12 | -------------------------------------------------------------------------------- /src/object/pluck.js: -------------------------------------------------------------------------------- 1 | define(['./map', '../function/prop'], function (map, prop) { 2 | 3 | /** 4 | * Extract a list of property values. 5 | */ 6 | function pluck(obj, propName){ 7 | return map(obj, prop(propName)); 8 | } 9 | 10 | return pluck; 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /src/random/randBit.js: -------------------------------------------------------------------------------- 1 | define(['./random'], function (random) { 2 | 3 | /** 4 | * Returns random bit (0 or 1) 5 | * @version 0.2.0 (2012/11/29) 6 | */ 7 | function randomBit() { 8 | return random() > 0.5? 1 : 0; 9 | } 10 | 11 | return randomBit; 12 | }); 13 | -------------------------------------------------------------------------------- /src/time.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'now' : require('./time/now'), 7 | 'parseMs' : require('./time/parseMs'), 8 | 'toTimeString' : require('./time/toTimeString') 9 | }; 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /src/array/contains.js: -------------------------------------------------------------------------------- 1 | define(['./indexOf'], function (indexOf) { 2 | 3 | /** 4 | * If array contains values. 5 | * @version 0.1.0 (2011/10/31) 6 | */ 7 | function contains(arr, val) { 8 | return indexOf(arr, val) !== -1; 9 | } 10 | return contains; 11 | }); 12 | -------------------------------------------------------------------------------- /src/random/randSign.js: -------------------------------------------------------------------------------- 1 | define(['./random'], function (random) { 2 | 3 | /** 4 | * Returns random sign (-1 or 1) 5 | * @version 0.2.0 (2012/11/29) 6 | */ 7 | function randomSign() { 8 | return random() > 0.5? 1 : -1; 9 | } 10 | 11 | return randomSign; 12 | }); 13 | -------------------------------------------------------------------------------- /src/string/contains.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * searches for a given substring 5 | * @version 0.1.0 (2012/08/30) 6 | */ 7 | function contains(str, substring){ 8 | return str.indexOf(substring) !== -1; 9 | } 10 | 11 | return contains; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/number/spec-MIN_INT.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/MIN_INT'], function (MIN_INT) { 2 | 3 | describe('number/MIN_INT', function(){ 4 | it('should be equal -2 ^ 31', function(){ 5 | expect( MIN_INT ).toEqual( Math.pow(-2, 31) ); 6 | }); 7 | }); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/time/now.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Get current time in miliseconds 5 | * @version 0.1.0 (2012/04/11) 6 | */ 7 | var now = (typeof Date.now === 'function')? Date.now : function(){ 8 | return +(new Date()); 9 | }; 10 | 11 | return now; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/number/spec-MAX_INT.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/MAX_INT'], function (MAX_INT) { 2 | 3 | describe('number/MAX_INT', function(){ 4 | it('should be equal (2 ^ 31) - 1', function(){ 5 | expect( MAX_INT ).toEqual( Math.pow(2, 31) - 1 ); 6 | }); 7 | }); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/object/hasOwn.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Safer Object.hasOwnProperty 5 | * @version 0.1.0 (2012/01/19) 6 | */ 7 | function hasOwn(obj, prop){ 8 | return Object.prototype.hasOwnProperty.call(obj, prop); 9 | } 10 | 11 | return hasOwn; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/number/spec-MAX_UINT.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/MAX_UINT'], function (MAX_INT) { 2 | 3 | describe('number/MAX_UINT', function(){ 4 | it('should be equal (2 ^ 32) - 1', function(){ 5 | expect( MAX_INT ).toEqual( Math.pow(2, 32) - 1 ); 6 | }); 7 | }); 8 | 9 | }); 10 | -------------------------------------------------------------------------------- /src/math/floor.js: -------------------------------------------------------------------------------- 1 | define(['./countSteps'], function(countSteps){ 2 | /** 3 | * Floor value to full steps. 4 | * @version 0.2.0 (2012/11/30) 5 | */ 6 | function floor(val, step){ 7 | step = step || 1; 8 | return countSteps(val, step) * step; 9 | } 10 | return floor; 11 | }); 12 | -------------------------------------------------------------------------------- /src/number/pad.js: -------------------------------------------------------------------------------- 1 | define(['../string/lpad'], function(lpad){ 2 | 3 | /** 4 | * Add padding zeros if n.length < minLength. 5 | * @version 0.2.0 (2011/11/1) 6 | */ 7 | function pad(n, minLength){ 8 | return lpad(''+ n, minLength, '0'); 9 | } 10 | 11 | return pad; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/string/crop.js: -------------------------------------------------------------------------------- 1 | define(['./truncate'], function (truncate) { 2 | /** 3 | * Truncate string at full words. 4 | * @version 0.1.0 (2011/10/31) 5 | */ 6 | function crop(str, maxChars, append) { 7 | return truncate(str, maxChars, append, true); 8 | } 9 | 10 | return crop; 11 | }); 12 | -------------------------------------------------------------------------------- /src/number/rol.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Bitwise circular shift left 4 | * http://en.wikipedia.org/wiki/Circular_shift 5 | * @version 0.1.0 (2011/10/21) 6 | */ 7 | function rol(val, shift){ 8 | return (val << shift) | (val >> (32 - shift)); 9 | } 10 | return rol; 11 | }); 12 | -------------------------------------------------------------------------------- /src/number/ror.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Bitwise circular shift right 4 | * http://en.wikipedia.org/wiki/Circular_shift 5 | * @version 0.1.0 (2011/10/21) 6 | */ 7 | function ror(val, shift){ 8 | return (val >> shift) | (val << (32 - shift)); 9 | } 10 | return ror; 11 | }); 12 | -------------------------------------------------------------------------------- /src/object/contains.js: -------------------------------------------------------------------------------- 1 | define(['./some'], function (some) { 2 | 3 | /** 4 | * Check if object contains value 5 | */ 6 | function contains(obj, needle) { 7 | return some(obj, function(val) { 8 | return (val === needle); 9 | }); 10 | } 11 | return contains; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/array/pluck.js: -------------------------------------------------------------------------------- 1 | define(['./map', '../function/prop'], function (map, prop) { 2 | 3 | /** 4 | * Extract a list of property values. 5 | * @version 0.1.0 (2012/06/04) 6 | */ 7 | function pluck(arr, propName){ 8 | return map(arr, prop(propName)); 9 | } 10 | 11 | return pluck; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/number/toUInt.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * "Convert" value into a 32-bit unsigned integer. 5 | * IMPORTANT: Value will wrap at 2^32. 6 | * @version 0.2.0 (2011/11/25) 7 | */ 8 | function toUInt(val){ 9 | return val >>> 0; 10 | } 11 | 12 | return toUInt; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/object/has.js: -------------------------------------------------------------------------------- 1 | define(['./get'], function (get) { 2 | 3 | var UNDEF; 4 | 5 | /** 6 | * Check if object has nested property. 7 | * @version 0.2.0 (2012/03/14) 8 | */ 9 | function has(obj, prop){ 10 | return get(obj, prop) !== UNDEF; 11 | } 12 | 13 | return has; 14 | 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /_build/templates/spec/default.hbs: -------------------------------------------------------------------------------- 1 | define(['amd-utils/{{package}}/{{name}}'], function({{name}}){ 2 | 3 | describe('{{package}}/{{name}}', function(){ 4 | 5 | it('', function(){ 6 | expect( {{name}}() ).toBe('TODO: create tests for module "{{package}}/{{name}}"!'); 7 | }); 8 | 9 | }); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /src/array/union.js: -------------------------------------------------------------------------------- 1 | define(['./unique'], function (unique) { 2 | 3 | /** 4 | * Concat multiple arrays and remove duplicates 5 | * @version 0.1.0 (2011/01/12) 6 | */ 7 | function union(arrs) { 8 | return unique(Array.prototype.concat.apply([], arguments)); 9 | } 10 | 11 | return union; 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /src/function/func.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Returns a function that call a method on the passed object 5 | * @version 0.1.0 (2012/06/04) 6 | */ 7 | function func(name){ 8 | return function(obj){ 9 | return obj[name](); 10 | }; 11 | } 12 | 13 | return func; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/function/prop.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Returns a function that gets a property of the passed object 5 | * @version 0.1.0 (2012/06/04) 6 | */ 7 | function prop(name){ 8 | return function(obj){ 9 | return obj[name]; 10 | }; 11 | } 12 | 13 | return prop; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/math/lerp.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Linear interpolation. 4 | * IMPORTANT:will return `Infinity` if numbers overflow Number.MAX_VALUE 5 | * @version 0.1.0 (2011/08/09) 6 | */ 7 | function lerp(ratio, start, end){ 8 | return start + (end - start) * ratio; 9 | } 10 | 11 | return lerp; 12 | }); 13 | -------------------------------------------------------------------------------- /src/string/pascalCase.js: -------------------------------------------------------------------------------- 1 | define(['./camelCase', './upperCase'], function(camelCase, upperCase){ 2 | /** 3 | * camelCase + uppercase first char 4 | * @version 0.1.0 (2011/10/26) 5 | */ 6 | function pascalCase(str){ 7 | return camelCase(str).replace(/^[a-z]/, upperCase); 8 | } 9 | return pascalCase; 10 | }); 11 | -------------------------------------------------------------------------------- /src/math/ceil.js: -------------------------------------------------------------------------------- 1 | define(['./floor'], function(floor){ 2 | 3 | /** 4 | * Round value up with a custom radix. 5 | * @version 0.1.0 (2012/11/30) 6 | */ 7 | function ceil(val, step){ 8 | step = step || 1; 9 | return val % step? floor(val + Math.abs(step), step) : val; 10 | } 11 | 12 | return ceil; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/math/inRange.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Checks if value is inside the range. 4 | * @version 0.1.0 (2011/08/09) 5 | */ 6 | function inRange(val, min, max, threshold){ 7 | threshold = threshold || 0; 8 | return (val + threshold >= min && val - threshold <= max); 9 | } 10 | 11 | return inRange; 12 | }); 13 | -------------------------------------------------------------------------------- /src/collection/pluck.js: -------------------------------------------------------------------------------- 1 | define(['./map'], function (map) { 2 | 3 | /** 4 | * Extract a list of property values. 5 | * @version 0.1.0 (2012/11/13) 6 | */ 7 | function pluck(list, key) { 8 | return map(list, function(value) { 9 | return value[key]; 10 | }); 11 | } 12 | 13 | return pluck; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/math/round.js: -------------------------------------------------------------------------------- 1 | define(['./floor'], function (floor) { 2 | 3 | /** 4 | * Round number to a specific radix 5 | * @version 0.1.0 (2012/11/27) 6 | */ 7 | function round(value, radix){ 8 | radix = radix || 1; // default round 1 9 | return floor(value + radix / 2, radix); 10 | } 11 | 12 | return round; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/array/compact.js: -------------------------------------------------------------------------------- 1 | define(['./filter'], function (filter) { 2 | 3 | /** 4 | * Remove all null/undefined items from array. 5 | * @version 0.1.0 (2011/11/15) 6 | */ 7 | function compact(arr) { 8 | return filter(arr, function(val){ 9 | return (val != null); 10 | }); 11 | } 12 | 13 | return compact; 14 | }); 15 | -------------------------------------------------------------------------------- /src/queryString/parse.js: -------------------------------------------------------------------------------- 1 | define(['./decode', './getQuery'], function (decode, getQuery) { 2 | 3 | /** 4 | * Get query string, parses and decodes it. 5 | * @version 0.2.0 (2012/09/26) 6 | */ 7 | function parse(url, shouldTypecast) { 8 | return decode(getQuery(url), shouldTypecast); 9 | } 10 | 11 | return parse; 12 | }); 13 | 14 | -------------------------------------------------------------------------------- /src/object/reject.js: -------------------------------------------------------------------------------- 1 | define(['./filter'], function (filter) { 2 | 3 | /** 4 | * Object reject 5 | */ 6 | function reject(obj, callback, thisObj) { 7 | return filter(obj, function(value, index, obj) { 8 | return !callback.call(thisObj, value, index, obj); 9 | }, thisObj); 10 | } 11 | 12 | return reject; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/object/size.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function (forOwn) { 2 | 3 | /** 4 | * Get object size 5 | * @version 0.1.1 (2012/01/28) 6 | */ 7 | function size(obj) { 8 | var count = 0; 9 | forOwn(obj, function(){ 10 | count++; 11 | }); 12 | return count; 13 | } 14 | 15 | return size; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /src/math/map.js: -------------------------------------------------------------------------------- 1 | define(['./lerp', './norm'], function(lerp, norm){ 2 | /** 3 | * Maps a number from one scale to another. 4 | * @example map(3, 0, 4, -1, 1) -> 0.5 5 | * @version 0.1.1 (2011/10/21) 6 | */ 7 | function map(val, min1, max1, min2, max2){ 8 | return lerp( norm(val, min1, max1), min2, max2 ); 9 | } 10 | return map; 11 | }); 12 | -------------------------------------------------------------------------------- /_build/doc_template/doc.hbs: -------------------------------------------------------------------------------- 1 | {{> header}} 2 |
7 | {{{content}}} 8 | {{> footer}} 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repository is moving away! 2 | 3 | development will be continued at https://github.com/mout/mout 4 | 5 | for info about how to upgrade legacy projects see: https://github.com/mout/mout/wiki/Migrating-old-projects-from-amd-utils 6 | 7 | it will be better for the future of the project! See [issue #112](https://github.com/millermedeiros/amd-utils/issues/112) to understand the reasons. 8 | -------------------------------------------------------------------------------- /src/object/values.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function (forOwn) { 2 | 3 | /** 4 | * Get object values 5 | * @version 0.2.0 (2011/12/17) 6 | */ 7 | function values(obj) { 8 | var vals = []; 9 | forOwn(obj, function(val, key){ 10 | vals.push(val); 11 | }); 12 | return vals; 13 | } 14 | 15 | return values; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /tests/spec/number/spec-rol.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/rol'], function (rol) { 2 | 3 | describe('number/rol()', function(){ 4 | it('should rotate bits left', function(){ 5 | expect( rol( parseInt('10101', 2), 5).toString(2) ).toEqual( '1010100000' ); 6 | expect( rol( 1 << 30, 5).toString(2) ).toEqual( '1000' ); 7 | }); 8 | }); 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /tests/spec/string/spec-properCase.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/properCase'], function (properCase) { 2 | 3 | describe('string/properCase()', function(){ 4 | 5 | it('should uppercase first char of each word and lowercase others', function(){ 6 | expect( properCase('lorem iPSum dolor') ).toEqual('Lorem Ipsum Dolor'); 7 | }); 8 | 9 | }); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /tests/spec/string/spec-trim.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/trim'], function (trim) { 2 | 3 | describe('string/trim()', function(){ 4 | var str = ' \t \t \t\t lorem ipsum \t \t \t\t '; 5 | 6 | it('should remove whitespaces from begin and end of string', function(){ 7 | expect( trim(str) ).toEqual('lorem ipsum'); 8 | }); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /tests/spec/spec-random.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'random/spec-choice', 5 | 'random/spec-guid', 6 | 'random/spec-rand', 7 | 'random/spec-randBit', 8 | 'random/spec-randHex', 9 | 'random/spec-randInt', 10 | 'random/spec-randSign', 11 | 'random/spec-random' 12 | ], function(){ 13 | //noop 14 | }); 15 | -------------------------------------------------------------------------------- /tests/spec/function/spec-prop.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/function/prop'], function (prop) { 2 | 3 | describe('function/prop()', function () { 4 | 5 | it('should grab property from object', function () { 6 | 7 | var o = {foo : 'bar'}; 8 | var getFoo = prop('foo'); 9 | 10 | expect( getFoo(o) ).toBe('bar'); 11 | 12 | }); 13 | 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /tests/spec/string/spec-ltrim.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/ltrim'], function (ltrim) { 2 | 3 | describe('string/ltrim()', function(){ 4 | var str = ' \t \t \t\t lorem ipsum \t \t \t\t '; 5 | 6 | it('should remove whitespaces from begin of string', function(){ 7 | expect( ltrim(str) ).toEqual('lorem ipsum \t \t \t\t '); 8 | }); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /tests/spec/string/spec-rtrim.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/rtrim'], function (rtrim) { 2 | 3 | describe('string/rtrim()', function(){ 4 | var str = ' \t \t \t\t lorem ipsum \t \t \t\t '; 5 | 6 | it('should remove whitespaces from end of string', function(){ 7 | expect( rtrim(str) ).toEqual(' \t \t \t\t lorem ipsum'); 8 | }); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/array/pick.js: -------------------------------------------------------------------------------- 1 | define(['../random/randInt'], function (randInt) { 2 | 3 | /** 4 | * Remove a random item from the Array and return it 5 | * @version 0.1.0 (2012/04/24) 6 | */ 7 | function pick(arr){ 8 | if (! arr.length) return; 9 | var idx = randInt(0, arr.length - 1); 10 | return arr.splice(idx, 1)[0]; 11 | } 12 | 13 | return pick; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/array/remove.js: -------------------------------------------------------------------------------- 1 | define(['./indexOf'], function(indexOf){ 2 | 3 | /** 4 | * Remove a single item from the array. 5 | * (it won't remove duplicates, just a single item) 6 | * @version 0.1.1 (2012/03/13) 7 | */ 8 | function remove(arr, item){ 9 | var idx = indexOf(arr, item); 10 | if (idx !== -1) arr.splice(idx, 1); 11 | } 12 | 13 | return remove; 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/lpad.js: -------------------------------------------------------------------------------- 1 | define(['./repeat'], function (repeat) { 2 | 3 | /** 4 | * Pad string with `char` if its' length is smaller than `minLen` 5 | * @version 0.1.1 (2012/05/03) 6 | */ 7 | function lpad(str, minLen, ch) { 8 | ch = ch || ' '; 9 | return (str.length < minLen)? repeat(ch, minLen - str.length) + str : str; 10 | } 11 | 12 | return lpad; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/rpad.js: -------------------------------------------------------------------------------- 1 | define(['./repeat'], function (repeat) { 2 | 3 | /** 4 | * Pad string with `char` if its' length is smaller than `minLen` 5 | * @version 0.1.1 (2012/05/03) 6 | */ 7 | function rpad(str, minLen, ch) { 8 | ch = ch || ' '; 9 | return (str.length < minLen)? str + repeat(ch, minLen - str.length) : str; 10 | } 11 | 12 | return rpad; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/rtrim.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove white-spaces from end of string. 4 | * @example stringUtils.rtrim(' lorem ipsum ') -> ' lorem ipsum' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/07/20) 8 | */ 9 | function rtrim(str){ 10 | return (str || '').replace(/\s+$/g, ''); 11 | } 12 | return rtrim; 13 | }); 14 | -------------------------------------------------------------------------------- /src/string/trim.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove white-spaces from beginning and end of string. 4 | * @example trim(' lorem ipsum ') -> 'lorem ipsum' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/07/20) 8 | */ 9 | function trim(str){ 10 | return (str || '').replace(/^\s+|\s+$/g, ''); 11 | } 12 | return trim; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/array/spec-contains.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/contains'], function (contains) { 2 | 3 | describe('array/contains()', function(){ 4 | 5 | it('should check for existance', function(){ 6 | 7 | var arr = [1, 2, 3]; 8 | expect( contains(arr, 2) ).toBe( true ); 9 | expect( contains(arr, 4) ).toBe( false ); 10 | }); 11 | 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/spec-function.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'function/spec-bind', 5 | 'function/spec-compose', 6 | 'function/spec-curry', 7 | 'function/spec-debounce', 8 | 'function/spec-func', 9 | 'function/spec-prop', 10 | 'function/spec-series', 11 | 'function/spec-throttle' 12 | ], function(){ 13 | //noop 14 | }); 15 | -------------------------------------------------------------------------------- /tests/spec/spec-queryString.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'queryString/spec-contains', 5 | 'queryString/spec-decode', 6 | 'queryString/spec-encode', 7 | 'queryString/spec-getParam', 8 | 'queryString/spec-getQuery', 9 | 'queryString/spec-parse', 10 | 'queryString/spec-setParam' 11 | ], function(){ 12 | //noop 13 | }); 14 | -------------------------------------------------------------------------------- /src/math/countSteps.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Count number of full steps. 4 | * @version 0.2.0 (2011/10/21) 5 | */ 6 | function countSteps(val, step, overflow){ 7 | //if (val/step == 0) mod oveflow will return NaN, so ~~ converts it to 0 8 | return overflow? ~~(Math.floor(val / step) % overflow) : Math.floor(val / step); 9 | } 10 | return countSteps; 11 | }); 12 | -------------------------------------------------------------------------------- /src/string/ltrim.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove white-spaces from beginning of string. 4 | * @example stringUtils.ltrim(' lorem ipsum ') -> 'lorem ipsum ' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/07/20) 8 | */ 9 | function ltrim(str){ 10 | return (str || '').replace(/^\s+/g, ''); 11 | } 12 | return ltrim; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/object/spec-contains.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/contains'], function(contains){ 2 | 3 | describe('object/contains', function(){ 4 | 5 | it('should check for existence', function(){ 6 | var list = {a:1, b:2, c:3}; 7 | expect( contains(list, 2) ).toBe( true ); 8 | expect( contains(list, 4) ).toBe( false ); 9 | }); 10 | 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/string/spec-removeNonWord.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/removeNonWord'], function (removeNonWord) { 2 | 3 | describe('string/removeNonWord()', function(){ 4 | 5 | it('should remove non word chars', function(){ 6 | var str = 'lorem ~!@#$%^&*()_+`-={}[]|\\:";\'/?><., ipsum'; 7 | expect( removeNonWord(str) ).toEqual('lorem - ipsum'); 8 | }); 9 | 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /_build/doc_template/index.hbs: -------------------------------------------------------------------------------- 1 | {{> header}} 2 | 3 |
4 |
5 | {{{content}}}
6 | lorem ipsum
') -> 'lorem ipsum' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/07/20) 8 | */ 9 | function stripHtmlTags(str){ 10 | return (str || '').replace(/<[^>]*>/g, ''); 11 | } 12 | return stripHtmlTags; 13 | }); 14 | -------------------------------------------------------------------------------- /src/array/removeAll.js: -------------------------------------------------------------------------------- 1 | define(['./indexOf'], function(indexOf){ 2 | 3 | /** 4 | * Remove all instances of an item from array. 5 | * @version 0.1.1 (2012/01/28) 6 | */ 7 | function removeAll(arr, item){ 8 | var idx = indexOf(arr, item); 9 | while (idx !== -1) { 10 | arr.splice(idx, 1); 11 | idx = indexOf(arr, item, idx); 12 | } 13 | } 14 | 15 | return removeAll; 16 | }); 17 | -------------------------------------------------------------------------------- /src/random/rand.js: -------------------------------------------------------------------------------- 1 | define(['./random', '../number/MIN_INT', '../number/MAX_INT'], function(random, MIN_INT, MAX_INT){ 2 | 3 | /** 4 | * Returns random number inside range 5 | * @version 0.4.0 (2012/04/24) 6 | */ 7 | function rand(min, max){ 8 | min = min == null? MIN_INT : min; 9 | max = max == null? MAX_INT : max; 10 | return min + (max - min) * random(); 11 | } 12 | 13 | return rand; 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/escapeRegExp.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | var _rEscapeChars; 4 | 5 | /** 6 | * Escape RegExp string chars. 7 | * @version 0.1.0 (2011/12/17) 8 | */ 9 | function escapeRegExp(str) { 10 | if (! _rEscapeChars) { 11 | _rEscapeChars = /[\\.+*?\^$\[\](){}\/'#]/g; 12 | } 13 | return str.replace(_rEscapeChars,'\\$&'); 14 | } 15 | 16 | return escapeRegExp; 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /src/string/unhyphenate.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Replaces hyphens with spaces. (only hyphens between word chars) 4 | * @example unhyphenate('lorem-ipsum-dolor') -> 'lorem ipsum dolor' 5 | * @version 0.1.0 (2011/08/09) 6 | */ 7 | function unhyphenate(str){ 8 | return (str || '').replace(/(\w)(-)(\w)/g, '$1 $3'); //convert hyphens between word chars to spaces 9 | } 10 | return unhyphenate; 11 | }); 12 | -------------------------------------------------------------------------------- /tests/spec/string/spec-unCamelCase.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/unCamelCase'], function (unCamelCase) { 2 | 3 | describe('string/unCamelCase()', function(){ 4 | 5 | it('should add space between camelCase text', function(){ 6 | expect( unCamelCase('loremIpsumDolor') ).toEqual('lorem ipsum dolor'); 7 | expect( unCamelCase('lorem IpsumDolor') ).toEqual('lorem ipsum dolor'); 8 | }); 9 | 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/string/removeNonASCII.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove non-printable ASCII chars 4 | * @param {string} str 5 | * @return {string} 6 | * @version 0.1.1 (2011/08/09) 7 | */ 8 | function removeNonASCII(str){ 9 | return (str || '').replace(/[^\x20-\x7E]/g, ''); //matches non-printable ASCII chars - http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters 10 | } 11 | return removeNonASCII; 12 | }); 13 | -------------------------------------------------------------------------------- /src/string/removeNonWord.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove non-word chars. 4 | * @example removeNonWord('lorem! ipsum?') -> 'lorem ipsum' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/07/20) 8 | */ 9 | function removeNonWord(str){ 10 | return (str || '').replace(/[^0-9a-zA-Z\xC0-\xFF \-]/g, ''); //remove non-word chars 11 | } 12 | return removeNonWord; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/spec-math.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'math/spec-ceil', 5 | 'math/spec-clamp', 6 | 'math/spec-countSteps', 7 | 'math/spec-floor', 8 | 'math/spec-inRange', 9 | 'math/spec-isNear', 10 | 'math/spec-lerp', 11 | 'math/spec-loop', 12 | 'math/spec-map', 13 | 'math/spec-norm', 14 | 'math/spec-round' 15 | ], function(){ 16 | //noop 17 | }); 18 | -------------------------------------------------------------------------------- /tests/spec/string/spec-stripHtmlTags.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/stripHtmlTags'], function (stripHtmlTags) { 2 | 3 | describe('string/stripHtmlTags()', function(){ 4 | it('should remove html tags', function(){ 5 | var str = '