├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── README.md ├── _build ├── add.js ├── config.js ├── doc_template │ ├── assets_ │ │ ├── css │ │ │ ├── main.css │ │ │ ├── shCore.css │ │ │ └── shThemeDefault.css │ │ └── js │ │ │ ├── lib │ │ │ ├── jquery.js │ │ │ ├── require.js │ │ │ └── syntax-highlighter │ │ │ │ ├── shAutoloader.js │ │ │ │ ├── shBrushAS3.js │ │ │ │ ├── shBrushAppleScript.js │ │ │ │ ├── shBrushBash.js │ │ │ │ ├── shBrushCSharp.js │ │ │ │ ├── shBrushColdFusion.js │ │ │ │ ├── shBrushCpp.js │ │ │ │ ├── shBrushCss.js │ │ │ │ ├── shBrushDelphi.js │ │ │ │ ├── shBrushDiff.js │ │ │ │ ├── shBrushErlang.js │ │ │ │ ├── shBrushGroovy.js │ │ │ │ ├── shBrushJScript.js │ │ │ │ ├── shBrushJava.js │ │ │ │ ├── shBrushJavaFX.js │ │ │ │ ├── shBrushPerl.js │ │ │ │ ├── shBrushPhp.js │ │ │ │ ├── shBrushPlain.js │ │ │ │ ├── shBrushPowerShell.js │ │ │ │ ├── shBrushPython.js │ │ │ │ ├── shBrushRuby.js │ │ │ │ ├── shBrushSass.js │ │ │ │ ├── shBrushScala.js │ │ │ │ ├── shBrushSql.js │ │ │ │ ├── shBrushVb.js │ │ │ │ ├── shBrushXml.js │ │ │ │ ├── shCore.js │ │ │ │ └── shLegacy.js │ │ │ └── main.js │ ├── doc.hbs │ ├── footer.hbs │ ├── header.hbs │ ├── index.hbs │ └── sidebar.hbs ├── helpers.js ├── package.js └── templates │ ├── mod │ ├── collection.hbs │ ├── default.hbs │ ├── index.hbs │ └── pkg.hbs │ └── spec │ ├── default.hbs │ ├── package.hbs │ └── runner.hbs ├── build.js ├── clean.sh ├── component.json ├── doc ├── html │ ├── array.html │ ├── assets_ │ │ ├── css │ │ │ ├── main.css │ │ │ ├── shCore.css │ │ │ └── shThemeDefault.css │ │ └── js │ │ │ ├── lib │ │ │ ├── jquery.js │ │ │ ├── require.js │ │ │ └── syntax-highlighter │ │ │ │ ├── shAutoloader.js │ │ │ │ ├── shBrushAS3.js │ │ │ │ ├── shBrushAppleScript.js │ │ │ │ ├── shBrushBash.js │ │ │ │ ├── shBrushCSharp.js │ │ │ │ ├── shBrushColdFusion.js │ │ │ │ ├── shBrushCpp.js │ │ │ │ ├── shBrushCss.js │ │ │ │ ├── shBrushDelphi.js │ │ │ │ ├── shBrushDiff.js │ │ │ │ ├── shBrushErlang.js │ │ │ │ ├── shBrushGroovy.js │ │ │ │ ├── shBrushJScript.js │ │ │ │ ├── shBrushJava.js │ │ │ │ ├── shBrushJavaFX.js │ │ │ │ ├── shBrushPerl.js │ │ │ │ ├── shBrushPhp.js │ │ │ │ ├── shBrushPlain.js │ │ │ │ ├── shBrushPowerShell.js │ │ │ │ ├── shBrushPython.js │ │ │ │ ├── shBrushRuby.js │ │ │ │ ├── shBrushSass.js │ │ │ │ ├── shBrushScala.js │ │ │ │ ├── shBrushSql.js │ │ │ │ ├── shBrushVb.js │ │ │ │ ├── shBrushXml.js │ │ │ │ ├── shCore.js │ │ │ │ └── shLegacy.js │ │ │ └── main.js │ ├── collection.html │ ├── financial.html │ ├── function.html │ ├── index.html │ ├── lang.html │ ├── math.html │ ├── number.html │ ├── object.html │ ├── queryString.html │ ├── random.html │ ├── sidebar_.html │ ├── string.html │ └── time.html └── mdown │ ├── array.md │ ├── collection.md │ ├── function.md │ ├── lang.md │ ├── math.md │ ├── number.md │ ├── object.md │ ├── queryString.md │ ├── random.md │ ├── string.md │ └── time.md ├── package.json ├── src ├── array.js ├── array │ ├── append.js │ ├── combine.js │ ├── compact.js │ ├── contains.js │ ├── difference.js │ ├── every.js │ ├── filter.js │ ├── find.js │ ├── flatten.js │ ├── forEach.js │ ├── indexOf.js │ ├── insert.js │ ├── intersection.js │ ├── invoke.js │ ├── join.js │ ├── lastIndexOf.js │ ├── map.js │ ├── max.js │ ├── min.js │ ├── pick.js │ ├── pluck.js │ ├── range.js │ ├── reduce.js │ ├── reduceRight.js │ ├── reject.js │ ├── remove.js │ ├── removeAll.js │ ├── shuffle.js │ ├── some.js │ ├── sort.js │ ├── split.js │ ├── toLookup.js │ ├── union.js │ ├── unique.js │ ├── xor.js │ └── zip.js ├── collection.js ├── collection │ ├── contains.js │ ├── every.js │ ├── filter.js │ ├── find.js │ ├── forEach.js │ ├── make_.js │ ├── map.js │ ├── max.js │ ├── min.js │ ├── pluck.js │ ├── reduce.js │ ├── reject.js │ ├── size.js │ └── some.js ├── function.js ├── function │ ├── bind.js │ ├── compose.js │ ├── curry.js │ ├── debounce.js │ ├── func.js │ ├── prop.js │ ├── series.js │ └── throttle.js ├── index.js ├── lang.js ├── lang │ ├── clone.js │ ├── createObject.js │ ├── ctorApply.js │ ├── defaults.js │ ├── inheritPrototype.js │ ├── isArguments.js │ ├── isArray.js │ ├── isBoolean.js │ ├── isDate.js │ ├── isEmpty.js │ ├── isFinite.js │ ├── isFunction.js │ ├── isKind.js │ ├── isNaN.js │ ├── isNull.js │ ├── isNumber.js │ ├── isObject.js │ ├── isRegExp.js │ ├── isString.js │ ├── isUndefined.js │ ├── kindOf.js │ └── toArray.js ├── math.js ├── math │ ├── ceil.js │ ├── clamp.js │ ├── countSteps.js │ ├── floor.js │ ├── inRange.js │ ├── isNear.js │ ├── lerp.js │ ├── loop.js │ ├── map.js │ ├── norm.js │ └── round.js ├── number.js ├── number │ ├── MAX_INT.js │ ├── MAX_UINT.js │ ├── MIN_INT.js │ ├── abbreviate.js │ ├── currencyFormat.js │ ├── enforcePrecision.js │ ├── pad.js │ ├── rol.js │ ├── ror.js │ ├── sign.js │ ├── toInt.js │ ├── toUInt.js │ └── toUInt31.js ├── object.js ├── object │ ├── contains.js │ ├── deepFillIn.js │ ├── deepMixIn.js │ ├── every.js │ ├── fillIn.js │ ├── filter.js │ ├── find.js │ ├── forIn.js │ ├── forOwn.js │ ├── get.js │ ├── has.js │ ├── hasOwn.js │ ├── keys.js │ ├── map.js │ ├── max.js │ ├── merge.js │ ├── min.js │ ├── mixIn.js │ ├── namespace.js │ ├── pick.js │ ├── pluck.js │ ├── reduce.js │ ├── reject.js │ ├── set.js │ ├── size.js │ ├── some.js │ ├── unset.js │ └── values.js ├── queryString.js ├── queryString │ ├── contains.js │ ├── decode.js │ ├── encode.js │ ├── getParam.js │ ├── getQuery.js │ ├── parse.js │ └── setParam.js ├── random.js ├── random │ ├── choice.js │ ├── guid.js │ ├── rand.js │ ├── randBit.js │ ├── randHex.js │ ├── randInt.js │ ├── randSign.js │ └── random.js ├── string.js ├── string │ ├── camelCase.js │ ├── contains.js │ ├── crop.js │ ├── endsWith.js │ ├── escapeHtml.js │ ├── escapeRegExp.js │ ├── escapeUnicode.js │ ├── hyphenate.js │ ├── interpolate.js │ ├── lowerCase.js │ ├── lpad.js │ ├── ltrim.js │ ├── makePath.js │ ├── normalizeLineBreaks.js │ ├── pascalCase.js │ ├── properCase.js │ ├── removeNonASCII.js │ ├── removeNonWord.js │ ├── repeat.js │ ├── replaceAccents.js │ ├── rpad.js │ ├── rtrim.js │ ├── sentenceCase.js │ ├── slugify.js │ ├── startsWith.js │ ├── stripHtmlTags.js │ ├── trim.js │ ├── truncate.js │ ├── typecast.js │ ├── unCamelCase.js │ ├── underscore.js │ ├── unescapeHtml.js │ ├── unescapeUnicode.js │ ├── unhyphenate.js │ └── upperCase.js ├── time.js └── time │ ├── now.js │ ├── parseMs.js │ └── toTimeString.js ├── tests ├── lib │ ├── jasmine │ │ ├── MIT.LICENSE │ │ ├── jasmine-html.js │ │ ├── jasmine.async.js │ │ ├── jasmine.css │ │ └── jasmine.js │ └── requirejs │ │ └── require.js ├── runner.html ├── runner.js └── spec │ ├── array │ ├── spec-append.js │ ├── spec-combine.js │ ├── spec-compact.js │ ├── spec-contains.js │ ├── spec-difference.js │ ├── spec-every.js │ ├── spec-filter.js │ ├── spec-find.js │ ├── spec-flatten.js │ ├── spec-forEach.js │ ├── spec-indexOf.js │ ├── spec-insert.js │ ├── spec-intersection.js │ ├── spec-invoke.js │ ├── spec-join.js │ ├── spec-lastIndexOf.js │ ├── spec-map.js │ ├── spec-max.js │ ├── spec-min.js │ ├── spec-pick.js │ ├── spec-pluck.js │ ├── spec-range.js │ ├── spec-reduce.js │ ├── spec-reduceRight.js │ ├── spec-reject.js │ ├── spec-remove.js │ ├── spec-removeAll.js │ ├── spec-shuffle.js │ ├── spec-some.js │ ├── spec-sort.js │ ├── spec-split.js │ ├── spec-toLookup.js │ ├── spec-union.js │ ├── spec-unique.js │ ├── spec-xor.js │ └── spec-zip.js │ ├── collection │ ├── spec-contains.js │ ├── spec-every.js │ ├── spec-filter.js │ ├── spec-find.js │ ├── spec-forEach.js │ ├── spec-make_.js │ ├── spec-map.js │ ├── spec-max.js │ ├── spec-min.js │ ├── spec-pluck.js │ ├── spec-reduce.js │ ├── spec-reject.js │ ├── spec-size.js │ └── spec-some.js │ ├── function │ ├── spec-bind.js │ ├── spec-compose.js │ ├── spec-curry.js │ ├── spec-debounce.js │ ├── spec-func.js │ ├── spec-prop.js │ ├── spec-series.js │ └── spec-throttle.js │ ├── lang │ ├── spec-clone.js │ ├── spec-createObject.js │ ├── spec-ctorApply.js │ ├── spec-defaults.js │ ├── spec-inheritPrototype.js │ ├── spec-isArguments.js │ ├── spec-isArray.js │ ├── spec-isBoolean.js │ ├── spec-isDate.js │ ├── spec-isEmpty.js │ ├── spec-isFinite.js │ ├── spec-isFunction.js │ ├── spec-isKind.js │ ├── spec-isNaN.js │ ├── spec-isNull.js │ ├── spec-isNumber.js │ ├── spec-isObject.js │ ├── spec-isRegExp.js │ ├── spec-isString.js │ ├── spec-isUndefined.js │ ├── spec-kindOf.js │ └── spec-toArray.js │ ├── math │ ├── spec-ceil.js │ ├── spec-clamp.js │ ├── spec-countSteps.js │ ├── spec-floor.js │ ├── spec-inRange.js │ ├── spec-isNear.js │ ├── spec-lerp.js │ ├── spec-loop.js │ ├── spec-map.js │ ├── spec-norm.js │ └── spec-round.js │ ├── number │ ├── spec-MAX_INT.js │ ├── spec-MAX_UINT.js │ ├── spec-MIN_INT.js │ ├── spec-abbreviate.js │ ├── spec-currencyFormat.js │ ├── spec-enforcePrecision.js │ ├── spec-pad.js │ ├── spec-rol.js │ ├── spec-ror.js │ ├── spec-sign.js │ ├── spec-toInt.js │ ├── spec-toUInt.js │ └── spec-toUInt31.js │ ├── object │ ├── spec-contains.js │ ├── spec-deepFillIn.js │ ├── spec-deepMixIn.js │ ├── spec-every.js │ ├── spec-fillIn.js │ ├── spec-filter.js │ ├── spec-find.js │ ├── spec-forIn.js │ ├── spec-forOwn.js │ ├── spec-get.js │ ├── spec-has.js │ ├── spec-hasOwn.js │ ├── spec-keys.js │ ├── spec-map.js │ ├── spec-max.js │ ├── spec-merge.js │ ├── spec-min.js │ ├── spec-mixIn.js │ ├── spec-namespace.js │ ├── spec-pick.js │ ├── spec-pluck.js │ ├── spec-reduce.js │ ├── spec-reject.js │ ├── spec-set.js │ ├── spec-size.js │ ├── spec-some.js │ ├── spec-unset.js │ └── spec-values.js │ ├── queryString │ ├── spec-contains.js │ ├── spec-decode.js │ ├── spec-encode.js │ ├── spec-getParam.js │ ├── spec-getQuery.js │ ├── spec-parse.js │ └── spec-setParam.js │ ├── random │ ├── spec-choice.js │ ├── spec-guid.js │ ├── spec-rand.js │ ├── spec-randBit.js │ ├── spec-randHex.js │ ├── spec-randInt.js │ ├── spec-randSign.js │ └── spec-random.js │ ├── spec-array.js │ ├── spec-collection.js │ ├── spec-function.js │ ├── spec-lang.js │ ├── spec-math.js │ ├── spec-number.js │ ├── spec-object.js │ ├── spec-queryString.js │ ├── spec-random.js │ ├── spec-string.js │ ├── spec-time.js │ ├── src │ └── spec-math.js │ ├── string │ ├── spec-camelCase.js │ ├── spec-contains.js │ ├── spec-crop.js │ ├── spec-endsWith.js │ ├── spec-escapeHtml.js │ ├── spec-escapeRegExp.js │ ├── spec-escapeUnicode.js │ ├── spec-hyphenate.js │ ├── spec-interpolate.js │ ├── spec-lowerCase.js │ ├── spec-lpad.js │ ├── spec-ltrim.js │ ├── spec-makePath.js │ ├── spec-normalizeLineBreaks.js │ ├── spec-pascalCase.js │ ├── spec-properCase.js │ ├── spec-removeNonASCII.js │ ├── spec-removeNonWord.js │ ├── spec-repeat.js │ ├── spec-replaceAccents.js │ ├── spec-rpad.js │ ├── spec-rtrim.js │ ├── spec-sentenceCase.js │ ├── spec-slugify.js │ ├── spec-startsWith.js │ ├── spec-stripHtmlTags.js │ ├── spec-trim.js │ ├── spec-truncate.js │ ├── spec-typecast.js │ ├── spec-unCamelCase.js │ ├── spec-underscore.js │ ├── spec-unescapeHtml.js │ ├── spec-unescapeUnicode.js │ ├── spec-unhyphenate.js │ └── spec-upperCase.js │ └── time │ ├── spec-now.js │ ├── spec-parseMs.js │ └── spec-toTimeString.js └── updateDocs.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .tmp* 2 | .project 3 | .settings/ 4 | .livereload 5 | 6 | .DS_Store? 7 | ehthumbs.db 8 | Icon? 9 | Thumbs.db 10 | 11 | 12 | # ---- 13 | 14 | # we also ignore node_modules 15 | node_modules/ 16 | 17 | # we ignore coverage reports since they change at each build 18 | coverage/ 19 | 20 | 21 | # ---- 22 | 23 | 24 | # ignore files added by `npm install` 25 | 26 | /array.js 27 | /array/ 28 | /collection.js 29 | /collection/ 30 | /financial.js 31 | /financial/ 32 | /function.js 33 | /function/ 34 | /index.js 35 | /lang.js 36 | /lang/ 37 | /math.js 38 | /math/ 39 | /number.js 40 | /number/ 41 | /object.js 42 | /object/ 43 | /queryString.js 44 | /queryString/ 45 | /random.js 46 | /random/ 47 | /string.js 48 | /string/ 49 | /time.js 50 | /time/ 51 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # dumb files 2 | # ========== 3 | 4 | .tmp* 5 | .project 6 | .settings/ 7 | .livereload 8 | .DS_Store? 9 | ehthumbs.db 10 | Icon? 11 | Thumbs.db 12 | 13 | 14 | # stuff not needed by node 15 | # ======================== 16 | 17 | node_modules/ 18 | tests/ 19 | _build/ 20 | doc/html/ 21 | 22 | # we keep the doc/mdown/ folder in case npm decides to display it in the future 23 | # also good in case user is using an old version or working offline 24 | 25 | # we also keep the src/ folder in case the user still needs the AMD modules 26 | # after build (see issue #102) 27 | 28 | component.json 29 | updateDocs.sh 30 | clean.sh 31 | build.js 32 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_build/doc_template/assets_/js/lib/syntax-highlighter/shBrushPlain.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | ;(function() 18 | { 19 | // CommonJS 20 | SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null); 21 | 22 | function Brush() 23 | { 24 | }; 25 | 26 | Brush.prototype = new SyntaxHighlighter.Highlighter(); 27 | Brush.aliases = ['text', 'plain']; 28 | 29 | SyntaxHighlighter.brushes.Plain = Brush; 30 | 31 | // CommonJS 32 | typeof(exports) != 'undefined' ? exports.Brush = Brush : null; 33 | })(); 34 | -------------------------------------------------------------------------------- /_build/doc_template/doc.hbs: -------------------------------------------------------------------------------- 1 | {{> header}} 2 | 7 | {{{content}}} 8 | {{> footer}} 9 | -------------------------------------------------------------------------------- /_build/doc_template/footer.hbs: -------------------------------------------------------------------------------- 1 |
2 | Documentation generated by mdoc. 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /_build/doc_template/header.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{page_title}} 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 | -------------------------------------------------------------------------------- /_build/doc_template/index.hbs: -------------------------------------------------------------------------------- 1 | {{> header}} 2 | 3 | Fork me on GitHub 4 | 5 | {{{content}}} 6 |

Documentation

7 | 12 | {{> footer}} 13 | -------------------------------------------------------------------------------- /_build/doc_template/sidebar.hbs: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 |
6 |
7 | {{#modules}} 8 |

{{module}}

9 |
10 | {{#toc}} 11 | 12 |

{{title}}

13 | {{{description}}} 14 |
15 | {{/toc}} 16 |
17 | {{/modules}} 18 |
19 |
20 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | 2 | # delete files created by node.js install 3 | # not using `git clean -X -d` since node_modules is also ignored 4 | 5 | rm -r array.js 6 | rm -r array 7 | rm -r collection.js 8 | rm -r collection 9 | rm -r financial.js 10 | rm -r financial 11 | rm -r function.js 12 | rm -r function 13 | rm -r index.js 14 | rm -r lang.js 15 | rm -r lang 16 | rm -r math.js 17 | rm -r math 18 | rm -r number.js 19 | rm -r number 20 | rm -r object.js 21 | rm -r object 22 | rm -r queryString.js 23 | rm -r queryString 24 | rm -r random.js 25 | rm -r random 26 | rm -r string.js 27 | rm -r string 28 | rm -r time.js 29 | rm -r time 30 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "amd-utils", 3 | "version" : "0.10.0", 4 | "main" : "src/" 5 | } 6 | -------------------------------------------------------------------------------- /doc/html/assets_/js/lib/syntax-highlighter/shBrushPlain.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | ;(function() 18 | { 19 | // CommonJS 20 | SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null); 21 | 22 | function Brush() 23 | { 24 | }; 25 | 26 | Brush.prototype = new SyntaxHighlighter.Highlighter(); 27 | Brush.aliases = ['text', 'plain']; 28 | 29 | SyntaxHighlighter.brushes.Plain = Brush; 30 | 31 | // CommonJS 32 | typeof(exports) != 'undefined' ? exports.Brush = Brush : null; 33 | })(); 34 | -------------------------------------------------------------------------------- /doc/mdown/time.md: -------------------------------------------------------------------------------- 1 | # amd-utils / time # 2 | 3 | Utilities for time manipulation. 4 | 5 | 6 | ## now():Number 7 | 8 | Returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC. 9 | Uses `Date.now()` if available. 10 | 11 | ### Example 12 | 13 | ```js 14 | now(); // 1335449614650 15 | ``` 16 | 17 | 18 | 19 | ## parseMs(ms):Object 20 | 21 | Parse timestamp (milliseconds) into an object `{milliseconds:number, 22 | seconds:number, minutes:number, hours:number, days:number}`. 23 | 24 | ### Example 25 | 26 | ```js 27 | // {days:27, hours:4, minutes:26, seconds:5, milliseconds:454} 28 | parseMs(2348765454); 29 | ``` 30 | 31 | 32 | 33 | ## toTimeString(ms):String 34 | 35 | Convert timestamp (milliseconds) into a time string in the format "[H:]MM:SS". 36 | 37 | ### Example 38 | 39 | ```js 40 | toTimeString(12513); // "00:12" 41 | toTimeString(951233); // "15:51" 42 | toTimeString(8765235); // "2:26:05" 43 | ``` 44 | -------------------------------------------------------------------------------- /src/array/append.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Appends an array to the end of another. 5 | * The first array will be modified. 6 | * @version 0.1.1 (2012/06/10) 7 | */ 8 | function append(arr1, arr2) { 9 | var pad = arr1.length, 10 | i = -1, 11 | n = arr2.length; 12 | while (++i < n) { 13 | arr1[pad + i] = arr2[i]; 14 | } 15 | return arr1; 16 | } 17 | return append; 18 | }); 19 | -------------------------------------------------------------------------------- /src/array/combine.js: -------------------------------------------------------------------------------- 1 | define(['./indexOf'], function (indexOf) { 2 | 3 | /** 4 | * Combines an array with all the items of another. 5 | * Does not allow duplicates and is case and type sensitive. 6 | * @version 0.1.0 (2012/01/28) 7 | */ 8 | function combine(arr1, arr2) { 9 | 10 | var x, length = arr2.length; 11 | 12 | for (x = 0; x < length; x++) { 13 | if (indexOf(arr1, arr2[x]) === -1) { 14 | arr1.push(arr2[x]); 15 | } 16 | } 17 | 18 | return arr1; 19 | } 20 | return combine; 21 | }); 22 | -------------------------------------------------------------------------------- /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/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/array/difference.js: -------------------------------------------------------------------------------- 1 | define(['./unique', './filter', './some', './contains'], function (unique, filter, some, contains) { 2 | 3 | 4 | /** 5 | * Return a new Array with elements that aren't present in the other Arrays. 6 | * @version 0.1.0 (2011/01/12) 7 | */ 8 | function difference(arr) { 9 | var arrs = Array.prototype.slice.call(arguments, 1), 10 | result = filter(unique(arr), function(needle){ 11 | return !some(arrs, function(haystack){ 12 | return contains(haystack, needle); 13 | }); 14 | }); 15 | return result; 16 | } 17 | 18 | return difference; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/array/every.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array every 5 | * @version 0.5.0 (2012/12/18) 6 | */ 7 | function every(arr, callback, thisObj) { 8 | var result = true, 9 | i = -1, 10 | n = arr.length; 11 | while (++i < n) { 12 | // we iterate over sparse items since there is no way to make it 13 | // work properly on IE 7-8. see #64 14 | if (!callback.call(thisObj, arr[i], i, arr) ) { 15 | result = false; 16 | break; 17 | } 18 | } 19 | return result; 20 | } 21 | 22 | return every; 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/filter.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Array filter 5 | * @version 0.4.0 (2012/07/26) 6 | */ 7 | function filter(arr, callback, thisObj) { 8 | var results = []; 9 | forEach(arr, function (val, i, arr) { 10 | if ( callback.call(thisObj, val, i, arr) ) { 11 | results.push(val); 12 | } 13 | }); 14 | return results; 15 | } 16 | 17 | return filter; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/array/find.js: -------------------------------------------------------------------------------- 1 | define(['./some'], function (some) { 2 | 3 | /** 4 | * Returns first item that matches criteria 5 | * @version 0.3.0 (2012/12/18) 6 | */ 7 | function find(arr, iterator, thisObj){ 8 | var needle, 9 | i = -1, n = arr.length, 10 | val; 11 | while (++i < n){ 12 | val = arr[i]; 13 | if (iterator.call(thisObj, val, i, arr)) { 14 | needle = val; 15 | break; 16 | } 17 | } 18 | return needle; 19 | } 20 | 21 | return find; 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/flatten.js: -------------------------------------------------------------------------------- 1 | define(['../lang/isArray'], function (isArray) { 2 | /* 3 | * Helper function to flatten to a destination array. 4 | * Used to remove the need to create intermediate arrays while flattening. 5 | */ 6 | function flattenTo(arr, result, level) { 7 | if (level === 0) { 8 | result.push.apply(result, arr); 9 | return; 10 | } 11 | 12 | var value, 13 | i = -1, 14 | n = arr.length; 15 | while (++i < n) { 16 | value = arr[i]; 17 | if (isArray(value)) { 18 | flattenTo(value, result, level - 1); 19 | } else { 20 | result.push(value); 21 | } 22 | } 23 | return result; 24 | } 25 | 26 | /** 27 | * Recursively flattens an array. 28 | * A new array containing all the elements is returned. 29 | * If `shallow` is true, it will only flatten one level. 30 | * @version 0.1.0 (2012/08/02) 31 | */ 32 | function flatten(arr, shallow) { 33 | return flattenTo(arr, [], shallow ? 1 : -1); 34 | } 35 | return flatten; 36 | }); 37 | 38 | -------------------------------------------------------------------------------- /src/array/forEach.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array forEach 5 | * @version 0.8.0 (2012/12/18) 6 | */ 7 | function forEach(arr, callback, thisObj) { 8 | if (arr == null) { 9 | return; 10 | } 11 | var i = -1, 12 | n = arr.length; 13 | while (++i < n) { 14 | // we iterate over sparse items since there is no way to make it 15 | // work properly on IE 7-8. see #64 16 | if ( callback.call(thisObj, arr[i], i, arr) === false ) { 17 | break; 18 | } 19 | } 20 | } 21 | 22 | return forEach; 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /src/array/indexOf.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array.indexOf 5 | * @version 0.5.0 (2012/12/18) 6 | */ 7 | function indexOf(arr, item, fromIndex) { 8 | fromIndex = fromIndex || 0; 9 | var n = arr.length, 10 | i = fromIndex < 0? n + fromIndex : fromIndex; 11 | while (i < n) { 12 | // we iterate over sparse items since there is no way to make it 13 | // work properly on IE 7-8. see #64 14 | if (arr[i] === item) { 15 | return i; 16 | } 17 | i += 1; 18 | } 19 | return -1; 20 | } 21 | 22 | return indexOf; 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/insert.js: -------------------------------------------------------------------------------- 1 | define(['./difference', '../lang/toArray'], function (difference, toArray) { 2 | 3 | /** 4 | * Insert item into array if not already present. 5 | * @version 0.2.0 (2012/01/28) 6 | */ 7 | function insert(arr, rest_items) { 8 | var diff = difference(toArray(arguments).slice(1), arr); 9 | if (diff.length) { 10 | Array.prototype.push.apply(arr, diff); 11 | } 12 | return arr.length; 13 | } 14 | return insert; 15 | }); 16 | -------------------------------------------------------------------------------- /src/array/intersection.js: -------------------------------------------------------------------------------- 1 | define(['./unique', './filter', './every', './contains'], function (unique, filter, every, contains) { 2 | 3 | 4 | /** 5 | * Return a new Array with elements common to all Arrays. 6 | * - based on underscore.js implementation 7 | * @version 0.1.0 (2011/01/12) 8 | */ 9 | function intersection(arr) { 10 | var arrs = Array.prototype.slice.call(arguments, 1), 11 | result = filter(unique(arr), function(needle){ 12 | return every(arrs, function(haystack){ 13 | return contains(haystack, needle); 14 | }); 15 | }); 16 | return result; 17 | } 18 | 19 | return intersection; 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /src/array/invoke.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Call `methodName` on each item of the array passing custom arguments if 5 | * needed. 6 | * @version 0.1.0 (2012/10/02) 7 | */ 8 | function invoke(arr, methodName, var_args){ 9 | var args = Array.prototype.slice.call(arguments, 2); 10 | forEach(arr, function(item){ 11 | item[methodName].apply(item, args); 12 | }); 13 | return arr; 14 | } 15 | 16 | return invoke; 17 | }); 18 | -------------------------------------------------------------------------------- /src/array/join.js: -------------------------------------------------------------------------------- 1 | define(['./filter'], function(filter) { 2 | 3 | function isValidString(val) { 4 | return (val != null && val !== ''); 5 | } 6 | 7 | /** 8 | * Joins strings with the specified separator inserted between each value. 9 | * Null values and empty strings will be excluded. 10 | * @version 0.1.0 (2012/08/24) 11 | */ 12 | function join(items, separator) { 13 | separator = separator || ''; 14 | return filter(items, isValidString).join(separator); 15 | } 16 | 17 | return join; 18 | }); 19 | -------------------------------------------------------------------------------- /src/array/lastIndexOf.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array lastIndexOf 5 | * @version 0.4.0 (2012/12/18) 6 | */ 7 | function lastIndexOf(arr, item, fromIndex) { 8 | var len = arr.length; 9 | fromIndex = (fromIndex == null || fromIndex >= len)? len - 1 : fromIndex; 10 | fromIndex = (fromIndex < 0)? len + fromIndex : fromIndex; 11 | while (fromIndex >= 0) { 12 | // we iterate over sparse items since there is no way to make it 13 | // work properly on IE 7-8. see #64 14 | if (arr[fromIndex] === item) { 15 | return fromIndex; 16 | } 17 | fromIndex--; 18 | } 19 | return -1; 20 | } 21 | 22 | return lastIndexOf; 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/map.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Array map 5 | * @version 0.5.0 (2012/11/19) 6 | */ 7 | function map(arr, callback, thisObj) { 8 | var results = []; 9 | if (arr == null){ 10 | return results; 11 | } 12 | forEach(arr, function (val, i, arr) { 13 | results[i] = callback.call(thisObj, val, i, arr); 14 | }); 15 | return results; 16 | } 17 | 18 | return map; 19 | }); 20 | -------------------------------------------------------------------------------- /src/array/max.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Return maximum value inside array 5 | * @version 0.1.0 (2012/01/29) 6 | */ 7 | function max(arr, iterator){ 8 | if (arr.length && !iterator) { 9 | return Math.max.apply(Math, arr); 10 | } else if (!arr.length) { 11 | return Infinity; 12 | } else { 13 | var result, 14 | compare = -Infinity, 15 | tmp; 16 | forEach(arr, function(val, i, list){ 17 | tmp = iterator(val, i, list); 18 | if (tmp > compare) { 19 | compare = tmp; 20 | result = val; 21 | } 22 | }); 23 | return result; 24 | } 25 | } 26 | 27 | return max; 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /src/array/min.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Return minimum value inside array 5 | * @version 0.1.0 (2012/01/29) 6 | */ 7 | function min(arr, iterator){ 8 | if (arr.length && !iterator) { 9 | return Math.min.apply(Math, arr); 10 | } else if (!arr.length) { 11 | return -Infinity; 12 | } else { 13 | var result, 14 | compare = Infinity, 15 | tmp; 16 | forEach(arr, function(val, i, list){ 17 | tmp = iterator(val, i, list); 18 | if (tmp < compare) { 19 | compare = tmp; 20 | result = val; 21 | } 22 | }); 23 | return result; 24 | } 25 | } 26 | 27 | return min; 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /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/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/array/range.js: -------------------------------------------------------------------------------- 1 | define(['../math/countSteps'], function (countSteps) { 2 | 3 | /** 4 | * Returns an Array of numbers inside range. 5 | * @version 0.1.0 (2011/11/15) 6 | */ 7 | function range(start, stop, step) { 8 | if (stop == null) { 9 | stop = start; 10 | start = 0; 11 | } 12 | step = step || 1; 13 | 14 | var result = [], 15 | nSteps = countSteps(stop - start, step), 16 | i = start; 17 | 18 | while (i <= stop) { 19 | result.push(i); 20 | i += step; 21 | } 22 | 23 | return result; 24 | } 25 | 26 | return range; 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /src/array/reduce.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * Array reduce 5 | * @version 0.3.0 (2012/07/26) 6 | */ 7 | function reduce(arr, fn, initVal) { 8 | // check for args.length since initVal might be "undefined" see #gh-57 9 | var hasInit = arguments.length > 2, 10 | result = initVal; 11 | 12 | if (!arr.length && !hasInit) { 13 | throw new Error('reduce of empty array with no initial value'); 14 | } 15 | 16 | forEach(arr, function (val, i, arr) { 17 | if (! hasInit) { 18 | result = val; 19 | hasInit = true; 20 | } else { 21 | result = fn(result, val, i, arr); 22 | } 23 | }); 24 | 25 | return result; 26 | } 27 | 28 | return reduce; 29 | }); 30 | -------------------------------------------------------------------------------- /src/array/reduceRight.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array reduceRight 5 | * @version 0.5.0 (2012/12/18) 6 | */ 7 | function reduceRight(arr, fn, initVal) { 8 | // check for args.length since initVal might be "undefined" see #gh-57 9 | var hasInit = arguments.length > 2, 10 | result = initVal, 11 | i = arr.length, 12 | val; 13 | 14 | if (!i && !hasInit) { 15 | throw new Error('reduce of empty array with no initial value'); 16 | } 17 | 18 | while (--i >= 0) { 19 | // we iterate over sparse items since there is no way to make it 20 | // work properly on IE 7-8. see #64 21 | val = arr[i]; 22 | if (! hasInit) { 23 | result = val; 24 | hasInit = true; 25 | } else { 26 | result = fn(result, val, i, arr); 27 | } 28 | } 29 | return result; 30 | } 31 | 32 | return reduceRight; 33 | }); 34 | -------------------------------------------------------------------------------- /src/array/reject.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function(forEach) { 2 | 3 | /** 4 | * Array reject 5 | * @version 0.1.0 (2012/09/04) 6 | */ 7 | function reject(arr, callback, thisObj) { 8 | var results = []; 9 | forEach(arr, function(val, i, arr) { 10 | if (!callback.call(thisObj, val, i, arr)) { 11 | results.push(val); 12 | } 13 | }); 14 | return results; 15 | } 16 | 17 | return reject; 18 | }); 19 | -------------------------------------------------------------------------------- /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/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/array/shuffle.js: -------------------------------------------------------------------------------- 1 | define(['../random/randInt', './forEach'], function (randInt, forEach) { 2 | 3 | /** 4 | * Shuffle array items. 5 | * @version 0.2.0 (2011/11/17) 6 | */ 7 | function shuffle(arr) { 8 | var result = [], 9 | rnd; 10 | forEach(arr, function(val, i, arr){ 11 | if (!i) { 12 | result[0] = val; 13 | } else { 14 | rnd = randInt(0, i); 15 | result[i] = result[rnd]; 16 | result[rnd] = val; 17 | } 18 | }); 19 | return result; 20 | } 21 | 22 | return shuffle; 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/some.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Array some 5 | * @version 0.5.0 (2012/12/18) 6 | */ 7 | function some(arr, callback, thisObj) { 8 | var result = false, 9 | i = -1, 10 | n = arr.length; 11 | while (++i < n) { 12 | // we iterate over sparse items since there is no way to make it 13 | // work properly on IE 7-8. see #64 14 | if ( callback.call(thisObj, arr[i], i, arr) ) { 15 | result = true; 16 | break; 17 | } 18 | } 19 | return result; 20 | } 21 | 22 | return some; 23 | }); 24 | -------------------------------------------------------------------------------- /src/array/split.js: -------------------------------------------------------------------------------- 1 | define(function() { 2 | 3 | /** 4 | * Split array into a fixed number of segments. 5 | * @version 0.1.0 6 | */ 7 | function split(array, segments) { 8 | segments = segments || 2; 9 | 10 | var output = [], 11 | segmentLength = Math.floor(array.length / segments), 12 | remainder = array.length % segments, 13 | start = 0, 14 | i = 0, 15 | n = array.length, 16 | len; 17 | 18 | while (start < n) { 19 | len = i++ < remainder ? segmentLength + 1 : segmentLength; 20 | output.push(array.slice(start, start + len)); 21 | start += len; 22 | } 23 | 24 | return output; 25 | } 26 | return split; 27 | }); 28 | -------------------------------------------------------------------------------- /src/array/toLookup.js: -------------------------------------------------------------------------------- 1 | define(['../lang/isFunction'], function (isFunction) { 2 | 3 | /** 4 | * Creates an object that holds a lookup for the objects in the array. 5 | * The key for each value in `arr` is specified by the `key` parameter. 6 | * If `key` is a function, the function will be called with the value as 7 | * the parameter and the result will be used for the key. If `key` is a 8 | * string it will use the property specified by `key` as the key for each 9 | * value. 10 | * @version 0.1.0 (2012/08/02) 11 | */ 12 | function toLookup(arr, key) { 13 | var result = {}, 14 | value, 15 | i = -1, n = arr.length; 16 | if (isFunction(key)) { 17 | while (++i < n) { 18 | value = arr[i]; 19 | result[key(value)] = value; 20 | } 21 | } else { 22 | while (++i < n) { 23 | value = arr[i]; 24 | result[value[key]] = value; 25 | } 26 | } 27 | return result; 28 | } 29 | return toLookup; 30 | }); 31 | -------------------------------------------------------------------------------- /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/array/unique.js: -------------------------------------------------------------------------------- 1 | define(['./indexOf', './filter'], function(indexOf, filter){ 2 | 3 | /** 4 | * @return {array} Array of unique items 5 | * @version 0.1.0 (2011/10/18) 6 | */ 7 | function unique(arr){ 8 | return filter(arr, isUnique); 9 | } 10 | 11 | function isUnique(item, i, arr){ 12 | return indexOf(arr, item, i+1) === -1; 13 | } 14 | 15 | return unique; 16 | }); 17 | 18 | -------------------------------------------------------------------------------- /src/array/xor.js: -------------------------------------------------------------------------------- 1 | define(['./unique', './filter', './contains'], function (unique, filter, contains) { 2 | 3 | 4 | /** 5 | * Exclusive OR. Returns items that are present in a single array. 6 | * - like ptyhon's `symmetric_difference` 7 | * @version 0.1.0 (2011/01/12) 8 | */ 9 | function xor(arr1, arr2) { 10 | arr1 = unique(arr1); 11 | arr2 = unique(arr2); 12 | 13 | var a1 = filter(arr1, function(item){ 14 | return !contains(arr2, item); 15 | }), 16 | a2 = filter(arr2, function(item){ 17 | return !contains(arr1, item); 18 | }); 19 | 20 | return a1.concat(a2); 21 | } 22 | 23 | return xor; 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /src/array/zip.js: -------------------------------------------------------------------------------- 1 | define(['./max', './pluck'], function (max, pluck) { 2 | 3 | /** 4 | * Merges together the values of each of the arrays with the values at the 5 | * corresponding position. 6 | * @version 0.1.0 (2012/10/30) 7 | */ 8 | function zip(arr){ 9 | var len = arr? max(pluck(arguments, 'length')) : 0, 10 | result = new Array(len), 11 | i = -1; 12 | while (++i < len){ 13 | result[i] = pluck(arguments, i); 14 | } 15 | return result; 16 | } 17 | 18 | return zip; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/collection.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'contains' : require('./collection/contains'), 7 | 'every' : require('./collection/every'), 8 | 'filter' : require('./collection/filter'), 9 | 'find' : require('./collection/find'), 10 | 'forEach' : require('./collection/forEach'), 11 | 'make_' : require('./collection/make_'), 12 | 'map' : require('./collection/map'), 13 | 'max' : require('./collection/max'), 14 | 'min' : require('./collection/min'), 15 | 'pluck' : require('./collection/pluck'), 16 | 'reduce' : require('./collection/reduce'), 17 | 'reject' : require('./collection/reject'), 18 | 'size' : require('./collection/size'), 19 | 'some' : require('./collection/some') 20 | }; 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /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/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/collection/filter.js: -------------------------------------------------------------------------------- 1 | define(['./forEach'], function (forEach) { 2 | 3 | /** 4 | * filter collection values, returns array. 5 | * @version 0.3.0 (2012/11/19) 6 | */ 7 | function filter(list, iterator, context) { 8 | var results = []; 9 | if (!list) { 10 | return results; 11 | } 12 | forEach(list, function(value, index, list) { 13 | if (iterator.call(context, value, index, list)) { 14 | results[results.length] = value; 15 | } 16 | }); 17 | return results; 18 | } 19 | 20 | return filter; 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /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/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/collection/make_.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | 3 | /** 4 | * internal method used to create other collection modules. 5 | * @version 0.2.0 (2012/10/30) 6 | */ 7 | function makeCollectionMethod(arrMethod, objMethod, defaultReturn) { 8 | return function(){ 9 | var args = Array.prototype.slice.call(arguments); 10 | if (args[0] == null) { 11 | return defaultReturn; 12 | } 13 | // array-like is treated as array 14 | return (typeof args[0].length === 'number')? arrMethod.apply(null, args) : objMethod.apply(null, args); 15 | }; 16 | } 17 | 18 | return makeCollectionMethod; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/collection/map.js: -------------------------------------------------------------------------------- 1 | define(['../lang/isObject', '../object/values', '../array/map'], function (isObject, values, arrMap) { 2 | 3 | /** 4 | * Map collection values, returns Array. 5 | * @version 0.2.0 (2012/11/19) 6 | */ 7 | function map(list, callback, thisObj) { 8 | // list.length to check array-like object, if not array-like 9 | // we simply map all the object values 10 | if( isObject(list) && list.length == null ){ 11 | list = values(list); 12 | } 13 | return arrMap(list, function (val, key, list) { 14 | return callback.call(thisObj, val, key, list); 15 | }); 16 | } 17 | 18 | return map; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /src/collection/reject.js: -------------------------------------------------------------------------------- 1 | define(['./filter'], function (filter) { 2 | 3 | /** 4 | * Inverse or collection/filter 5 | * @version 0.1.0 (2012/11/13) 6 | */ 7 | function reject(list, iterator, context) { 8 | return filter(list, function(value, index, list) { 9 | return !iterator.call(context, value, index, list); 10 | }, context); 11 | } 12 | 13 | return reject; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/collection/size.js: -------------------------------------------------------------------------------- 1 | define(['../lang/isArray', '../object/size'], function (isArray, objSize) { 2 | 3 | /** 4 | * Get collection size 5 | * @version 0.2.0 (2012/11/16) 6 | */ 7 | function size(list) { 8 | if (!list) { 9 | return 0; 10 | } 11 | if (isArray(list)) { 12 | return list.length; 13 | } 14 | return objSize(list); 15 | } 16 | 17 | return size; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /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/function.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'bind' : require('./function/bind'), 7 | 'compose' : require('./function/compose'), 8 | 'curry' : require('./function/curry'), 9 | 'debounce' : require('./function/debounce'), 10 | 'func' : require('./function/func'), 11 | 'prop' : require('./function/prop'), 12 | 'series' : require('./function/series'), 13 | 'throttle' : require('./function/throttle') 14 | }; 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /src/function/bind.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | 3 | function slice(arr, offset){ 4 | return Array.prototype.slice.call(arr, offset || 0); 5 | } 6 | 7 | /** 8 | * Return a function that will execute in the given context, optionally adding any additional supplied parameters to the beginning of the arguments collection. 9 | * @param {Function} fn Function. 10 | * @param {object} context Execution context. 11 | * @param {rest} args Arguments (0...n arguments). 12 | * @return {Function} Wrapped Function. 13 | * @version 0.1.0 (2011/02/18) 14 | */ 15 | function bind(fn, context, args){ 16 | var argsArr = slice(arguments, 2); //curried args 17 | return function(){ 18 | return fn.apply(context, argsArr.concat(slice(arguments))); 19 | }; 20 | } 21 | 22 | return bind; 23 | }); 24 | 25 | -------------------------------------------------------------------------------- /src/function/compose.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Returns a function that composes multiple functions, passing results to 5 | * each other. 6 | * @version 0.1.0 (2012/05/24) 7 | */ 8 | function compose() { 9 | var fns = arguments; 10 | return function(arg){ 11 | // only cares about the first argument since the chain can only 12 | // deal with a single return value anyway. It should start from 13 | // the last fn. 14 | var n = fns.length; 15 | while (n--) { 16 | arg = fns[n].call(this, arg); 17 | } 18 | return arg; 19 | }; 20 | } 21 | 22 | return compose; 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /src/function/curry.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | function slice(arr, offset){ 4 | return Array.prototype.slice.call(arr, offset || 0); 5 | } 6 | 7 | /** 8 | * Creates a partially applied function. 9 | * @version 0.1.0 (2012/11/16) 10 | */ 11 | function curry(fn, var_args){ 12 | var argsArr = slice(arguments, 1); //curried args 13 | return function(){ 14 | return fn.apply(this, argsArr.concat(slice(arguments))); 15 | }; 16 | } 17 | 18 | return curry; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/function/debounce.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Debounce callback execution 5 | * @version 0.1.0 (2012/11/27) 6 | */ 7 | function debounce(fn, threshold, isAsap){ 8 | var timeout, result; 9 | function debounced(){ 10 | var args = arguments, context = this; 11 | function delayed(){ 12 | if (! isAsap) { 13 | result = fn.apply(context, args); 14 | } 15 | timeout = null; 16 | } 17 | if (timeout) { 18 | clearTimeout(timeout); 19 | } else if (isAsap) { 20 | result = fn.apply(context, args); 21 | } 22 | timeout = setTimeout(delayed, threshold); 23 | return result; 24 | } 25 | return debounced; 26 | } 27 | 28 | return debounce; 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /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/function/series.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Returns a function that will execute a list of functions in sequence 5 | * passing the same arguments to each one. (useful for batch processing 6 | * items during a forEach loop) 7 | * @version 0.1.0 (2012/05/24) 8 | */ 9 | function series(){ 10 | var fns = arguments; 11 | return function(){ 12 | var i = 0, 13 | n = fns.length; 14 | while (i < n) { 15 | fns[i].apply(this, arguments); 16 | i += 1; 17 | } 18 | }; 19 | } 20 | 21 | return series; 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /src/function/throttle.js: -------------------------------------------------------------------------------- 1 | define(['../time/now'], function (now) { 2 | 3 | /** 4 | * @version 0.1.0 (2012/11/27) 5 | */ 6 | function throttle(fn, delay){ 7 | var context, timeout, result, args, 8 | cur, diff, prev = 0; 9 | function delayed(){ 10 | prev = now(); 11 | timeout = null; 12 | result = fn.apply(context, args); 13 | } 14 | function throttled(){ 15 | context = this; 16 | args = arguments; 17 | cur = now(); 18 | diff = delay - (cur - prev); 19 | if (diff <= 0) { 20 | clearTimeout(timeout); 21 | prev = cur; 22 | result = fn.apply(context, args); 23 | } else if (! timeout) { 24 | timeout = setTimeout(delayed, diff); 25 | } 26 | return result; 27 | } 28 | return throttled; 29 | } 30 | 31 | return throttle; 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'array' : require('./array'), 7 | 'collection' : require('./collection'), 8 | 'function' : require('./function'), 9 | 'lang' : require('./lang'), 10 | 'math' : require('./math'), 11 | 'number' : require('./number'), 12 | 'object' : require('./object'), 13 | 'queryString' : require('./queryString'), 14 | 'random' : require('./random'), 15 | 'string' : require('./string'), 16 | 'time' : require('./time') 17 | }; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/lang/createObject.js: -------------------------------------------------------------------------------- 1 | define(['../object/mixIn'], function(mixIn){ 2 | 3 | /** 4 | * Create Object using prototypal inheritance and setting custom properties. 5 | * - Mix between Douglas Crockford Prototypal Inheritance and the EcmaScript 5 `Object.create()` method. 6 | * @param {object} parent Parent Object. 7 | * @param {object} [props] Object properties. 8 | * @return {object} Created object. 9 | * @version 0.1.0 (2011/08/09) 10 | */ 11 | function createObject(parent, props){ 12 | function F(){} 13 | F.prototype = parent; 14 | return mixIn(new F(), props); 15 | 16 | } 17 | return createObject; 18 | }); 19 | 20 | -------------------------------------------------------------------------------- /src/lang/ctorApply.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | function F(){} 4 | 5 | /** 6 | * Do fn.apply on a constructor. 7 | * @version 0.1.0 (2011/11/24) 8 | */ 9 | function ctorApply(ctor, args) { 10 | F.prototype = ctor.prototype; 11 | var instance = new F(); 12 | ctor.apply(instance, args); 13 | return instance; 14 | } 15 | 16 | return ctorApply; 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /src/lang/defaults.js: -------------------------------------------------------------------------------- 1 | define(['./toArray', '../array/find'], function (toArray, find) { 2 | 3 | /** 4 | * Return first non void argument 5 | * @version 0.1.0 (2012/02/28) 6 | */ 7 | function defaults(var_args){ 8 | return find(toArray(arguments), nonVoid); 9 | } 10 | 11 | function nonVoid(val){ 12 | return val != null; 13 | } 14 | 15 | return defaults; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /src/lang/inheritPrototype.js: -------------------------------------------------------------------------------- 1 | define(['./createObject'], function(createObject){ 2 | 3 | /** 4 | * Inherit prototype from another Object. 5 | * - inspired by Nicholas Zackas Solution 6 | * @param {object} child Child object 7 | * @param {object} parent Parent Object 8 | * @version 0.1.0 (2011/02/18) 9 | */ 10 | function inheritPrototype(child, parent){ 11 | var p = createObject(parent.prototype); 12 | p.constructor = child; 13 | child.prototype = p; 14 | } 15 | 16 | return inheritPrototype; 17 | }); 18 | -------------------------------------------------------------------------------- /src/lang/isArguments.js: -------------------------------------------------------------------------------- 1 | define(['./isKind'], function (isKind) { 2 | 3 | /** 4 | * @version 0.2.0 (2011/12/05) 5 | */ 6 | var isArgs = isKind(arguments, 'Arguments')? 7 | function(val){ 8 | return isKind(val, 'Arguments'); 9 | } : 10 | function(val){ 11 | // Arguments is an Object on IE7 12 | return !!(val && Object.prototype.hasOwnProperty.call(val, 'callee')); 13 | }; 14 | 15 | return isArgs; 16 | }); 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /src/lang/isEmpty.js: -------------------------------------------------------------------------------- 1 | define(['../object/forOwn', './isArray'], function (forOwn, isArray) { 2 | 3 | function isEmpty(val){ 4 | if (val == null) { 5 | // typeof null == 'object' so we check it first 6 | return false; 7 | } else if ( typeof val === 'string' || isArray(val) ) { 8 | return !val.length; 9 | } else if ( typeof val === 'object' || typeof val === 'function' ) { 10 | var result = true; 11 | forOwn(val, function(){ 12 | result = false; 13 | return false; // break loop 14 | }); 15 | return result; 16 | } else { 17 | return false; 18 | } 19 | } 20 | 21 | return isEmpty; 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /src/lang/isFinite.js: -------------------------------------------------------------------------------- 1 | define(['./isNumber'], function (isNumber) { 2 | 3 | var global = this; 4 | 5 | /** 6 | * Check if value is finite 7 | * @version 0.1.2 (2012/12/09) 8 | */ 9 | function isFinite(val){ 10 | var is = false; 11 | if (typeof val === 'string' && val !== '') { 12 | is = global.isFinite( parseFloat(val) ); 13 | } else if (isNumber(val)){ 14 | // need to use isNumber because of Number constructor 15 | is = global.isFinite( val ); 16 | } 17 | return is; 18 | } 19 | 20 | return isFinite; 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/lang/isNaN.js: -------------------------------------------------------------------------------- 1 | define(['./isNumber'], function (isNumber) { 2 | 3 | /** 4 | * Check if value is NaN for realz 5 | * @version 0.1.2 (2012/11/28) 6 | */ 7 | function isNaN(val){ 8 | // based on the fact that NaN !== NaN 9 | // need to check if it's a number to avoid conflicts with host objects 10 | // also need to coerce ToNumber to avoid edge case `new Number(NaN)` 11 | return isNumber(val) && val != +val; 12 | } 13 | 14 | return isNaN; 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/lang/kindOf.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | var _rKind = /^\[object (.*)\]$/, 4 | _toString = Object.prototype.toString, 5 | UNDEF; 6 | 7 | /** 8 | * Gets the "kind" of value. (e.g. "String", "Number", etc) 9 | * @version 0.1.0 (2011/10/31) 10 | */ 11 | function kindOf(val) { 12 | if (val === null) { 13 | return 'Null'; 14 | } else if (val === UNDEF) { 15 | return 'Undefined'; 16 | } else { 17 | return _rKind.exec( _toString.call(val) )[1]; 18 | } 19 | } 20 | return kindOf; 21 | }); 22 | -------------------------------------------------------------------------------- /src/lang/toArray.js: -------------------------------------------------------------------------------- 1 | define(['./kindOf'], function (kindOf) { 2 | 3 | var _win = this; 4 | 5 | /** 6 | * Convert array-like object into array 7 | * @version 0.3.1 (2012/08/30) 8 | */ 9 | function toArray(val){ 10 | var ret = [], 11 | kind = kindOf(val), 12 | n; 13 | 14 | if (val != null) { 15 | if ( val.length == null || kind === 'String' || kind === 'Function' || kind === 'RegExp' || val === _win ) { 16 | //string, regexp, function have .length but user probably just want 17 | //to wrap value into an array.. 18 | ret[ret.length] = val; 19 | } else { 20 | //window returns true on isObject in IE7 and may have length 21 | //property. `typeof NodeList` returns `function` on Safari so 22 | //we can't use it (#58) 23 | n = val.length; 24 | while (n--) { 25 | ret[n] = val[n]; 26 | } 27 | } 28 | } 29 | return ret; 30 | } 31 | return toArray; 32 | }); 33 | -------------------------------------------------------------------------------- /src/math.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'ceil' : require('./math/ceil'), 7 | 'clamp' : require('./math/clamp'), 8 | 'countSteps' : require('./math/countSteps'), 9 | 'floor' : require('./math/floor'), 10 | 'inRange' : require('./math/inRange'), 11 | 'isNear' : require('./math/isNear'), 12 | 'lerp' : require('./math/lerp'), 13 | 'loop' : require('./math/loop'), 14 | 'map' : require('./math/map'), 15 | 'norm' : require('./math/norm'), 16 | 'round' : require('./math/round') 17 | }; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/number.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'MAX_INT' : require('./number/MAX_INT'), 7 | 'MAX_UINT' : require('./number/MAX_UINT'), 8 | 'MIN_INT' : require('./number/MIN_INT'), 9 | 'abbreviate' : require('./number/abbreviate'), 10 | 'currencyFormat' : require('./number/currencyFormat'), 11 | 'enforcePrecision' : require('./number/enforcePrecision'), 12 | 'pad' : require('./number/pad'), 13 | 'rol' : require('./number/rol'), 14 | 'ror' : require('./number/ror'), 15 | 'sign' : require('./number/sign'), 16 | 'toInt' : require('./number/toInt'), 17 | 'toUInt' : require('./number/toUInt'), 18 | 'toUInt31' : require('./number/toUInt31') 19 | }; 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/enforcePrecision.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Enforce a specific amount of decimal digits and also fix floating 4 | * point rounding issues. 5 | * @example `enforcePrecision(0.615, 2) -> 0.62`, `(0.615).toFixed(2) -> 6 | * 0.61` 7 | * @version 0.1.0 (2011/10/21) 8 | */ 9 | function enforcePrecision(val, nDecimalDigits){ 10 | var pow = Math.pow(10, nDecimalDigits); 11 | return +(Math.round(val * pow) / pow).toFixed(nDecimalDigits); 12 | } 13 | return enforcePrecision; 14 | }); 15 | -------------------------------------------------------------------------------- /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/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/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/number/toInt.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | 3 | /** 4 | * "Convert" value into an 32-bit integer. 5 | * Works like `Math.floor` if val > 0 and `Math.ceil` if val < 0. 6 | * IMPORTANT: val will wrap at 2^31 and -2^31. 7 | * Perf tests: http://jsperf.com/vs-vs-parseint-bitwise-operators/7 8 | * @version 0.1.0 (2011/10/21) 9 | */ 10 | function toInt(val){ 11 | return ~~val; 12 | } 13 | 14 | return toInt; 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /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/number/toUInt31.js: -------------------------------------------------------------------------------- 1 | define(['./MAX_INT'], function(MAX_INT){ 2 | 3 | /** 4 | * "Convert" value into an 31-bit unsigned integer (since 1 bit is used for sign). 5 | * IMPORTANT: value wil wrap at 2^31, if negative will return 0. 6 | * @version 0.3.0 (2011/11/25) 7 | */ 8 | function toUInt31(val){ 9 | return (val <= 0)? 0 : (val > MAX_INT? ~~(val % (MAX_INT + 1)) : ~~val); 10 | } 11 | 12 | return toUInt31; 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /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/object/deepFillIn.js: -------------------------------------------------------------------------------- 1 | define(['../array/forEach', './forOwn'], function (forEach, forOwn) { 2 | 3 | /** 4 | * Deeply copy missing properties in the obj from the defaults. 5 | * @version 0.1.0 (2012/12/19) 6 | */ 7 | function deepFillIn(obj, var_defaults){ 8 | forEach(Array.prototype.slice.call(arguments, 1), function(base){ 9 | forOwn(base, function(val, key){ 10 | var curVal = obj[key]; 11 | if (curVal == null) { 12 | obj[key] = val; 13 | } else if (typeof curVal === 'object' && typeof val === 'object') { 14 | deepFillIn(curVal, val); 15 | } 16 | }); 17 | }); 18 | return obj; 19 | } 20 | 21 | return deepFillIn; 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /src/object/every.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function(forOwn) { 2 | 3 | /** 4 | * Object every 5 | */ 6 | function every(obj, callback, thisObj) { 7 | var result = true; 8 | forOwn(obj, function(val, key) { 9 | if (callback.call(thisObj, val, key, obj) === false) { 10 | result = false; 11 | return false; // break 12 | } 13 | }); 14 | return result; 15 | } 16 | 17 | return every; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/object/fillIn.js: -------------------------------------------------------------------------------- 1 | define(['../array/forEach', './forOwn'], function (forEach, forOwn) { 2 | 3 | /** 4 | * Copy missing properties in the obj from the defaults. 5 | * @version 0.1.0 (2012/02/25) 6 | */ 7 | function fillIn(obj, var_defaults){ 8 | forEach(Array.prototype.slice.call(arguments, 1), function(base){ 9 | forOwn(base, function(val, key){ 10 | if (obj[key] == null) { 11 | obj[key] = val; 12 | } 13 | }); 14 | }); 15 | return obj; 16 | } 17 | 18 | return fillIn; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/object/filter.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function(forOwn) { 2 | 3 | /** 4 | * Creates a new object with all the properties where the callback returns 5 | * true. 6 | * @version 0.1.0 7 | */ 8 | function filterValues(obj, callback, thisObj) { 9 | var output = {}; 10 | forOwn(obj, function(value, key, obj) { 11 | if (callback.call(thisObj, value, key, obj)) { 12 | output[key] = value; 13 | } 14 | }); 15 | 16 | return output; 17 | } 18 | return filterValues; 19 | }); 20 | -------------------------------------------------------------------------------- /src/object/find.js: -------------------------------------------------------------------------------- 1 | define(['./some'], function(some) { 2 | 3 | /** 4 | * Returns first item that matches criteria 5 | */ 6 | function find(obj, callback, thisObj) { 7 | var result; 8 | some(obj, function(value, key, obj) { 9 | if (callback.call(thisObj, value, key, obj)) { 10 | result = value; 11 | return true; //break 12 | } 13 | }); 14 | return result; 15 | } 16 | 17 | return find; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/object/forOwn.js: -------------------------------------------------------------------------------- 1 | define(['./hasOwn', './forIn'], function (hasOwn, forIn) { 2 | 3 | /** 4 | * Similar to Array/forEach but works over object properties and fixes Don't 5 | * Enum bug on IE. 6 | * based on: http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation 7 | * @version 0.4.0 (2012/10/30) 8 | */ 9 | function forOwn(obj, fn, thisObj){ 10 | forIn(obj, function(val, key){ 11 | if (hasOwn(obj, key)) { 12 | return fn.call(thisObj, obj[key], key, obj); 13 | } 14 | }); 15 | } 16 | 17 | return forOwn; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/object/get.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * get "nested" object property 5 | * @version 0.1.0 (2012/01/30) 6 | */ 7 | function get(obj, prop){ 8 | var parts = prop.split('.'), 9 | last = parts.pop(); 10 | 11 | while (prop = parts.shift()) { 12 | obj = obj[prop]; 13 | if (typeof obj !== 'object') return; 14 | } 15 | 16 | return obj[last]; 17 | } 18 | 19 | return get; 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/object/keys.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function (forOwn) { 2 | 3 | /** 4 | * Get object keys 5 | * @version 0.3.0 (2011/12/17) 6 | */ 7 | var keys = Object.keys || function (obj) { 8 | var keys = []; 9 | forOwn(obj, function(val, key){ 10 | keys.push(key); 11 | }); 12 | return keys; 13 | }; 14 | 15 | return keys; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /src/object/map.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function(forOwn) { 2 | 3 | /** 4 | * Creates a new object where all the values are the result of calling 5 | * `callback`. 6 | * @version 0.1.0 7 | */ 8 | function mapValues(obj, callback, thisObj) { 9 | var output = {}; 10 | forOwn(obj, function(val, key, obj) { 11 | output[key] = callback.call(thisObj, val, key, obj); 12 | }); 13 | 14 | return output; 15 | } 16 | return mapValues; 17 | }); 18 | -------------------------------------------------------------------------------- /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/merge.js: -------------------------------------------------------------------------------- 1 | define(['./hasOwn', '../lang/clone', '../lang/isObject'], function (hasOwn, clone, isObject) { 2 | 3 | /** 4 | * Deep merge objects. 5 | * @version 0.2.0 (2012/07/13) 6 | */ 7 | function merge() { 8 | var i = 1, 9 | key, val, obj, target; 10 | 11 | // make sure we don't modify source element and it's properties 12 | // objects are passed by reference 13 | target = clone( arguments[0] ); 14 | 15 | while (obj = arguments[i++]) { 16 | for (key in obj) { 17 | if ( ! hasOwn(obj, key) ) { 18 | continue; 19 | } 20 | 21 | val = obj[key]; 22 | 23 | if ( isObject(val) && isObject(target[key]) ){ 24 | // inception, deep merge objects 25 | target[key] = merge(target[key], val); 26 | } else { 27 | // make sure arrays, regexp, date, objects are cloned 28 | target[key] = clone(val); 29 | } 30 | 31 | } 32 | } 33 | 34 | return target; 35 | } 36 | 37 | return merge; 38 | 39 | }); 40 | -------------------------------------------------------------------------------- /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/mixIn.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function(forOwn){ 2 | 3 | /** 4 | * Combine properties from all the objects into first one. 5 | * - This method affects target object in place, if you want to create a new Object pass an empty object as first param. 6 | * @param {object} target Target Object 7 | * @param {...object} objects Objects to be combined (0...n objects). 8 | * @return {object} Target Object. 9 | * @version 0.1.4 (2012/10/29) 10 | */ 11 | function mixIn(target, objects){ 12 | var i = 0, 13 | n = arguments.length, 14 | obj; 15 | while(++i < n){ 16 | obj = arguments[i]; 17 | if (obj != null) { 18 | forOwn(obj, copyProp, target); 19 | } 20 | } 21 | return target; 22 | } 23 | 24 | function copyProp(val, key){ 25 | this[key] = val; 26 | } 27 | 28 | return mixIn; 29 | }); 30 | -------------------------------------------------------------------------------- /src/object/namespace.js: -------------------------------------------------------------------------------- 1 | define(['../array/forEach'], function (forEach) { 2 | 3 | /** 4 | * Create nested object if non-existent 5 | * @version 0.1.0 (2012/01/30) 6 | */ 7 | function namespace(obj, path){ 8 | if (!path) return obj; 9 | forEach(path.split('.'), function(key){ 10 | if (!obj[key]) { 11 | obj[key] = {}; 12 | } 13 | obj = obj[key]; 14 | }); 15 | return obj; 16 | } 17 | 18 | return namespace; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/object/pick.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | 3 | /** 4 | * Return a copy of the object, filtered to only have values for the whitelisted keys. 5 | * @version 0.1.0 (2012/09/26) 6 | */ 7 | function pick(obj, var_keys){ 8 | var keys = typeof arguments[1] !== 'string'? arguments[1] : Array.prototype.slice.call(arguments, 1), 9 | out = {}, 10 | i = 0, key; 11 | while (key = keys[i++]) { 12 | out[key] = obj[key]; 13 | } 14 | return out; 15 | } 16 | 17 | return pick; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /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/object/reduce.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn', './size'], function(forOwn, size) { 2 | 3 | /** 4 | * Object reduce 5 | */ 6 | function reduce(obj, callback, memo, thisObj) { 7 | var initial = arguments.length > 2; 8 | 9 | if (!size(obj) && !initial) { 10 | throw new Error('reduce of empty object with no initial value'); 11 | } 12 | 13 | forOwn(obj, function(value, key, list) { 14 | if (!initial) { 15 | memo = value; 16 | initial = true; 17 | } 18 | else { 19 | memo = callback.call(thisObj, memo, value, key, list); 20 | } 21 | }); 22 | 23 | return memo; 24 | } 25 | 26 | return reduce; 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /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/set.js: -------------------------------------------------------------------------------- 1 | define(['./namespace'], function (namespace) { 2 | 3 | /** 4 | * set "nested" object property 5 | * @version 0.1.0 (2012/01/30) 6 | */ 7 | function set(obj, prop, val){ 8 | var parts = (/^(.+)\.(.+)$/).exec(prop); 9 | if (parts){ 10 | namespace(obj, parts[1])[parts[2]] = val; 11 | } else { 12 | obj[prop] = val; 13 | } 14 | } 15 | 16 | return set; 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /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/object/some.js: -------------------------------------------------------------------------------- 1 | define(['./forOwn'], function(forOwn) { 2 | 3 | /** 4 | * Object some 5 | * @version 0.2.0 (2012/11/16) 6 | */ 7 | function some(obj, callback, thisObj) { 8 | var result = false; 9 | forOwn(obj, function(val, key) { 10 | if (callback.call(thisObj, val, key, obj)) { 11 | result = true; 12 | return false; // break 13 | } 14 | }); 15 | return result; 16 | } 17 | 18 | return some; 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /src/object/unset.js: -------------------------------------------------------------------------------- 1 | define(['./has'], function (has) { 2 | 3 | /** 4 | * Unset object property. 5 | * @version 0.2.0 (2012/01/31) 6 | */ 7 | function unset(obj, prop){ 8 | if (has(obj, prop)) { 9 | var parts = prop.split('.'), 10 | last = parts.pop(); 11 | while (prop = parts.shift()) { 12 | obj = obj[prop]; 13 | } 14 | return (delete obj[last]); 15 | 16 | } else { 17 | // if property doesn't exist treat as deleted 18 | return true; 19 | } 20 | } 21 | 22 | return unset; 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/queryString.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'contains' : require('./queryString/contains'), 7 | 'decode' : require('./queryString/decode'), 8 | 'encode' : require('./queryString/encode'), 9 | 'getParam' : require('./queryString/getParam'), 10 | 'getQuery' : require('./queryString/getQuery'), 11 | 'parse' : require('./queryString/parse'), 12 | 'setParam' : require('./queryString/setParam') 13 | }; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/queryString/contains.js: -------------------------------------------------------------------------------- 1 | define(['./getQuery'], function (getQuery) { 2 | 3 | /** 4 | * Checks if query string contains parameter. 5 | * @version 0.2.0 (2012/09/26) 6 | */ 7 | function contains(url, paramName) { 8 | var regex = new RegExp('(\\?|&)'+ paramName +'=', 'g'); //matches `?param=` or `¶m=` 9 | return regex.test(getQuery(url)); 10 | } 11 | 12 | return contains; 13 | }); 14 | -------------------------------------------------------------------------------- /src/queryString/decode.js: -------------------------------------------------------------------------------- 1 | define(['../string/typecast', '../lang/isString'], function (typecast, isString) { 2 | 3 | /** 4 | * Decode query string into an object of keys => vals. 5 | * @version 0.3.0 (2012/09/26) 6 | */ 7 | function decode(queryStr, shouldTypecast) { 8 | var queryArr = (queryStr || '').replace('?', '').split('&'), 9 | n = queryArr.length, 10 | obj = {}, 11 | item, val; 12 | while (n--) { 13 | item = queryArr[n].split('='); 14 | val = shouldTypecast === false? item[1] : typecast(item[1]); 15 | obj[item[0]] = isString(val)? decodeURIComponent(val) : val; 16 | } 17 | return obj; 18 | } 19 | 20 | return decode; 21 | }); 22 | -------------------------------------------------------------------------------- /src/queryString/encode.js: -------------------------------------------------------------------------------- 1 | define(['../object/forOwn'], function (forOwn) { 2 | 3 | /** 4 | * Encode object into a query string. 5 | * @version 0.3.0 (2012/09/26) 6 | */ 7 | function encode(obj){ 8 | var query = []; 9 | forOwn(obj, function(val, key){ 10 | query.push( key +'='+ encodeURIComponent(val) ); 11 | }); 12 | return (query.length)? '?'+ query.join('&') : ''; 13 | } 14 | 15 | return encode; 16 | }); 17 | -------------------------------------------------------------------------------- /src/queryString/getParam.js: -------------------------------------------------------------------------------- 1 | define(['../string/typecast', './getQuery'], function (typecast, getQuery) { 2 | 3 | /** 4 | * Get query parameter value. 5 | * @version 0.2.0 (2012/09/26) 6 | */ 7 | function getParam(url, param, shouldTypecast){ 8 | var regexp = new RegExp('(\\?|&)'+ param + '=([^&]*)'), //matches `?param=value` or `¶m=value`, value = $2 9 | result = regexp.exec( getQuery(url) ), 10 | val = (result && result[2])? result[2] : null; 11 | return shouldTypecast === false? val : typecast(val); 12 | } 13 | 14 | return getParam; 15 | }); 16 | -------------------------------------------------------------------------------- /src/queryString/getQuery.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Gets full query as string with all special chars decoded. 5 | * @version 0.2.0 (2012/09/26) 6 | */ 7 | function getQuery(url) { 8 | url = url.replace(/#.*/, ''); //removes hash (to avoid getting hash query) 9 | var queryString = /\?[a-zA-Z0-9\=\&\%\$\-\_\.\+\!\*\'\(\)\,]+/.exec(url); //valid chars according to: http://www.ietf.org/rfc/rfc1738.txt 10 | return (queryString)? decodeURIComponent(queryString[0]) : ''; 11 | } 12 | 13 | return getQuery; 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/queryString/setParam.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Set query string parameter value 5 | * @version 0.1.0 (2012/10/11) 6 | */ 7 | function setParam(url, paramName, value){ 8 | url = url || ''; 9 | 10 | var re = new RegExp('(\\?|&)'+ paramName +'=[^&]*' ); 11 | var param = paramName +'='+ encodeURIComponent( value ); 12 | 13 | if ( re.test(url) ) { 14 | return url.replace(re, '$1'+ param); 15 | } else { 16 | if (url.indexOf('?') === -1) { 17 | url += '?'; 18 | } 19 | if (url.indexOf('=') !== -1) { 20 | url += '&'; 21 | } 22 | return url + param; 23 | } 24 | 25 | } 26 | 27 | return setParam; 28 | 29 | }); 30 | -------------------------------------------------------------------------------- /src/random.js: -------------------------------------------------------------------------------- 1 | define(function(require){ 2 | 3 | //automatically generated, do not edit! 4 | //run `node build` instead 5 | return { 6 | 'choice' : require('./random/choice'), 7 | 'guid' : require('./random/guid'), 8 | 'rand' : require('./random/rand'), 9 | 'randBit' : require('./random/randBit'), 10 | 'randHex' : require('./random/randHex'), 11 | 'randInt' : require('./random/randInt'), 12 | 'randSign' : require('./random/randSign'), 13 | 'random' : require('./random/random') 14 | }; 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /src/random/choice.js: -------------------------------------------------------------------------------- 1 | define(['./randInt', '../lang/isArray'], function (randInt, isArray) { 2 | 3 | /** 4 | * Returns a random element from the supplied arguments 5 | * or from the array (if single argument is an array). 6 | * @version 0.1.1 (2011/12/08) 7 | */ 8 | function choice(items) { 9 | var target = (arguments.length === 1 && isArray(items))? items : arguments; 10 | return target[ randInt(0, target.length - 1) ]; 11 | } 12 | 13 | return choice; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /src/random/guid.js: -------------------------------------------------------------------------------- 1 | define(['./randHex', './choice'], function (randHex, choice) { 2 | 3 | /** 4 | * Returns pseudo-random guid (UUID v4) 5 | * IMPORTANT: it's not totally "safe" since randHex/choice uses Math.random 6 | * by default and sequences can be predicted in some cases. See the 7 | * "random/random" documentation for more info about it and how to replace 8 | * the default PRNG. 9 | * @version 0.1.1 (2012/11/29) 10 | */ 11 | function guid() { 12 | return ( 13 | randHex(8)+'-'+ 14 | randHex(4)+'-'+ 15 | // v4 UUID always contain "4" at this position to specify it was 16 | // randomly generated 17 | '4' + randHex(3) +'-'+ 18 | // v4 UUID always contain chars [a,b,8,9] at this position 19 | choice(8, 9, 'a', 'b') + randHex(3)+'-'+ 20 | randHex(12) 21 | ); 22 | } 23 | return guid; 24 | }); 25 | -------------------------------------------------------------------------------- /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/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/random/randHex.js: -------------------------------------------------------------------------------- 1 | define(['./choice'], function (choice) { 2 | 3 | var _chars = '0123456789abcdef'.split(''); 4 | 5 | /** 6 | * Returns a random hexadecimal string 7 | */ 8 | function randHex(size){ 9 | size = size && size > 0? size : 6; 10 | var str = ''; 11 | while (size--) { 12 | str += choice(_chars); 13 | } 14 | return str; 15 | } 16 | 17 | return randHex; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/random/randInt.js: -------------------------------------------------------------------------------- 1 | define(['../number/MIN_INT', '../number/MAX_INT', './rand'], function(MIN_INT, MAX_INT, rand){ 2 | 3 | /** 4 | * Gets random integer inside range or snap to min/max values. 5 | * @version 0.6.0 (2012/04/24) 6 | */ 7 | function randInt(min, max){ 8 | min = min == null? MIN_INT : ~~min; 9 | max = max == null? MAX_INT : ~~max; 10 | // can't be max + 0.5 otherwise it will round up if `rand` 11 | // returns `max` causing it to overflow range. 12 | // -0.5 and + 0.49 are required to avoid bias caused by rounding 13 | return Math.round( rand(min - 0.5, max + 0.499999999999) ); 14 | } 15 | 16 | return randInt; 17 | }); 18 | -------------------------------------------------------------------------------- /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/random/random.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Just a wrapper to Math.random. No methods inside amd-utils should call 5 | * Math.random() directly so we can inject the pseudo-random number 6 | * generator if needed (ie. in case we need a seeded random or a better 7 | * algorithm than the native one) 8 | * @version 0.1.0 (2012/11/29) 9 | */ 10 | function random(){ 11 | return random.get(); 12 | } 13 | 14 | // we expose the method so it can be swapped if needed 15 | random.get = Math.random; 16 | 17 | return random; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/string/camelCase.js: -------------------------------------------------------------------------------- 1 | define(['./replaceAccents', './removeNonWord', './upperCase', './lowerCase'], function(replaceAccents, removeNonWord, upperCase, lowerCase){ 2 | /** 3 | * Convert string to camelCase text. 4 | * - ported from Miller Medeiros Eclipse Monkey Scripts 5 | * @example camelCase('my -- awesome-text') -> 'myAwesomeText'; 6 | * @param {string} str 7 | * @return {string} 8 | * @version 0.2.0 (2011/08/09) 9 | */ 10 | function camelCase(str){ 11 | str = replaceAccents(str); 12 | str = removeNonWord(str) 13 | .replace(/\-/g, ' ') //convert all hyphens to spaces 14 | .replace(/\s[a-z]/g, upperCase) //convert first char of each word to UPPERCASE 15 | .replace(/\s+/g, '') //remove spaces 16 | .replace(/^[A-Z]/g, lowerCase); //convert first char to lowercase 17 | return str; 18 | } 19 | return camelCase; 20 | }); 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/string/endsWith.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | /** 3 | * Checks if string ends with specified suffix. 4 | * @example endsWith('lorem ipsum', 'ipsum') -> true 5 | * @example endsWith('lorem ipsum', 'lorem') -> false 6 | * @param {string} str 7 | * @param {string} suffix 8 | * @return {bool} 9 | * @version 0.1.0 (2012/03/01) 10 | */ 11 | function endsWith(str, suffix) { 12 | str = (str || ''); 13 | suffix = (suffix || ''); 14 | return str.indexOf(suffix, str.length - suffix.length) !== -1; 15 | } 16 | return endsWith; 17 | }); 18 | -------------------------------------------------------------------------------- /src/string/escapeHtml.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Escapes a string for insertion into HTML. 5 | * @version 0.1.0 (2012/05/24) 6 | */ 7 | function escapeHtml(str){ 8 | str = (str || '') 9 | .replace(/&/g, '&') 10 | .replace(//g, '>') 12 | .replace(/'/g, ''') 13 | .replace(/"/g, '"'); 14 | return str; 15 | } 16 | 17 | return escapeHtml; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /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/escapeUnicode.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Escape string into unicode sequences 5 | * @version 0.1.0 (2012/12/19) 6 | */ 7 | function escapeUnicode(str, shouldEscapePrintable){ 8 | if (!str) return ''; 9 | return str.replace(/[\s\S]/g, function(ch){ 10 | // skip printable ASCII chars if we should not escape them 11 | if (!shouldEscapePrintable && (/[\x20-\x7E]/).test(ch)) { 12 | return ch; 13 | } 14 | // we use "000" and slice(-4) for brevity, need to pad zeros, 15 | // unicode escape always have 4 chars after "\u" 16 | return '\\u'+ ('000'+ ch.charCodeAt(0).toString(16)).slice(-4); 17 | }); 18 | } 19 | 20 | return escapeUnicode; 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /src/string/hyphenate.js: -------------------------------------------------------------------------------- 1 | define(['./slugify', './unCamelCase'], function(slugify, unCamelCase){ 2 | /** 3 | * Replaces spaces with hyphens, split camelCase text, remove non-word chars, remove accents and convert to lower case. 4 | * @example hyphenate('loremIpsum dolor spéçïãl chârs') -> 'lorem-ipsum-dolor-special-chars' 5 | * @version 0.2.0 (2012/08/17) 6 | */ 7 | function hyphenate(str){ 8 | str = unCamelCase(str); 9 | return slugify(str, "-"); 10 | } 11 | return hyphenate; 12 | }); 13 | -------------------------------------------------------------------------------- /src/string/interpolate.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | var stache = /\{\{(\w+)\}\}/g; //mustache-like 4 | 5 | /** 6 | * String interpolation 7 | * @version 0.1.0 (2012/03/05) 8 | */ 9 | function interpolate(template, replacements, syntax){ 10 | var replaceFn = function(match, prop){ 11 | return (prop in replacements)? replacements[prop] : ''; 12 | }; 13 | return template.replace(syntax || stache, replaceFn); 14 | } 15 | 16 | return interpolate; 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /src/string/makePath.js: -------------------------------------------------------------------------------- 1 | define(['../array/join'], function(join){ 2 | 3 | /** 4 | * Group arguments as path segments, if any of the args is `null` or an 5 | * empty string it will be ignored from resulting path. 6 | * @version 0.3.0 (2012/08/24) 7 | */ 8 | function makePath(var_args){ 9 | var result = join(Array.prototype.slice.call(arguments), '/'); 10 | return result.replace(/\/{2,}/g, '/'); 11 | } 12 | 13 | return makePath; 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/normalizeLineBreaks.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Convert line-breaks from DOS/MAC to a single standard (UNIX by default) 5 | * @version 0.1.0 (2011/12/17) 6 | */ 7 | function normalizeLineBreaks(str, lineEnd) { 8 | lineEnd = lineEnd || '\n'; 9 | return str 10 | .replace(/\r\n/g, lineEnd) // DOS 11 | .replace(/\r/g, lineEnd) // Mac 12 | .replace(/\n/g, lineEnd); // Unix 13 | } 14 | 15 | return normalizeLineBreaks; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /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/string/properCase.js: -------------------------------------------------------------------------------- 1 | define(['./lowerCase', './upperCase'], function(lowerCase, upperCase){ 2 | /** 3 | * UPPERCASE first char of each word. 4 | * - ported from Miller Medeiros Eclipse Monkey Scripts 5 | * @example properCase('loRem iPSum') -> 'Lorem Ipsum' 6 | * @param {string} str 7 | * @return {string} 8 | * @version 0.1.0 (2011/07/20) 9 | */ 10 | function properCase(str){ 11 | return lowerCase(str).replace(/^\w|\s\w/g, upperCase); //replace first char of each word to UPPERCASE 12 | } 13 | return properCase; 14 | }); 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/sentenceCase.js: -------------------------------------------------------------------------------- 1 | define(['./lowerCase', './upperCase'], function(lowerCase, upperCase){ 2 | /** 3 | * UPPERCASE first char of each sentence and lowercase other chars. 4 | * - ported from Miller Medeiros Eclipse Monkey Scripts 5 | * @example sentenceCase('Lorem IpSum DoLOr. maeCeNnas Ullamcor.') -> 'Lorem ipsum dolor. Maecennas ullamcor.' 6 | * @param {string} str 7 | * @return {string} 8 | * @version 0.1.0 (2011/07/20) 9 | */ 10 | function sentenceCase(str){ 11 | return lowerCase(str).replace(/(^\w)|\.\s+(\w)/gm, upperCase); //replace first char of each sentence (new line or after '.\s+') to UPPERCASE 12 | } 13 | return sentenceCase; 14 | }); 15 | -------------------------------------------------------------------------------- /src/string/slugify.js: -------------------------------------------------------------------------------- 1 | define(['./replaceAccents', './removeNonWord', './trim'], function(replaceAccents, removeNonWord, trim){ 2 | /** 3 | * Convert to lower case, remove accents, remove non-word chars and 4 | * replace spaces with the specified delimeter. 5 | * Does not split camelCase text. 6 | * - ported from Miller Medeiros Eclipse Monkey Scripts 7 | * @example slugify('loremIpsum dolor spéçïãl chârs', '_') -> 'loremipsum_dolor_special_chars' 8 | * @param {string} str 9 | * @param {string} [delimeter="-"] 10 | * @return {string} 11 | * @version 0.2.0 (2012/08/17) 12 | */ 13 | function slugify(str, delimeter){ 14 | if (delimeter == null) { 15 | delimeter = "-"; 16 | } 17 | str = replaceAccents(str); 18 | str = removeNonWord(str); 19 | str = trim(str) //should come after removeNonWord 20 | .replace(/ +/g, delimeter) //replace spaces with delimeter 21 | .toLowerCase(); 22 | return str; 23 | } 24 | return slugify; 25 | }); 26 | -------------------------------------------------------------------------------- /src/string/startsWith.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | /** 3 | * Checks if string starts with specified prefix. 4 | * @example startsWith('lorem ipsum', 'ipsum') -> false 5 | * @example startsWith('lorem ipsum', 'lorem') -> true 6 | * @param {string} str 7 | * @param {string} prefix 8 | * @return {bool} 9 | * @version 0.1.0 (2012/03/01) 10 | */ 11 | function startsWith(str, prefix) { 12 | str = (str || ''); 13 | prefix = (prefix || ''); 14 | return str.indexOf(prefix) === 0; 15 | } 16 | return startsWith; 17 | }); 18 | -------------------------------------------------------------------------------- /src/string/stripHtmlTags.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Remove HTML tags from string. 4 | * @example stripHtmlTags('

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/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 | -------------------------------------------------------------------------------- /src/string/truncate.js: -------------------------------------------------------------------------------- 1 | define(['./trim'], function(trim){ 2 | /** 3 | * Limit number of chars. 4 | * @version 0.3.0 (2011/10/31) 5 | */ 6 | function truncate(str, maxChars, append, onlyFullWords){ 7 | append = append || '...'; 8 | maxChars = onlyFullWords? maxChars + 1 : maxChars; 9 | 10 | str = trim(str); 11 | if(str.length <= maxChars){ 12 | return str; 13 | } 14 | str = str.substr(0, maxChars - append.length); 15 | //crop at last space or remove trailing whitespace 16 | str = onlyFullWords? str.substr(0, str.lastIndexOf(' ')) : trim(str); 17 | return str + append; 18 | } 19 | return truncate; 20 | }); 21 | -------------------------------------------------------------------------------- /src/string/typecast.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | var UNDEF; 4 | 5 | /** 6 | * Parses string and convert it into a native value. 7 | * @version 0.2.0 (2011/10/30) 8 | */ 9 | function typecast(val) { 10 | var r; 11 | if ( val === null || val === 'null' ) { 12 | r = null; 13 | } else if ( val === 'true' ) { 14 | r = true; 15 | } else if ( val === 'false' ) { 16 | r = false; 17 | } else if ( val === UNDEF || val === 'undefined' ) { 18 | r = UNDEF; 19 | } else if ( val === '' || isNaN(val) ) { 20 | //isNaN('') returns false 21 | r = val; 22 | } else { 23 | //parseFloat(null || '') returns NaN 24 | r = parseFloat(val); 25 | } 26 | return r; 27 | } 28 | 29 | return typecast; 30 | }); 31 | -------------------------------------------------------------------------------- /src/string/unCamelCase.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | /** 3 | * Add space between camelCase text. 4 | * @example unCamelCase('loremIpsumDolor') -> 'lorem ipsum dolor' 5 | * @param {string} str 6 | * @return {string} 7 | * @version 0.1.0 (2011/08/09) 8 | */ 9 | function unCamelCase(str){ 10 | return (str || '').replace(/([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g, '$1 $2').toLowerCase(); //add space between camelCase text 11 | } 12 | return unCamelCase; 13 | }); 14 | -------------------------------------------------------------------------------- /src/string/underscore.js: -------------------------------------------------------------------------------- 1 | define(['./slugify', './unCamelCase'], function(slugify, unCamelCase){ 2 | /** 3 | * Replaces spaces with underscores, split camelCase text, remove non-word chars, remove accents and convert to lower case. 4 | * @version 0.1.0 5 | */ 6 | function underscore(str){ 7 | str = unCamelCase(str); 8 | return slugify(str, "_"); 9 | } 10 | return underscore; 11 | }); 12 | -------------------------------------------------------------------------------- /src/string/unescapeHtml.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Unescapes HTML special chars 5 | * @version 0.1.0 (2012/05/24) 6 | */ 7 | function unescapeHtml(str){ 8 | str = (str || '') 9 | .replace(/&/g , '&') 10 | .replace(/</g , '<') 11 | .replace(/>/g , '>') 12 | .replace(/'/g , "'") 13 | .replace(/"/g, '"'); 14 | return str; 15 | } 16 | 17 | return unescapeHtml; 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /src/string/unescapeUnicode.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | 3 | /** 4 | * Unescape unicode char sequences 5 | * @version 0.1.0 (2012/12/19) 6 | */ 7 | function unescapeUnicode(str){ 8 | if (!str) return ''; 9 | return str.replace(/\\u[0-9a-f]{4}/g, function(ch){ 10 | var code = parseInt(ch.slice(2), 16); 11 | return String.fromCharCode(code); 12 | }); 13 | } 14 | 15 | return unescapeUnicode; 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /src/time/parseMs.js: -------------------------------------------------------------------------------- 1 | define(['../math/countSteps'], function(countSteps){ 2 | 3 | /** 4 | * Parse timestamp into an object. 5 | * @version 0.1.0 (2011/12/08) 6 | */ 7 | function parseMs(ms){ 8 | return { 9 | milliseconds : countSteps(ms, 1, 1000), 10 | seconds : countSteps(ms, 1000, 60), 11 | minutes : countSteps(ms, 60000, 60), 12 | hours : countSteps(ms, 3600000, 24), 13 | days : countSteps(ms, 86400000) 14 | }; 15 | } 16 | 17 | return parseMs; 18 | }); 19 | -------------------------------------------------------------------------------- /src/time/toTimeString.js: -------------------------------------------------------------------------------- 1 | define(['../math/countSteps', '../number/pad'], function(countSteps, pad){ 2 | 3 | var HOUR = 3600000, 4 | MINUTE = 60000, 5 | SECOND = 1000; 6 | 7 | /** 8 | * Format timestamp into a time string. 9 | * @version 0.3.0 (2012/08/08) 10 | */ 11 | function toTimeString(ms){ 12 | var h = ms < HOUR ? 0 : countSteps(ms, HOUR), 13 | m = ms < MINUTE ? 0 : countSteps(ms, MINUTE, 60), 14 | s = ms < SECOND ? 0 : countSteps(ms, SECOND, 60), 15 | str = ''; 16 | 17 | str += h? h + ':' : ''; 18 | str += pad(m, 2) + ':'; 19 | str += pad(s, 2); 20 | 21 | return str; 22 | } 23 | return toTimeString; 24 | }); 25 | -------------------------------------------------------------------------------- /tests/lib/jasmine/MIT.LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2011 Pivotal Labs 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tests/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | amd-utils | Jasmine Test Runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/spec/array/spec-append.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/append'], function (append) { 2 | 3 | describe('array/append()', function(){ 4 | 5 | it('should append every item of the second array to the end of first array', function(){ 6 | 7 | var arr = [1, 2, 3], 8 | arr2 = [3, 4, 5], 9 | result; 10 | 11 | result = append(arr, arr2); 12 | expect(arr).toBe( result ); 13 | expect(arr).toEqual([1, 2, 3, 3, 4, 5]); 14 | }); 15 | 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /tests/spec/array/spec-combine.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/combine'], function (append) { 2 | 3 | describe('array/combine()', function(){ 4 | 5 | it('should append every item of the second array to the end of first array, ignoring duplicates', function(){ 6 | 7 | var arr = [1, 2, 3], 8 | arr2 = [3, 4, 5], 9 | result; 10 | 11 | result = append(arr, arr2); 12 | expect(arr).toBe( result ); 13 | expect(arr).toEqual([1, 2, 3, 4, 5]); 14 | }); 15 | 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /tests/spec/array/spec-compact.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/compact'], function (compact) { 2 | 3 | describe('array/compact()', function () { 4 | 5 | it('should remove null and undefined items', function () { 6 | 7 | var arr = [1, 2, null, false, '', 'foo', undefined]; 8 | arr[10] = 'bar'; 9 | 10 | expect( compact(arr).length ).toBe( 6 ); 11 | expect( compact(arr) ).toEqual( [1, 2, false, '', 'foo', 'bar'] ); 12 | }); 13 | 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /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/array/spec-difference.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/difference'], function (difference) { 2 | 3 | describe('array/difference()', function () { 4 | 5 | it('should keep only items that are present on 1st array but not present on other arrays', function () { 6 | 7 | var a = ['a', 'b', 1], 8 | b = ['c', 1], 9 | c = [1, 2, 3]; 10 | 11 | expect( difference(a, b, c) ).toEqual( ['a', 'b'] ); 12 | 13 | }); 14 | 15 | it('should remove duplicates', function () { 16 | 17 | var a = ['a', 'b', 1, 'b'], 18 | b = ['c', 'a', 1], 19 | c = [1, 2, 3, 'a']; 20 | 21 | expect( difference(a, b, c) ).toEqual( ['b'] ); 22 | 23 | }); 24 | 25 | it('should return an empty array if items are present on other arrays', function () { 26 | 27 | var a = ['b', 'a', 'c', 1, 2, 3], 28 | b = ['c', 'a'], 29 | c = [1, 'b', 2, 3, 'a']; 30 | 31 | expect( difference(a, b, c) ).toEqual( [] ); 32 | 33 | }); 34 | 35 | }); 36 | 37 | }); 38 | -------------------------------------------------------------------------------- /tests/spec/array/spec-find.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/find'], function (find) { 2 | 3 | describe('array/find', function () { 4 | 5 | it('should return first match', function () { 6 | 7 | var obj = {a : 'b'}, 8 | arr = [123, 'foo', 'bar', obj]; 9 | 10 | expect( find(arr, function(val){ return val === 123; }) ).toEqual( 123 ); 11 | expect( find(arr, function(val){ return typeof val === 'string'; }) ).toEqual( 'foo' ); 12 | expect( find(arr, function(val){ return val.a === 'b'; }) ).toEqual( obj ); 13 | 14 | }); 15 | 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/spec/array/spec-flatten.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/flatten'], function (flatten) { 2 | 3 | describe('array/flatten()', function () { 4 | 5 | it('should recursively flatten the array', function () { 6 | var arr = [1, [2], [3, [4], 5]], 7 | result; 8 | 9 | result = flatten(arr); 10 | expect(result).toEqual([1, 2, 3, 4, 5]); 11 | }); 12 | 13 | it('should only flatten one layer if shallow', function () { 14 | var arr = [1, [2], [3, [4, 5]]], 15 | result; 16 | 17 | result = flatten(arr, true); 18 | expect(result).toEqual([1, 2, 3, [4, 5]]); 19 | }); 20 | 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /tests/spec/array/spec-insert.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/insert'], function (insert) { 2 | 3 | describe('array/insert()', function(){ 4 | 5 | it('should push item if not present and return the length', function(){ 6 | 7 | var arr = [1, 2, 3]; 8 | 9 | expect( insert(arr, 3) ).toBe( 3 ); 10 | expect( arr.length ).toBe( 3 ); 11 | expect( arr ).toEqual( [1,2,3] ); 12 | 13 | expect( insert(arr, 4) ).toBe( 4 ); 14 | expect( arr.length ).toBe( 4 ); 15 | expect( arr ).toEqual( [1,2,3,4] ); 16 | }); 17 | 18 | it('should accept multiple items', function () { 19 | 20 | var arr = ['a', 'b']; 21 | 22 | expect( insert(arr, 'a', 'b') ).toBe( 2 ); 23 | expect( arr.length ).toBe( 2 ); 24 | expect( arr ).toEqual( ['a', 'b'] ); 25 | 26 | expect( insert(arr, 1, 2, 'b', 3, 'a', 'c') ).toBe( 6 ); 27 | expect( arr.length ).toBe( 6 ); 28 | expect( arr ).toEqual( ['a', 'b', 1, 2, 3, 'c'] ); 29 | 30 | }); 31 | 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /tests/spec/array/spec-intersection.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/intersection'], function (intersection) { 2 | 3 | describe('array/intersection()', function () { 4 | 5 | it('should keep only items that are present on all arrays', function () { 6 | 7 | var a = ['a', 'b', 1], 8 | b = ['c', 1], 9 | c = [1, 2, 3]; 10 | 11 | expect( intersection(a, b, c) ).toEqual( [1] ); 12 | 13 | }); 14 | 15 | it('should remove duplicates', function () { 16 | 17 | var a = ['a', 'b', 1], 18 | b = ['c', 'a', 1], 19 | c = [1, 'b', 2, 3, 'a']; 20 | 21 | expect( intersection(a, b, c) ).toEqual( ['a', 1] ); 22 | 23 | }); 24 | 25 | it('should return an empty array if no intersection', function () { 26 | 27 | var a = ['b'], 28 | b = ['c', 'a'], 29 | c = [1, 'b', 2, 3, 'a']; 30 | 31 | expect( intersection(a, b, c) ).toEqual( [] ); 32 | 33 | }); 34 | 35 | }); 36 | 37 | }); 38 | -------------------------------------------------------------------------------- /tests/spec/array/spec-join.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/join'], function(join) { 2 | 3 | describe('array/join()', function() { 4 | 5 | it('should join strings in the array', function() { 6 | var arr = ['foo', 'bar']; 7 | expect( join(arr, ', ') ).toEqual('foo, bar'); 8 | }); 9 | 10 | it('should convert items to string', function() { 11 | var testObj = { toString: function() { return 'test'; } }, 12 | arr = [0, 1, 2, testObj]; 13 | expect( join(arr, '+') ).toEqual('0+1+2+test'); 14 | }); 15 | 16 | it('should default to blank separator', function() { 17 | var arr = ['foo', 'bar']; 18 | expect( join(arr) ).toEqual('foobar'); 19 | }); 20 | 21 | it('should exclude null and empty values', function() { 22 | var arr = [null, 'foo', '', 'bar', undefined, 'baz']; 23 | expect( join(arr, '-') ).toEqual('foo-bar-baz'); 24 | }); 25 | 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /tests/spec/array/spec-max.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/max'], function (max) { 2 | 3 | describe('array/max()', function () { 4 | 5 | it('should return maximum value', function () { 6 | 7 | expect( max([100, 2, 1, 3, 200]) ).toBe(200); 8 | expect( max([100, 200]) ).toBe(200); 9 | expect( max([-10, 1, 0]) ).toBe(1); 10 | 11 | }); 12 | 13 | it('should return Infinity if empty', function () { 14 | 15 | expect( max([]) ).toBe(Infinity); 16 | 17 | }); 18 | 19 | it('should allow custom iterator', function () { 20 | 21 | expect( max([1,2,3], function(val){ return -val; }) ).toBe(1); 22 | 23 | expect( max(['foo', 'lorem', 'amet'], function(val){ 24 | return val.length; 25 | }) ).toBe('lorem'); 26 | 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/array/spec-min.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/min'], function (min) { 2 | 3 | describe('array/min()', function () { 4 | 5 | it('should return minimum value', function () { 6 | 7 | expect( min([100, 2, 1, 3, 200]) ).toBe(1); 8 | expect( min([100, 200]) ).toBe(100); 9 | expect( min([-10, 1, 0]) ).toBe(-10); 10 | 11 | }); 12 | 13 | it('should return -Infinity if empty', function () { 14 | 15 | expect( min([]) ).toBe(-Infinity); 16 | 17 | }); 18 | 19 | it('should allow custom iterator', function () { 20 | 21 | expect( min([1,2,3], function(val){ return -val; }) ).toBe(3); 22 | 23 | expect( min(['foo', 'lorem', 'amet'], function(val){ 24 | return val.length; 25 | }) ).toBe('foo'); 26 | 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/array/spec-pick.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/pick'], function (pick) { 2 | 3 | describe('array/pick()', function () { 4 | 5 | it('should remove a random item from the array and return it', function () { 6 | var arr = [1, 2, 3, 4, 5, 6], 7 | copy = arr.concat(); 8 | 9 | var a = pick(arr); 10 | 11 | expect( copy ).toContain( a ); 12 | expect( arr ).not.toContain( a ); 13 | expect( arr.length ).toBe( copy.length - 1 ); 14 | }); 15 | 16 | it('should return undefined if empty array', function () { 17 | var arr = [], 18 | copy = arr.concat(); 19 | 20 | var a = pick(arr); 21 | 22 | expect( a ).toBeUndefined(); 23 | expect( arr ).not.toContain( a ); 24 | expect( arr.length ).toBe( 0 ); 25 | }); 26 | 27 | }); 28 | 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /tests/spec/array/spec-pluck.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/pluck'], function (pluck) { 2 | 3 | describe('array/pluck()', function () { 4 | 5 | it('should extract properties from items', function () { 6 | 7 | var users = [ 8 | { 9 | name : 'John', 10 | age : 21 11 | }, 12 | { 13 | name : 'Mary', 14 | age : 25 15 | }, 16 | { 17 | name : 'Jane', 18 | age : 27 19 | } 20 | ]; 21 | 22 | expect( pluck(users, 'name') ).toEqual( ['John', 'Mary', 'Jane'] ); 23 | expect( pluck(users, 'age') ).toEqual( [21, 25, 27] ); 24 | }); 25 | 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /tests/spec/array/spec-removeAll.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/removeAll'], function (removeAll) { 2 | 3 | describe('array/removeAll()', function(){ 4 | 5 | it('should work in normal array', function(){ 6 | var arr = [1, 'a', 2, 'b', 'a', 'a']; 7 | 8 | expect( arr.length ).toEqual( 6 ); 9 | expect( arr[1] ).toBe( 'a' ); 10 | removeAll(arr, 'a'); 11 | expect( arr[1] ).toBe( 2 ); 12 | expect( arr.length ).toEqual( 3 ); 13 | }); 14 | 15 | it('should work in sparse array', function(){ 16 | var arr = []; 17 | arr[1] = 1; 18 | arr[3] = 'a'; 19 | arr[6] = 2; 20 | arr[8] = 'b'; 21 | arr[9] = 'a'; 22 | arr[15] = 'a'; 23 | 24 | expect( arr.length ).toEqual( 16 ); 25 | expect( arr[3] ).toBe( 'a' ); 26 | removeAll(arr, 'a'); 27 | expect( arr[3] ).toBeUndefined(); 28 | expect( arr.length ).toEqual( 13 ); 29 | }); 30 | 31 | }); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /tests/spec/array/spec-shuffle.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/shuffle'], function (shuffle) { 2 | 3 | describe('array/shuffle()', function () { 4 | 5 | it('should return new array with shuffled items', function () { 6 | 7 | var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; 8 | var arr2 = arr.slice(); 9 | var result = shuffle(arr); 10 | 11 | expect( result ).not.toBe( arr ); 12 | expect( result ).not.toEqual( arr2 ); 13 | 14 | }); 15 | 16 | }); 17 | 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/array/spec-split.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/split'], function(split) { 2 | 3 | describe('array/split()', function() { 4 | 5 | it('should split array into segments', function() { 6 | var arr = [1, 2, 3, 4, 5, 6]; 7 | expect( split(arr, 3) ).toEqual([ [1, 2], [3, 4], [5, 6] ]); 8 | }); 9 | 10 | it('should default to 2 segments', function() { 11 | var arr = [1, 2, 3, 4, 5, 6]; 12 | expect( split(arr) ).toEqual([ [1, 2, 3], [4, 5, 6] ]); 13 | }); 14 | 15 | it('should put remaining items on first segments if not even split', function() { 16 | var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; 17 | expect( split(arr, 3) ).toEqual( 18 | [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h'] ]); 19 | }); 20 | 21 | it('should return empty array when input is empty', function() { 22 | expect( split([]) ).toEqual([]); 23 | }); 24 | 25 | it('should not return empty segments', function() { 26 | var arr = [1, 2]; 27 | expect( split(arr, 3) ).toEqual([ [1], [2] ]); 28 | }); 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/array/spec-toLookup.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/toLookup'], function (toLookup) { 2 | 3 | describe('array/toLookup()', function () { 4 | 5 | it('should create an object with the key specified as a string', function () { 6 | var arr = [{ name: 'a', thing: 1 }, { name: 'b', thing: 2 }]; 7 | 8 | result = toLookup(arr, 'name'); 9 | expect(result).toEqual({ 10 | a: { name: 'a', thing: 1 }, 11 | b: { name: 'b', thing: 2 } 12 | }); 13 | }); 14 | 15 | it('should create an object with the key specified as a function', function () { 16 | var arr = [{ name: 'a', thing: 1 }, null], 17 | result; 18 | 19 | result = toLookup(arr, function (v) { 20 | if (v === null) { 21 | return 'null'; 22 | } else { 23 | return v.name; 24 | } 25 | }); 26 | expect(result).toEqual({ 27 | 'null': null, 28 | a: { name: 'a', thing: 1 } 29 | }); 30 | }); 31 | 32 | }); 33 | 34 | }); 35 | -------------------------------------------------------------------------------- /tests/spec/array/spec-union.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/union'], function (union) { 2 | 3 | describe('array/union()', function () { 4 | 5 | it('should concat arrays', function () { 6 | 7 | var a = ['a', 'b'], 8 | b = ['c'], 9 | c = [1, 2, 3]; 10 | 11 | expect( union(a, b, c) ).toEqual( ['a', 'b', 'c', 1, 2, 3] ); 12 | 13 | }); 14 | 15 | it('should remove duplicates', function () { 16 | 17 | var a = ['a', 'b'], 18 | b = ['c', 'a'], 19 | c = [1, 'b', 2, 3, 'a']; 20 | 21 | //note that unique remove from begin to end 22 | expect( union(a, b, c) ).toEqual( ['c', 1, 'b', 2, 3, 'a'] ); 23 | 24 | }); 25 | 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /tests/spec/array/spec-unique.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/unique'], function (unique) { 2 | 3 | describe('array/unique()', function(){ 4 | 5 | it('should remove duplicates', function(){ 6 | 7 | var source = ['a', 1, 2, 'c', 'b', 2 , 1, 'b', 'c']; 8 | var result = unique(source); 9 | 10 | expect( result.length ).toEqual( 5 ); 11 | expect( source.length ).toEqual( 9 ); 12 | 13 | expect( result.join(',') ).toEqual('a,2,1,b,c'); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/array/spec-xor.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/xor'], function (xor) { 2 | 3 | describe('array/xor()', function () { 4 | 5 | it('should keep only items that are present in a single array', function () { 6 | 7 | var a = ['a', 'b', 1], 8 | b = ['c', 1]; 9 | 10 | expect( xor(a, b) ).toEqual( ['a', 'b', 'c'] ); 11 | 12 | }); 13 | 14 | it('should remove duplicates', function () { 15 | 16 | var a = ['a', 'b', 1, 'b'], 17 | b = ['c', 'a', 1, 'c']; 18 | 19 | expect( xor(a, b) ).toEqual( ['b', 'c'] ); 20 | 21 | }); 22 | 23 | it('should return an empty array if items are present on both arrays', function () { 24 | 25 | var a = ['a', 'c'], 26 | b = ['c', 'a']; 27 | 28 | expect( xor(a, b) ).toEqual( [] ); 29 | 30 | }); 31 | 32 | }); 33 | 34 | }); 35 | -------------------------------------------------------------------------------- /tests/spec/array/spec-zip.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/array/zip'], function(zip){ 2 | 3 | describe('array/zip', function(){ 4 | 5 | it('should group elements from different arrays', function(){ 6 | var output = [ ['a', 1], ['b', 2], ['c', 3] ]; 7 | expect( zip(['a', 'b', 'c'], [1, 2, 3]) ).toEqual( output ); 8 | }); 9 | 10 | it('should work with "n" arrays', function () { 11 | var output = [ ['a', 1, true, 4], ['b', 2, false, 5], ['c', 3, true, 6] ]; 12 | expect( zip(['a', 'b', 'c'], [1, 2, 3], [true, false, true], [4,5,6]) ).toEqual( output ); 13 | }); 14 | 15 | it('should work with arrays of diff length', function () { 16 | var output = [ ['a', 1, true, 4], ['b', 2, false, undefined], ['c', 3, undefined, undefined] ]; 17 | expect( zip(['a', 'b', 'c'], [1, 2, 3], [true, false], [4]) ).toEqual( output ); 18 | }); 19 | 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /tests/spec/collection/spec-contains.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/collection/contains'], function(contains){ 2 | 3 | describe('collection/contains', function(){ 4 | 5 | it('should check for existence (array)', function(){ 6 | var arr = [1, 2, 3]; 7 | expect( contains(arr, 2) ).toBe( true ); 8 | expect( contains(arr, 4) ).toBe( false ); 9 | }); 10 | 11 | it('should check for existence (object)', function(){ 12 | var list = {a:1, b:2, c:3}; 13 | expect( contains(list, 2) ).toBe( true ); 14 | expect( contains(list, 4) ).toBe( false ); 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/collection/spec-forEach.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/collection/forEach'], function(forEach){ 2 | 3 | describe('collection/forEach', function(){ 4 | 5 | it('should loop arrays', function(){ 6 | var result = []; 7 | forEach([1,2,3,4], function(val, i){ 8 | result[i] = val; 9 | }); 10 | expect( result ).toEqual( [1,2,3,4] ); 11 | }); 12 | 13 | it('should loop over object own properties', function(){ 14 | var result = {}; 15 | var Foo = function(){ 16 | this.a = 'lorem'; 17 | this.b = 123; 18 | this.c = 'bar'; 19 | }; 20 | Foo.prototype.d = 'ipsum'; 21 | 22 | var src = new Foo(); 23 | forEach(src, function(val, i){ 24 | result[i] = val; 25 | }); 26 | expect( result ).toEqual( {a:'lorem', b:123, c:'bar'} ); 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/function/spec-bind.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/function/bind'], function (bind) { 2 | 3 | describe('function/bind()', function(){ 4 | 5 | var o1 = {val : 'bar'}; 6 | var o2 = {val : 123}; 7 | 8 | function getVal(){ 9 | return this.val; 10 | } 11 | 12 | function doIt(a, b, c){ 13 | var str = ''; 14 | str += a? a : ''; 15 | str += b? b : ''; 16 | str += c? c : ''; 17 | return this.val + str; 18 | } 19 | 20 | 21 | it('should change execution context', function(){ 22 | var a = bind(getVal, o1); 23 | var b = bind(getVal, o2); 24 | expect( a() ).toEqual('bar'); 25 | expect( b() ).toEqual(123); 26 | }); 27 | 28 | it('should curry args', function(){ 29 | var a = bind(doIt, o1, ' a', 'b', 'c'); 30 | var b = bind(doIt, o2, '456'); 31 | expect( a() ).toEqual('bar abc'); 32 | expect( b() ).toEqual('123456'); 33 | }); 34 | 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/spec/function/spec-compose.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/function/compose'], function (compose) { 2 | 3 | describe('function/compose()', function () { 4 | 5 | it('should pass returned value to each fn in the chain starting from left-most fn', function () { 6 | 7 | var arr = [1, 2, 3]; 8 | 9 | function map(arr, fn) { 10 | var n = arr.length; 11 | var i = 0; 12 | while (i < n) { 13 | arr[i] = fn(arr[i]); 14 | i += 1; 15 | } 16 | return arr; 17 | } 18 | 19 | function add2(val) { 20 | return val + 2; 21 | } 22 | 23 | function multi2(val){ 24 | return val * 2; 25 | } 26 | 27 | expect( map([1, 2, 3], compose(add2, multi2)) ).toEqual( [4, 6, 8] ); 28 | 29 | }); 30 | 31 | }); 32 | 33 | 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /tests/spec/function/spec-curry.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/function/curry'], function(curry){ 2 | 3 | var add = function(a, b){ 4 | return a + b; 5 | }; 6 | 7 | 8 | describe('function/curry', function(){ 9 | 10 | it('should curry arguments', function(){ 11 | var addTen = curry(add, 10); 12 | expect( addTen(2) ).toBe( 12 ); 13 | expect( addTen(5) ).toBe( 15 ); 14 | }); 15 | 16 | it('should curry multiple arguments', function(){ 17 | expect( curry(add, 10, 5)() ).toBe( 15 ); 18 | }); 19 | 20 | }); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /tests/spec/function/spec-func.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/function/func'], function (func) { 2 | 3 | describe('function/func()', function () { 4 | 5 | it('should call method of object', function () { 6 | 7 | var o = {getFoo : function(){ return 'bar'; }}; 8 | var getFoo = func('getFoo'); 9 | 10 | expect( getFoo(o) ).toBe('bar'); 11 | 12 | }); 13 | 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /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/lang/spec-ctorApply.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/ctorApply'], function (ctorApply) { 2 | 3 | describe('lang/ctorApply()', function () { 4 | 5 | it('should call constructor only once passing arguments and keep prototype chain', function () { 6 | 7 | var _count = 0; 8 | 9 | var Foo = function(a, b, c){ 10 | this.a = a; 11 | this.b = b; 12 | this.c = c; 13 | _count++; 14 | }; 15 | 16 | //make sure prototype chain is maintained 17 | Foo.prototype.get = function(key){ 18 | return this[key]; 19 | }; 20 | 21 | var obj = ctorApply(Foo, ['lorem', 'ipsum', 123]); 22 | 23 | expect( _count ).toEqual( 1 ); 24 | expect( obj.get('a') ).toEqual( 'lorem' ); 25 | expect( obj.get('b') ).toEqual( 'ipsum' ); 26 | expect( obj.get('c') ).toEqual( 123 ); 27 | 28 | }); 29 | 30 | }); 31 | 32 | }); 33 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-defaults.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/defaults'], function (defaults) { 2 | 3 | describe('lang/defaults', function () { 4 | 5 | it('should return first non void value', function () { 6 | 7 | var a, 8 | b = null; 9 | 10 | expect( defaults(a, 'foo') ).toEqual( 'foo' ); 11 | expect( defaults(b, 'bar') ).toEqual( 'bar' ); 12 | expect( defaults(a, b, 123) ).toEqual( 123 ); 13 | expect( defaults(a, b, 123, 'dolor') ).toEqual( 123 ); 14 | expect( defaults(a, false, b, 123, 'dolor') ).toEqual( false ); 15 | expect( defaults(a, true, b, 123, 'dolor') ).toEqual( true ); 16 | 17 | var obj = {}; 18 | expect( defaults(obj, a, b, 123, 'dolor') ).toEqual( obj ); 19 | expect( defaults(a, b, obj, 123, 'dolor') ).toEqual( obj ); 20 | 21 | }); 22 | 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-inheritPrototype.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/inheritPrototype'], function (inheritPrototype) { 2 | 3 | describe('lang/inheritPrototype()', function(){ 4 | 5 | it('should inherit prototype', function(){ 6 | 7 | function Foo(name){ 8 | this.name = name; 9 | } 10 | Foo.prototype = { 11 | getName : function(){ 12 | return this.name; 13 | } 14 | }; 15 | 16 | function Bar(name){ 17 | this.name = name; 18 | } 19 | inheritPrototype(Bar, Foo); 20 | Bar.prototype.test = true; 21 | 22 | 23 | var a = new Foo('ipsum'); 24 | var b = new Bar('asd'); 25 | 26 | expect(a.getName()).toEqual('ipsum'); 27 | expect(a.test).toEqual(undefined); 28 | 29 | expect(b.getName()).toEqual('asd'); 30 | expect(b.test).toEqual(true); 31 | 32 | }); 33 | 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isArguments.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isArguments'], function (isArguments) { 2 | 3 | describe('lang/isArguments()', function () { 4 | 5 | it('should detect if value is arguments', function () { 6 | 7 | expect( isArguments(arguments) ).toBe( true ); 8 | 9 | expect( isArguments('') ).toBe( false ); 10 | expect( isArguments(123) ).toBe( false ); 11 | expect( isArguments(null) ).toBe( false ); 12 | expect( isArguments({}) ).toBe( false ); 13 | expect( isArguments([]) ).toBe( false ); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isArray.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isArray'], function (isArray) { 2 | 3 | describe('lang/isArray()', function () { 4 | 5 | it('should detect if value is a Array', function () { 6 | 7 | expect( isArray([1, 'foo']) ).toBe( true ); 8 | expect( isArray(new Array(3)) ).toBe( true ); 9 | 10 | expect( isArray('') ).toBe( false ); 11 | expect( isArray(123) ).toBe( false ); 12 | expect( isArray(null) ).toBe( false ); 13 | expect( isArray({}) ).toBe( false ); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isBoolean.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isBoolean'], function (isBoolean) { 2 | 3 | describe('lang/isBoolean()', function () { 4 | 5 | it('should detect if value is a Boolean', function () { 6 | 7 | expect( isBoolean(true) ).toBe( true ); 8 | expect( isBoolean(false) ).toBe( true ); 9 | expect( isBoolean(new Boolean(false)) ).toBe( true ); 10 | expect( isBoolean(new Boolean(true)) ).toBe( true ); 11 | expect( isBoolean(Boolean(0)) ).toBe( true ); 12 | expect( isBoolean(Boolean(1)) ).toBe( true ); 13 | 14 | expect( isBoolean('') ).toBe( false ); 15 | expect( isBoolean(123) ).toBe( false ); 16 | expect( isBoolean(null) ).toBe( false ); 17 | expect( isBoolean({}) ).toBe( false ); 18 | 19 | }); 20 | 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isDate.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isDate'], function (isDate) { 2 | 3 | describe('lang/isDate()', function () { 4 | 5 | it('should detect if value is a Date', function () { 6 | 7 | expect( isDate(new Date()) ).toBe( true ); 8 | 9 | expect( isDate('') ).toBe( false ); 10 | expect( isDate(123) ).toBe( false ); 11 | expect( isDate(null) ).toBe( false ); 12 | expect( isDate({}) ).toBe( false ); 13 | expect( isDate([]) ).toBe( false ); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isFunction.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isFunction'], function (isFunction) { 2 | 3 | describe('lang/isFunction()', function () { 4 | 5 | it('should detect if value is a function', function () { 6 | 7 | expect( isFunction(function () {}) ).toBe( true ); 8 | expect( isFunction(new Function('return 1;')) ).toBe( true ); 9 | 10 | expect( isFunction('') ).toBe( false ); 11 | expect( isFunction(123) ).toBe( false ); 12 | expect( isFunction(null) ).toBe( false ); 13 | expect( isFunction({}) ).toBe( false ); 14 | expect( isFunction([]) ).toBe( false ); 15 | 16 | }); 17 | 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isKind.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isKind'], function (isKind) { 2 | 3 | describe('lang/isKind()', function(){ 4 | 5 | it('should check kind of value', function () { 6 | 7 | expect( isKind([1, 'foo'], 'Array') ).toBe( true ); 8 | expect( isKind(false, 'Boolean') ).toBe( true ); 9 | expect( isKind(true, 'Boolean') ).toBe( true ); 10 | expect( isKind(new Date(), 'Date') ).toBe( true ); 11 | expect( isKind(function () {}, 'Function') ).toBe( true ); 12 | expect( isKind(null, 'Null') ).toBe( true ); 13 | expect( isKind(123, 'Number') ).toBe( true ); 14 | expect( isKind({}, 'Object') ).toBe( true ); 15 | expect( isKind(/\w+/, 'RegExp') ).toBe( true ); 16 | expect( isKind('', 'String') ).toBe( true ); 17 | expect( isKind(undefined, 'Undefined') ).toBe( true ); 18 | 19 | }); 20 | 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isNaN.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isNaN'], function(isNaN){ 2 | 3 | describe('lang/isNaN', function(){ 4 | 5 | it('should check if value is NaN for realz', function(){ 6 | expect( isNaN(true) ).toBe( false ); 7 | expect( isNaN(false) ).toBe( false ); 8 | expect( isNaN(123) ).toBe( false ); 9 | expect( isNaN('000123') ).toBe( false ); 10 | expect( isNaN('dolor123bar') ).toBe( false ); 11 | expect( isNaN( {} ) ).toBe( false ); 12 | expect( isNaN( [] ) ).toBe( false ); 13 | expect( isNaN( [1,2] ) ).toBe( false ); 14 | expect( isNaN( '' ) ).toBe( false ); 15 | expect( isNaN( null ) ).toBe( false ); 16 | expect( isNaN( undefined ) ).toBe( false ); 17 | expect( isNaN( new Number(123) ) ).toBe( false ); 18 | expect( isNaN( new Number('123') ) ).toBe( false ); 19 | expect( isNaN( NaN ) ).toBe( true ); 20 | expect( isNaN( new Number(NaN) ) ).toBe( true ); 21 | }); 22 | 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isNull.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isNull'], function (isNull) { 2 | 3 | describe('lang/isNull()', function () { 4 | 5 | it('should detect if value is a Null', function () { 6 | 7 | expect( isNull(null) ).toBe( true ); 8 | 9 | expect( isNull('') ).toBe( false ); 10 | expect( isNull(123) ).toBe( false ); 11 | expect( isNull([]) ).toBe( false ); 12 | expect( isNull({}) ).toBe( false ); 13 | 14 | }); 15 | 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isNumber.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isNumber'], function (isNumber) { 2 | 3 | describe('lang/isNumber()', function () { 4 | 5 | it('should detect if value is a Number', function () { 6 | 7 | expect( isNumber(0) ).toBe( true ); 8 | expect( isNumber(123) ).toBe( true ); 9 | expect( isNumber(new Number(123)) ).toBe( true ); 10 | expect( isNumber(Number('123')) ).toBe( true ); 11 | 12 | expect( isNumber('') ).toBe( false ); 13 | expect( isNumber(false) ).toBe( false ); 14 | expect( isNumber(null) ).toBe( false ); 15 | expect( isNumber({}) ).toBe( false ); 16 | 17 | }); 18 | 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isObject.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isObject'], function (isObject) { 2 | 3 | describe('lang/isObject()', function () { 4 | 5 | it('should detect if value is an object', function () { 6 | 7 | expect( isObject({}) ).toBe( true ); 8 | expect( isObject(new function(){}) ).toBe( true ); 9 | 10 | expect( isObject('') ).toBe( false ); 11 | expect( isObject(123) ).toBe( false ); 12 | expect( isObject(null) ).toBe( false ); 13 | expect( isObject([]) ).toBe( false ); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isRegExp.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isRegExp'], function (isRegExp) { 2 | 3 | describe('lang/isRegExp()', function () { 4 | 5 | it('should detect if value is a RegExp', function () { 6 | 7 | expect( isRegExp(/\w+/) ).toBe( true ); 8 | expect( isRegExp(new RegExp('\\w+', 'g')) ).toBe( true ); 9 | 10 | expect( isRegExp('') ).toBe( false ); 11 | expect( isRegExp(123) ).toBe( false ); 12 | expect( isRegExp(null) ).toBe( false ); 13 | expect( isRegExp({}) ).toBe( false ); 14 | expect( isRegExp([]) ).toBe( false ); 15 | 16 | }); 17 | 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isString.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isString'], function (isString) { 2 | 3 | describe('lang/isString()', function () { 4 | 5 | it('should detect if value is a string', function () { 6 | 7 | expect( isString('foo') ).toBe( true ); 8 | expect( isString(new String('lorem')) ).toBe( true ); 9 | expect( isString(String(123)) ).toBe( true ); 10 | 11 | expect( isString(null) ).toBe( false ); 12 | expect( isString(12) ).toBe( false ); 13 | expect( isString(false) ).toBe( false ); 14 | 15 | }); 16 | 17 | }); 18 | 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/lang/spec-isUndefined.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/lang/isUndefined'], function (isUndefined) { 2 | 3 | describe('lang/isUndefined()', function () { 4 | 5 | it('should detect if value is undefined', function () { 6 | 7 | expect( isUndefined(undefined) ).toBe( true ); 8 | expect( isUndefined() ).toBe( true ); 9 | 10 | expect( isUndefined('') ).toBe( false ); 11 | expect( isUndefined(123) ).toBe( false ); 12 | expect( isUndefined(null) ).toBe( false ); 13 | expect( isUndefined({}) ).toBe( false ); 14 | expect( isUndefined([]) ).toBe( false ); 15 | 16 | }); 17 | 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /tests/spec/math/spec-countSteps.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/countSteps'], function (countSteps) { 2 | 3 | describe('math/countSteps()', function(){ 4 | 5 | it('count number of full steps', function(){ 6 | expect( countSteps(12, 5) ).toEqual(2); 7 | expect( countSteps(17, 5) ).toEqual(3); 8 | expect( countSteps(122, 10) ).toEqual(12); 9 | expect( countSteps(129, 10) ).toEqual(12); 10 | }); 11 | 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/math/spec-floor.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/floor'], function (floor) { 2 | 3 | describe('math/floor()', function(){ 4 | 5 | it('floor value to full steps', function(){ 6 | expect( floor(12.5) ).toEqual(12); 7 | expect( floor(12, 5) ).toEqual(10); 8 | expect( floor(17, 5) ).toEqual(15); 9 | expect( floor(122, 10) ).toEqual(120); 10 | expect( floor(129, 10) ).toEqual(120); 11 | }); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/spec/math/spec-isNear.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/isNear'], function (isNear) { 2 | 3 | describe('math/isNear()', function(){ 4 | 5 | it('should return true if val is close to target +/- threshold', function(){ 6 | expect( isNear(10.5, 10, 0.5) ).toEqual(true); 7 | expect( isNear(9.5, 10, 0.5) ).toEqual(true); 8 | expect( isNear(9.9, 10, 0.5) ).toEqual(true); 9 | expect( isNear(10.1, 10, 0.5) ).toEqual(true); 10 | expect( isNear(10, 10, 0.5) ).toEqual(true); 11 | }); 12 | 13 | it('should return false if val is far from target +/- threshold', function(){ 14 | expect( isNear(10.51, 10, 0.5) ).toEqual(false); 15 | expect( isNear(9.45, 10, 0.5) ).toEqual(false); 16 | expect( isNear(9.1, 10, 0.5) ).toEqual(false); 17 | expect( isNear(10.9, 10, 0.5) ).toEqual(false); 18 | expect( isNear(8, 10, 0.5) ).toEqual(false); 19 | }); 20 | 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /tests/spec/math/spec-lerp.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/lerp'], function (lerp) { 2 | 3 | describe('math/lerp()', function(){ 4 | 5 | it('interpolate values', function(){ 6 | expect( lerp(0.5, 0, 10) ).toEqual(5); 7 | expect( lerp(0.75, 0, 100) ).toEqual(75); 8 | expect( lerp(0.66, 0, 1000) ).toEqual(660); 9 | expect( lerp(1, 0, 1000) ).toEqual(1000); 10 | expect( lerp(0, 0, 1000) ).toEqual(0); 11 | }); 12 | 13 | }); 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /tests/spec/math/spec-map.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/map'], function (map) { 2 | 3 | describe('math/map()', function(){ 4 | 5 | it('map a number from one scale to another', function(){ 6 | expect( map(5, 0, 10, 10, 20) ).toEqual(15); 7 | expect( map(-50, -100, 0, 0, 100) ).toEqual(50); 8 | expect( map(0, -1, 1, 0, 100) ).toEqual(50); 9 | }); 10 | 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /tests/spec/math/spec-norm.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/math/norm'], function (norm) { 2 | 3 | describe('math/norm()', function(){ 4 | 5 | it('should normalize value inside range', function(){ 6 | expect( norm(50, 0, 100) ).toEqual(0.5); 7 | expect( norm(200, 0, 500) ).toEqual(0.4); 8 | expect( norm(200, 0, 1000) ).toEqual(0.2); 9 | }); 10 | 11 | it('should calculate ratio even outside range', function(){ 12 | expect( norm(1500, 0, 1000) ).toEqual(1.5); 13 | expect( norm(-1500, 0, 1000) ).toEqual(-1.5); 14 | }); 15 | 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/spec/number/spec-pad.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/pad'], function (pad) { 2 | 3 | describe('number/pad()', function(){ 4 | it('should add zeroes if number length is < minLength', function(){ 5 | expect( pad(15, 0) ).toEqual( '15' ); 6 | expect( pad(15, 1) ).toEqual( '15' ); 7 | expect( pad(15, 2) ).toEqual( '15' ); 8 | expect( pad(15, 3) ).toEqual( '015' ); 9 | expect( pad(15, 4) ).toEqual( '0015' ); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /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/number/spec-ror.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/ror'], function (ror) { 2 | 3 | describe('number/ror()', function(){ 4 | it('should rotate bits right', function(){ 5 | expect( ror( parseInt('10101', 2), 6).toString(2) ).toEqual( '10101'+ (new Array(27)).join(0) ); 6 | expect( ror( 1 << 30, 5).toString(2) ).toEqual( '1'+ (new Array(26)).join('0') ); 7 | }); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /tests/spec/number/spec-sign.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/sign'], function (sign) { 2 | 3 | describe('number/sign()', function () { 4 | 5 | it('should return -1 if number is negative', function () { 6 | expect( sign(-123) ).toEqual(-1); 7 | expect( sign(-0.5) ).toEqual(-1); 8 | expect( sign(- Math.pow(2,32)) ).toEqual(-1); 9 | }); 10 | 11 | it('should return +1 if number is positive or zero', function () { 12 | expect( sign(0) ).toEqual(1); 13 | expect( sign(123) ).toEqual(1); 14 | expect( sign(0.5) ).toEqual(1); 15 | expect( sign(Math.pow(2,32)) ).toEqual(1); 16 | }); 17 | 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /tests/spec/number/spec-toInt.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/toInt'], function (toInt) { 2 | 3 | describe('number/toInt()', function(){ 4 | 5 | it('should remove decimal digits', function(){ 6 | expect( toInt(1.25) ).toEqual(1); 7 | expect( toInt(0.75) ).toEqual(0); 8 | expect( toInt(-0.55) ).toEqual(0); 9 | expect( toInt(2.999) ).toEqual(2); 10 | expect( toInt(10.0001) ).toEqual(10); 11 | expect( toInt(-5.0001) ).toEqual(-5); 12 | expect( toInt(-9.99999) ).toEqual(-9); 13 | }); 14 | 15 | it('should wrap at MAX_INT and MIN_INT', function(){ 16 | expect( toInt( Math.pow(2,31) - 1.5 ) ).toEqual(2147483646); 17 | expect( toInt( Math.pow(2,31) + 0.5 ) ).toEqual(-2147483648); 18 | expect( toInt( Math.pow(-2,31) - 1.5 ) ).toEqual(2147483647); 19 | expect( toInt( Math.pow(-2,31) - 0.5 ) ).toEqual(-2147483648); 20 | expect( toInt( Math.pow(-2,31) + 0.5 ) ).toEqual(-2147483647); 21 | }); 22 | 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /tests/spec/number/spec-toUInt31.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/number/toUInt31'], function (toUInt31) { 2 | 3 | describe('number/toUInt31()', function(){ 4 | 5 | it('should remove decimal digits', function(){ 6 | expect( toUInt31(1.25) ).toEqual(1); 7 | expect( toUInt31(0.75) ).toEqual(0); 8 | expect( toUInt31(2.999) ).toEqual(2); 9 | expect( toUInt31(10.0001) ).toEqual(10); 10 | }); 11 | 12 | it('should treat negative numbers as zero', function () { 13 | expect( toUInt31(-0.55) ).toEqual(0); 14 | expect( toUInt31(-5.0001) ).toEqual(0); 15 | expect( toUInt31(-9.99999) ).toEqual(0); 16 | }); 17 | 18 | it('should wrap at 2^31', function () { 19 | expect( toUInt31( Math.pow(2,31) + 0.5 ) ).toEqual( 0 ); 20 | expect( toUInt31( Math.pow(2,31) + 5.5 ) ).toEqual( 5 ); 21 | expect( toUInt31( Math.pow(2,32) - 0.5 ) ).toEqual( 2147483647 ); 22 | }); 23 | 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /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/object/spec-every.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/every'], function(every){ 2 | 3 | describe('object/every', function(){ 4 | 5 | var isEven = function(val, key, obj){ 6 | return (val % 2 === 0); 7 | }; 8 | 9 | it('should work on normal object', function () { 10 | var a1 = {a: 1, b: 2, c: 3}; 11 | var a2 = {a: 1, b: 3, c: 5}; 12 | var a3 = {a: 2, b: 4, c: 6}; 13 | 14 | expect( every(a1, isEven) ).toBe( false ); 15 | expect( every(a2, isEven) ).toBe( false ); 16 | expect( every(a3, isEven) ).toBe( true ); 17 | }); 18 | 19 | it('should work on empty objects', function () { 20 | expect( every({}, isEven) ).toBe( true ); 21 | }); 22 | 23 | it('should avoid don\'t enum bug on IE 7-8', function () { 24 | var a1 = {a:2, toString:3}; 25 | var a2 = {a:2, toString:4}; 26 | expect( every(a1, isEven) ).toBe( false ); 27 | expect( every(a2, isEven) ).toBe( true ); 28 | }); 29 | 30 | }); 31 | 32 | }); 33 | -------------------------------------------------------------------------------- /tests/spec/object/spec-get.js: -------------------------------------------------------------------------------- 1 | define( 2 | [ 3 | 'amd-utils/object/get' 4 | ], 5 | function (get) { 6 | 7 | describe('object/get()', function () { 8 | 9 | it('should get nested property', function () { 10 | var foo = { 11 | bar : { 12 | lorem : { 13 | ipsum : 'dolor' 14 | } 15 | } 16 | }; 17 | expect( get(foo, 'bar.lorem.ipsum') ).toBe( 'dolor' ); 18 | }); 19 | 20 | it('should return undefined if non existent', function () { 21 | var foo = { 22 | bar : { 23 | lorem : 'ipsum' 24 | } 25 | }; 26 | var undef; 27 | expect( get(foo, 'bar.dolor') ).toBe( undef ); 28 | }); 29 | 30 | }); 31 | 32 | } 33 | ); 34 | 35 | -------------------------------------------------------------------------------- /tests/spec/object/spec-max.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/max'], function(max){ 2 | 3 | describe('object/max', function(){ 4 | 5 | it('should return maximum value', function () { 6 | 7 | expect( max({a: 100, b: 2, c: 1, d: 3, e: 200}) ).toBe(200); 8 | expect( max({foo: 100, bar: 200}) ).toBe(200); 9 | expect( max({a: -10, b: 1, c: 0}) ).toBe(1); 10 | 11 | }); 12 | 13 | it('should return Infinity if empty', function () { 14 | 15 | expect( max({}) ).toBe(Infinity); 16 | 17 | }); 18 | 19 | it('should allow custom iterator', function () { 20 | 21 | expect( max({a: 1, b: 2, c: 3}, function(val){ return -val; }) ).toBe(1); 22 | 23 | expect( max({a: 'foo', b: 'lorem', c: 'amet'}, function(val){ 24 | return val.length; 25 | }) ).toBe('lorem'); 26 | 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/object/spec-min.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/min'], function(min){ 2 | 3 | describe('object/min', function(){ 4 | 5 | it('should return minimum value', function () { 6 | 7 | expect( min({a: 100, b: 2, c: 1, d: 3, e: 200}) ).toBe(1); 8 | expect( min({foo: 100, bar: 200}) ).toBe(100); 9 | expect( min({a: -10, b: 1, c: 0}) ).toBe(-10); 10 | 11 | }); 12 | 13 | it('should return -Infinity if empty', function () { 14 | 15 | expect( min({}) ).toBe(-Infinity); 16 | 17 | }); 18 | 19 | it('should allow custom iterator', function () { 20 | 21 | expect( min({a: 1, b: 2, c: 3}, function(val){ return -val; }) ).toBe(3); 22 | 23 | expect( min({a: 'foo', b: 'lorem', c: 'amet'}, function(val){ 24 | return val.length; 25 | }) ).toBe('foo'); 26 | 27 | }); 28 | 29 | }); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /tests/spec/object/spec-pick.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/pick'], function (pick) { 2 | 3 | describe('object/pick()', function () { 4 | 5 | it('should keep only desired properties', function () { 6 | var obj = { 7 | foo : 1, 8 | bar : 2, 9 | lorem : 3 10 | }; 11 | var result = pick(obj, 'foo', 'lorem'); 12 | expect(result).toEqual({foo: 1, lorem : 3}); 13 | }); 14 | 15 | it('should allow passing keys as array', function () { 16 | var obj = { 17 | a : false, // test for falsy value 18 | b : 'bar', 19 | toString : 'dolor' // test don't enum bug on IE 20 | }; 21 | var result = pick(obj, ['a', 'toString']); 22 | expect(result).toEqual({a: false, toString : 'dolor'}); 23 | }); 24 | 25 | }); 26 | 27 | }); 28 | -------------------------------------------------------------------------------- /tests/spec/object/spec-pluck.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/pluck'], function(pluck){ 2 | 3 | describe('object/pluck', function(){ 4 | 5 | it('should extract properties from items', function () { 6 | 7 | var users = { 8 | first: { 9 | name : 'John', 10 | age : 21 11 | }, 12 | second: { 13 | name : 'Mary', 14 | age : 25 15 | }, 16 | third: { 17 | name : 'Jane', 18 | age : 27 19 | } 20 | }; 21 | 22 | expect( pluck(users, 'name') ).toEqual( {first: 'John', second: 'Mary', third: 'Jane'} ); 23 | expect( pluck(users, 'age') ).toEqual( {first: 21, second: 25, third: 27} ); 24 | }); 25 | 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /tests/spec/object/spec-reject.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/reject', 'amd-utils/object/size'], function(reject, size) { 2 | 3 | describe('object/reject', function(){ 4 | 5 | it('should reject items', function() { 6 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5}; 7 | var thisObj = {}; 8 | 9 | var result = reject(obj, function(val, key, list) { 10 | expect(val).toBe(obj[key]); 11 | expect(list).toBe(obj); 12 | expect(this).toBe(thisObj); 13 | return (val % 2) !== 0; 14 | }, thisObj); 15 | 16 | expect(size(obj)).toEqual(5); 17 | expect(result).toEqual({b: 2, d: 4}); 18 | }); 19 | 20 | it('should return empty object if all items rejected', function() { 21 | var obj = {a: 1, b: 2, c: 3, d: 4, e: 5}; 22 | var result = reject(obj, function() { return true; }); 23 | expect(result).toEqual({}); 24 | }); 25 | 26 | }); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /tests/spec/object/spec-some.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/object/some'], function(some){ 2 | 3 | describe('object/some', function(){ 4 | 5 | var isEven = function(val, key, obj){ 6 | return (val % 2 === 0); 7 | }; 8 | 9 | it('should work on normal object', function () { 10 | var a1 = {a: 1, b: 2, c: 3}; 11 | var a2 = {a: 1, b: 3, c: 5}; 12 | var a3 = {a: 2, b: 4, c: 6}; 13 | 14 | expect( some(a1, isEven) ).toBe( true ); 15 | expect( some(a2, isEven) ).toBe( false ); 16 | expect( some(a3, isEven) ).toBe( true ); 17 | }); 18 | 19 | it('should work on empty objects', function () { 20 | expect( some({}, isEven) ).toBe( false ); 21 | }); 22 | 23 | it('should avoid don\'t enum bug on IE 7-8', function () { 24 | var a1 = {a:1, toString:2}; 25 | var a2 = {a:1, toString:3}; 26 | expect( some(a1, isEven) ).toBe( true ); 27 | expect( some(a2, isEven) ).toBe( false ); 28 | }); 29 | 30 | }); 31 | 32 | }); 33 | -------------------------------------------------------------------------------- /tests/spec/queryString/spec-contains.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/queryString/contains'], function (contains) { 2 | 3 | describe('queryString/contains()', function () { 4 | 5 | it('should check if param exists', function () { 6 | var query = "?foo=bar&a=123&b=false&c=null"; 7 | var url = "http://example.com/?foo=bar&a=123&b=false&c=null"; 8 | 9 | expect( contains(query , 'foo') ) .toEqual( true ); 10 | expect( contains(url , 'foo') ) .toEqual( true ); 11 | expect( contains(query , 'a' ) ) .toEqual( true ); 12 | expect( contains(url , 'a' ) ) .toEqual( true ); 13 | expect( contains(query , 'b' ) ) .toEqual( true ); 14 | expect( contains(url , 'b' ) ) .toEqual( true ); 15 | expect( contains(query , 'c' ) ) .toEqual( true ); 16 | expect( contains(url , 'c' ) ) .toEqual( true ); 17 | 18 | expect( contains(query , 'd' ) ) .toEqual( false ); 19 | expect( contains(url , 'd' ) ) .toEqual( false ); 20 | }); 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /tests/spec/queryString/spec-encode.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/queryString/encode'], function (encode) { 2 | 3 | describe('queryString/encode()', function () { 4 | 5 | it('should convert simple object into query string.', function () { 6 | var q = { 7 | a : 123, 8 | b : false, 9 | c : null, 10 | d : 'bar' 11 | }; 12 | expect( encode(q) ).toBe( '?a=123&b=false&c=null&d=bar' ); 13 | }); 14 | 15 | it('should encode special chars', function () { 16 | var q = { 17 | a : 'bar', 18 | b : 'lorem ipsum', 19 | c : 'spéçîãl çhârs' 20 | }; 21 | expect( encode(q) ).toBe( '?a=bar&b=lorem%20ipsum&c=sp%C3%A9%C3%A7%C3%AE%C3%A3l%20%C3%A7h%C3%A2rs' ); 22 | }); 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /tests/spec/queryString/spec-getQuery.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/queryString/getQuery'], function (getQuery) { 2 | 3 | describe('queryString/getQuery()', function () { 4 | 5 | it('should extract query string from url', function () { 6 | var q = getQuery("http://example.com/?foo=bar&a=123&b=false&c=null"); 7 | expect( q ).toBe( '?foo=bar&a=123&b=false&c=null' ); 8 | }); 9 | }); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /tests/spec/queryString/spec-parse.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/queryString/parse'], function (parse) { 2 | 3 | describe('queryString/parse()', function () { 4 | 5 | it('should extract query string from url and parse it', function () { 6 | var q = parse("http://example.com/?foo=bar&a=123&b=false&c=null"); 7 | expect( q.foo ).toBe( 'bar' ); 8 | expect( q.a ).toBe( 123 ); 9 | expect( q.b ).toBe( false ); 10 | expect( q.c ).toBe( null ); 11 | }); 12 | 13 | it('should allow toggling typecase', function () { 14 | var q = parse("http://example.com/?foo=bar&a=123&b=false&c=null", false); 15 | expect( q.foo ).toBe( 'bar' ); 16 | expect( q.a ).toBe( '123' ); 17 | expect( q.b ).toBe( 'false' ); 18 | expect( q.c ).toBe( 'null' ); 19 | }); 20 | 21 | }); 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /tests/spec/random/spec-guid.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/random/guid'], function (guid) { 2 | 3 | describe('random/guid()', function(){ 4 | 5 | beforeEach(function(){ 6 | this.addMatchers({ 7 | toDiffAny : function(vals){ 8 | var n = arguments.length; 9 | while(n--){ 10 | if(this.actual !== arguments[n]) return true; 11 | } 12 | return false; 13 | } 14 | }); 15 | }); 16 | 17 | it('returns a random guid each call', function(){ 18 | var q = guid(); 19 | var w = guid(); 20 | var e = guid(); 21 | var r = guid(); 22 | var t = guid(); 23 | var y = guid(); 24 | 25 | // match guid v4 format e.g. 3f2504e0-2f89-41d3-9a0c-0305e82c3301 26 | expect( q ).toMatch(/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[ab89][a-f0-9]{3}-[a-f0-9]{12}/); 27 | expect( q ).not.toBeUndefined(); 28 | expect( q ).toDiffAny(w, e, r, t, y); 29 | }); 30 | 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/spec/spec-array.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'array/spec-append', 5 | 'array/spec-combine', 6 | 'array/spec-compact', 7 | 'array/spec-contains', 8 | 'array/spec-difference', 9 | 'array/spec-every', 10 | 'array/spec-filter', 11 | 'array/spec-find', 12 | 'array/spec-flatten', 13 | 'array/spec-forEach', 14 | 'array/spec-indexOf', 15 | 'array/spec-insert', 16 | 'array/spec-intersection', 17 | 'array/spec-invoke', 18 | 'array/spec-join', 19 | 'array/spec-lastIndexOf', 20 | 'array/spec-map', 21 | 'array/spec-max', 22 | 'array/spec-min', 23 | 'array/spec-pick', 24 | 'array/spec-pluck', 25 | 'array/spec-range', 26 | 'array/spec-reduce', 27 | 'array/spec-reduceRight', 28 | 'array/spec-reject', 29 | 'array/spec-remove', 30 | 'array/spec-removeAll', 31 | 'array/spec-shuffle', 32 | 'array/spec-some', 33 | 'array/spec-sort', 34 | 'array/spec-split', 35 | 'array/spec-toLookup', 36 | 'array/spec-union', 37 | 'array/spec-unique', 38 | 'array/spec-xor', 39 | 'array/spec-zip' 40 | ], function(){ 41 | //noop 42 | }); 43 | -------------------------------------------------------------------------------- /tests/spec/spec-collection.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'collection/spec-contains', 5 | 'collection/spec-every', 6 | 'collection/spec-filter', 7 | 'collection/spec-find', 8 | 'collection/spec-forEach', 9 | 'collection/spec-make_', 10 | 'collection/spec-map', 11 | 'collection/spec-max', 12 | 'collection/spec-min', 13 | 'collection/spec-pluck', 14 | 'collection/spec-reduce', 15 | 'collection/spec-reject', 16 | 'collection/spec-size', 17 | 'collection/spec-some' 18 | ], function(){ 19 | //noop 20 | }); 21 | -------------------------------------------------------------------------------- /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-lang.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'lang/spec-clone', 5 | 'lang/spec-createObject', 6 | 'lang/spec-ctorApply', 7 | 'lang/spec-defaults', 8 | 'lang/spec-inheritPrototype', 9 | 'lang/spec-isArguments', 10 | 'lang/spec-isArray', 11 | 'lang/spec-isBoolean', 12 | 'lang/spec-isDate', 13 | 'lang/spec-isEmpty', 14 | 'lang/spec-isFinite', 15 | 'lang/spec-isFunction', 16 | 'lang/spec-isKind', 17 | 'lang/spec-isNaN', 18 | 'lang/spec-isNull', 19 | 'lang/spec-isNumber', 20 | 'lang/spec-isObject', 21 | 'lang/spec-isRegExp', 22 | 'lang/spec-isString', 23 | 'lang/spec-isUndefined', 24 | 'lang/spec-kindOf', 25 | 'lang/spec-toArray' 26 | ], function(){ 27 | //noop 28 | }); 29 | -------------------------------------------------------------------------------- /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/spec-number.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'number/spec-MAX_INT', 5 | 'number/spec-MAX_UINT', 6 | 'number/spec-MIN_INT', 7 | 'number/spec-abbreviate', 8 | 'number/spec-currencyFormat', 9 | 'number/spec-enforcePrecision', 10 | 'number/spec-pad', 11 | 'number/spec-rol', 12 | 'number/spec-ror', 13 | 'number/spec-sign', 14 | 'number/spec-toInt', 15 | 'number/spec-toUInt', 16 | 'number/spec-toUInt31' 17 | ], function(){ 18 | //noop 19 | }); 20 | -------------------------------------------------------------------------------- /tests/spec/spec-object.js: -------------------------------------------------------------------------------- 1 | //automatically generated, do not edit! 2 | //run `node build` instead 3 | define([ 4 | 'object/spec-contains', 5 | 'object/spec-deepFillIn', 6 | 'object/spec-deepMixIn', 7 | 'object/spec-every', 8 | 'object/spec-fillIn', 9 | 'object/spec-filter', 10 | 'object/spec-find', 11 | 'object/spec-forIn', 12 | 'object/spec-forOwn', 13 | 'object/spec-get', 14 | 'object/spec-has', 15 | 'object/spec-hasOwn', 16 | 'object/spec-keys', 17 | 'object/spec-map', 18 | 'object/spec-max', 19 | 'object/spec-merge', 20 | 'object/spec-min', 21 | 'object/spec-mixIn', 22 | 'object/spec-namespace', 23 | 'object/spec-pick', 24 | 'object/spec-pluck', 25 | 'object/spec-reduce', 26 | 'object/spec-reject', 27 | 'object/spec-set', 28 | 'object/spec-size', 29 | 'object/spec-some', 30 | 'object/spec-unset', 31 | 'object/spec-values' 32 | ], function(){ 33 | //noop 34 | }); 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/spec/string/spec-crop.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/crop'], function (crop) { 2 | 3 | describe('cropstring/()', function(){ 4 | var str = 'lorem ipsum dolor sit amet'; 5 | 6 | it('should limit number of chars', function(){ 7 | var r1 = crop(str, 10); 8 | expect( r1.length ).toBeLessThan( 11 ); 9 | expect( r1 ).toEqual( 'lorem...' ); 10 | 11 | var r2 = crop(str, 14); 12 | expect( r2.length ).toBeLessThan( 15 ); 13 | expect( r2 ).toEqual( 'lorem ipsum...' ); 14 | }); 15 | 16 | it('should append string param', function(){ 17 | var r1 = crop(str, 10, '--'); 18 | expect( r1.length ).toBeLessThan( 11 ); 19 | expect( r1 ).toEqual( 'lorem--' ); 20 | 21 | var r2 = crop(str, 14, '='); 22 | expect( r2.length ).toBeLessThan( 15 ); 23 | expect( r2 ).toEqual( 'lorem ipsum=' ); 24 | }); 25 | 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /tests/spec/string/spec-endsWith.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/endsWith'], function (endsWith) { 2 | 3 | describe('string/endsWith()', function(){ 4 | 5 | it('should return true if string ends with suffix', function(){ 6 | expect( endsWith('lorem-ipsum', 'ipsum') ).toBeTruthy(); 7 | }); 8 | 9 | it('should return false if string does not end with suffix', function(){ 10 | expect( endsWith('lorem-ipsum', 'lorem') ).toBeFalsy(); 11 | }); 12 | 13 | it('should treat undefined as empty string', function () { 14 | var str; 15 | expect( endsWith(str, 'ipsum') ).toBeFalsy(); 16 | }); 17 | 18 | it('should treat null as empty string', function(){ 19 | expect( endsWith(null, '') ).toBeTruthy(); 20 | }); 21 | 22 | it('should return true if suffix undefined', function(){ 23 | var suffix; 24 | expect( endsWith('lorem-ipsum', suffix) ).toBeTruthy(); 25 | }); 26 | 27 | it('should return true if suffix null', function () { 28 | expect( endsWith('lorem-ipsum', null) ).toBeTruthy(); 29 | }); 30 | 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /tests/spec/string/spec-escapeHtml.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/escapeHtml'], function (escapeHtml) { 2 | 3 | describe('string/escapeHtml()', function () { 4 | 5 | it('should convert special chars into entities', function () { 6 | expect( escapeHtml('\'lorem\' & "ipsum"') ) 7 | .toEqual( '<em>'lorem'</em> & "ipsum"' ); 8 | }); 9 | 10 | it('should return empty string if no argument', function () { 11 | expect( escapeHtml() ).toBe( '' ); 12 | }); 13 | }); 14 | 15 | 16 | }); 17 | 18 | -------------------------------------------------------------------------------- /tests/spec/string/spec-escapeRegExp.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/escapeRegExp'], function (escapeRegExp) { 2 | 3 | describe('string/escapeRegExp', function () { 4 | 5 | it('should escape special chars', function () { 6 | 7 | expect( escapeRegExp('lorem.ipsum') ).toEqual( 'lorem\\.ipsum' ); 8 | expect( escapeRegExp("\\.+*?^$[](){}/'#") ).toEqual( "\\\\\\.\\+\\*\\?\\^\\$\\[\\]\\(\\)\\{\\}\\/\\'\\#" ); 9 | 10 | }); 11 | 12 | }); 13 | 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /tests/spec/string/spec-escapeUnicode.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/escapeUnicode'], function(escapeUnicode){ 2 | 3 | describe('string/escapeUnicode', function(){ 4 | 5 | it('should escape only especial chars by default', function(){ 6 | expect( escapeUnicode('before éãôø after éãôø') ).toBe('before \\u00e9\\u00e3\\u00f4\\u00f8 after \\u00e9\\u00e3\\u00f4\\u00f8'); 7 | }); 8 | 9 | it('should work with empty strings and null', function () { 10 | expect( escapeUnicode('') ).toBe(''); 11 | expect( escapeUnicode(null) ).toBe(''); 12 | expect( escapeUnicode() ).toBe(''); 13 | }); 14 | 15 | it('should allow escaping everything', function () { 16 | expect( escapeUnicode('føo bår', true) ).toEqual( '\\u0066\\u00f8\\u006f\\u0020\\u0062\\u00e5\\u0072' ); 17 | }); 18 | 19 | }); 20 | 21 | }); 22 | -------------------------------------------------------------------------------- /tests/spec/string/spec-lowerCase.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/lowerCase'], function (lowerCase) { 2 | 3 | describe('it should convert string to lower case', function () { 4 | expect( lowerCase('FOO') ).toEqual( 'foo' ); 5 | expect( lowerCase('Bar') ).toEqual( 'bar' ); 6 | expect( lowerCase('ipsum') ).toEqual( 'ipsum' ); 7 | }); 8 | 9 | describe('it should return empty string if null or undefined', function () { 10 | expect( lowerCase() ).toEqual( '' ); 11 | expect( lowerCase(null) ).toEqual( '' ); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /tests/spec/string/spec-lpad.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/lpad'], function (lpad) { 2 | 3 | describe('string/lpad()', function(){ 4 | it('should add chars to the left if length is < minLength', function(){ 5 | expect( lpad('ab', 0, '-') ).toEqual( 'ab' ); 6 | expect( lpad('ab', 1, '-') ).toEqual( 'ab' ); 7 | expect( lpad('ab', 2, '-') ).toEqual( 'ab' ); 8 | expect( lpad('ab', 3, '-') ).toEqual( '-ab' ); 9 | expect( lpad('ab', 4, '-') ).toEqual( '--ab' ); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /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-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-removeNonASCII.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/removeNonASCII'], function (removeNonASCII) { 2 | 3 | describe('string/removeNonASCII()', function(){ 4 | it('should remove non-printable chars', function(){ 5 | var accents = 'áÁâÂàÀåÅãÃäÄçÇéÉêÊèÈëËíÍîÎìÌïÏñÑóÓôÔòÒØõÕöÖÐþúÚûÛùÙüÜýÝÿ'; 6 | var printable = 'lorem ~!@#$%^&*()_+`-={}[]|\\:";\'/?><., ipsum'; 7 | var str = accents + printable; 8 | 9 | expect( removeNonASCII( str ) ).toEqual( printable ); 10 | }); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/spec/string/spec-repeat.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/repeat'], function (repeat) { 2 | 3 | describe('string/repeat()', function () { 4 | 5 | it('should repeat string n times', function () { 6 | 7 | expect( repeat('a', 3) ).toEqual( 'aaa' ); 8 | expect( repeat('ab', 3) ).toEqual( 'ababab' ); 9 | expect( repeat('a', 1) ).toEqual( 'a' ); 10 | expect( repeat('a', 0) ).toEqual( '' ); 11 | 12 | }); 13 | 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /tests/spec/string/spec-replaceAccents.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/replaceAccents'], function (replaceAccents) { 2 | 3 | describe('string/replaceAccents()', function(){ 4 | 5 | it('should replace all Basic Latin and Latin-1 accented chars with regular ones', function(){ 6 | var accents = 'áÁâÂàÀåÅãÃäÄçÇéÉêÊèÈëËíÍîÎìÌïÏñÑóÓôÔòÒØõÕöÖÐþúÚûÛùÙüÜýÝÿ'; 7 | var regular = 'aAaAaAaAaAaAcCeEeEeEeEiIiIiIiInNoOoOoOOoOoODpuUuUuUuUyYy'; 8 | expect( replaceAccents(accents) ).toEqual( regular ); 9 | }); 10 | 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /tests/spec/string/spec-rpad.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/rpad'], function (rpad) { 2 | 3 | describe('string/rpad()', function(){ 4 | it('should add chars to the right if length is < minLength', function(){ 5 | expect( rpad('ab', 0, '-') ).toEqual( 'ab' ); 6 | expect( rpad('ab', 1, '-') ).toEqual( 'ab' ); 7 | expect( rpad('ab', 2, '-') ).toEqual( 'ab' ); 8 | expect( rpad('ab', 3, '-') ).toEqual( 'ab-' ); 9 | expect( rpad('ab', 4, '-') ).toEqual( 'ab--' ); 10 | }); 11 | }); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/spec/string/spec-sentenceCase.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/sentenceCase'], function (sentenceCase) { 2 | 3 | describe('string/sentenceCase()', function(){ 4 | 5 | it('should uppercase first char of each sentence and lowercase others', function(){ 6 | expect( sentenceCase('lorem Ipsum doLOr. sit amet dolor.') ).toEqual('Lorem ipsum dolor. Sit amet dolor.'); 7 | }); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /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 = '
lorem ipsum dolor
sit
amet'; 6 | expect( stripHtmlTags( str ) ).toEqual( 'lorem ipsum dolor sit amet' ); 7 | }); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /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/string/spec-typecast.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/typecast'], function (typecast) { 2 | 3 | describe('string/typecast()', function () { 4 | it('should typecast values if Number, Boolean, null or undefined', function () { 5 | expect( typecast('true') ).toBe( true ); 6 | expect( typecast('false') ).toBe( false ); 7 | expect( typecast('123') ).toBe( 123 ); 8 | expect( typecast('123.45') ).toBe( 123.45 ); 9 | expect( typecast('null') ).toBe( null ); 10 | expect( typecast(null) ).toBe( null ); 11 | expect( typecast('undefined') ).toBe( undefined ); 12 | expect( typecast() ).toBe( undefined ); 13 | expect( typecast('foo') ).toBe( "foo" ); 14 | }); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/spec/string/spec-unescapeHtml.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/unescapeHtml'], function (unescapeHtml) { 2 | 3 | describe('string/unescapeHtml()', function () { 4 | 5 | it('should convert entities into chars', function () { 6 | expect( unescapeHtml( '<em>'lorem'</em> & "ipsum"' ) ) 7 | .toEqual( '\'lorem\' & "ipsum"' ); 8 | }); 9 | 10 | it('should return empty string if no argument', function () { 11 | expect( unescapeHtml() ).toBe( '' ); 12 | }); 13 | 14 | }); 15 | 16 | 17 | }); 18 | 19 | -------------------------------------------------------------------------------- /tests/spec/string/spec-unescapeUnicode.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/unescapeUnicode'], function(unescapeUnicode){ 2 | 3 | describe('string/unescapeUnicode', function(){ 4 | 5 | it('should unescape unicode chars', function(){ 6 | expect( unescapeUnicode('before \\u00e9\\u00e3\\u00f4\\u00f8 after \\u00e9\\u00e3\\u00f4\\u00f8') ).toBe('before éãôø after éãôø'); 7 | }); 8 | 9 | it('should not affect regular chars or non-unicode scapes', function () { 10 | expect( unescapeUnicode('foo \n bar \t \\x45') ).toEqual('foo \n bar \t \\x45'); 11 | }); 12 | 13 | it('should work with empty strings and null', function () { 14 | expect( unescapeUnicode('') ).toBe(''); 15 | expect( unescapeUnicode(null) ).toBe(''); 16 | expect( unescapeUnicode() ).toBe(''); 17 | }); 18 | 19 | it('should work with escaped printable ASCII chars as well', function () { 20 | expect( unescapeUnicode('\\u0066\\u00f8\\u006f\\u0020\\u0062\\u00e5\\u0072') ).toEqual( 'føo bår' ); 21 | }); 22 | 23 | }); 24 | 25 | }); 26 | -------------------------------------------------------------------------------- /tests/spec/string/spec-unhyphenate.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/unhyphenate'], function (unhyphenate) { 2 | 3 | describe('string/unhyphenate()', function(){ 4 | 5 | it('should replace hyphens with spaces if between words', function(){ 6 | var s1 = 'lorem-ipsum-dolor-sit-amet'; 7 | var s2 = 'lorem-ipsum-dolor--sit-amet'; 8 | var s3 = 'lorem-ipsum-dolor---sit-amet'; 9 | var s4 = 'lorem-ipsum-dolor - sit-amet'; 10 | 11 | expect( unhyphenate(s1) ).toEqual( 'lorem ipsum dolor sit amet' ); 12 | expect( unhyphenate(s2) ).toEqual( 'lorem ipsum dolor--sit amet' ); 13 | expect( unhyphenate(s3) ).toEqual( 'lorem ipsum dolor---sit amet' ); 14 | expect( unhyphenate(s4) ).toEqual( 'lorem ipsum dolor - sit amet' ); 15 | }); 16 | 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /tests/spec/string/spec-upperCase.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/string/upperCase'], function (upperCase) { 2 | 3 | describe('it should convert string to lower case', function () { 4 | expect( upperCase('FOO') ).toEqual( 'FOO' ); 5 | expect( upperCase('Bar') ).toEqual( 'BAR' ); 6 | expect( upperCase('ipsum') ).toEqual( 'IPSUM' ); 7 | }); 8 | 9 | describe('it should return empty string if null or undefined', function () { 10 | expect( upperCase() ).toEqual( '' ); 11 | expect( upperCase(null) ).toEqual( '' ); 12 | }); 13 | 14 | }); 15 | -------------------------------------------------------------------------------- /tests/spec/time/spec-now.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/time/now'], function (now) { 2 | 3 | var past = now(); 4 | 5 | describe('time/now()', function () { 6 | 7 | it('should return an integer', function() { 8 | var b = now(); 9 | expect( b.toFixed('0') ).toEqual( b + '' ); 10 | }); 11 | 12 | it('should be greater than first call', function () { 13 | expect( now() ).toBeGreaterThan( past ); 14 | }); 15 | 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/spec/time/spec-toTimeString.js: -------------------------------------------------------------------------------- 1 | define(['amd-utils/time/toTimeString'], function (toTimeString) { 2 | 3 | describe('time/toTimeString()', function(){ 4 | 5 | it('should convert to proper units', function(){ 6 | expect( toTimeString(999) ).toBe('00:00'); 7 | expect( toTimeString(1000) ).toBe('00:01'); 8 | expect( toTimeString(11000) ).toBe('00:11'); 9 | expect( toTimeString(71000) ).toBe('01:11'); 10 | expect( toTimeString(3671000) ).toBe('1:01:11'); 11 | }); 12 | 13 | it('should work for large numbers', function(){ 14 | expect( toTimeString(86400000) ).toBe('24:00:00'); 15 | expect( toTimeString(86400000 * 7) ).toBe('168:00:00'); 16 | }); 17 | 18 | }); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------