diff --git a/README.md b/README.md index 5a628f5..a50172b 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,10 @@ source code of plugins below to learn how to write your own custom tool panels. > When writing plugins, you can use utilities exposed by Eruda, see [docs](https://github.com/liriliri/eruda/blob/master/doc/UTIL_API.md) here. +## Contribution + +Read [Contributing Guide](https://github.com/liriliri/eruda/blob/master/doc/CONTRIBUTING.md) for development setup instructions. + ## Related Projects * [eustia](https://github.com/liriliri/eustia): Generator of eruda's utility library. diff --git a/dev/typo.dic b/dev/typo.dic index b59d39e..b449307 100644 --- a/dev/typo.dic +++ b/dev/typo.dic @@ -4,6 +4,7 @@ btns devtool draggabilly eruda +eustia focusin iframe iteratee diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md new file mode 100644 index 0000000..48e7961 --- /dev/null +++ b/doc/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing Guide + +## Development Setup + +[Node.js](https://nodejs.org/en/) is needed for the development of eruda. + +After cloning the repo, run: + +```bash +# install npm dependencies. +npm install +# copy jasmine lib from node_modules to test folder. +npm run cpTestLib +``` + +## Commonly used NPM scripts + +```bash +# watch and auto re-build, webpack-dev-server is required. +npm run dev +# build eruda.js and eruda.min.js +npm run build +``` + +## Project Structure + +- **dev**: development related files. +- **doc**: documents. +- **eustia**: eustia extended utilties. +- **script**: webpack configuration, and some other useful scripts. +- **src**: source code, written in es2015. +- **test**: contain pages for testing. diff --git a/doc/README_CH.md b/doc/README_CH.md new file mode 100644 index 0000000..d4d895c --- /dev/null +++ b/doc/README_CH.md @@ -0,0 +1,81 @@ +# Eruda + +[![npm version](https://badge.fury.io/js/eruda.svg)](https://badge.fury.io/js/eruda) + +Eruda 是一个专为手机网页前端设计的调试面板,类似 DevTools 的迷你版,其主要功能包括:捕获 console 日志、检查元素状态、显示性能指标、捕获XHR请求、显示本地存储和 Cookie 信息、浏览器特性检测等等。 + +## 功能清单 + +![Eruda](http://7xn2zy.com1.z0.glb.clouddn.com/eruda_screenshot3.jpg) + +1. 按钮拖拽,面板透明度大小设置。 + +2. Console面板:捕获Console日志,支持log、error、info、warn、dir、time/timeEnd、clear、count、assert、table;支持占位符,包括%c自定义样式输出;支持按日志类型及正则表达式过滤;支持快捷命令加载underscore、jQuery库;支持JavaScript脚本执行。 + +3. Elements面板:查看标签内容及属性;查看应用在Dom上的样式;支持页面元素高亮;支持屏幕直接点击选取;查看Dom上绑定的各类事件。 + +4. Network面板:图表显示页面加载速度;查看页面各资源请求时间(Android);捕获XHR请求,查看发送数据、返回头、返回内容等信息。 + +5. Resources面板:查看并清除localStorage、sessionStorage及cookie;查看页面加载脚本及样式文件;查看页面加载图片。 + +6. Sources面板:查看页面源码;格式化html,css,js代码及json数据。 + +7. Info面板:输出URL及User Agent;支持自定义输出内容。 + +8. Snippets面板:页面元素添加边框;加时间戳刷新页面;支持自定义代码片段。 + +9. Features面板:浏览器常用特性检测;提供Can I use,Html5Test快捷访问。 + +## 快速上手 + +通过npm安装: + +```bash +npm install eruda --save +``` + +在页面中加载脚本: + +```html + + +``` + +Js文件对于移动端来说略重(gzip后大概80kb)。建议通过url参数来控制是否加载调试器,比如: + +```javascript +;(function () { + var src = 'node_modules/eruda/eruda.min.js'; + if (!/eruda=true/.test(window.location) && localStorage.getItem('active-eruda') != 'true') return; + document.write(''); + document.write('eruda.init();'); +})(); +``` + +初始化时可以传入配置: +* container: 用于插件初始化的Dom元素,如果不设置,默认创建div作为容器直接置于html根结点下面。 +* tool:指定要初始化哪些面板,默认加载所有。 + +```javascript +var el = document.createElement('div'); +document.body.appendChild(el); + +eruda.init({ + container: el, + tool: ['console', 'elements'] +}); +``` + +> 该工具支持自行编写插件,可参考[eruda-fps](https://github.com/liriliri/eruda-fps)。 + +## Demo + +![Demo](http://7xn2zy.com1.z0.glb.clouddn.com/eruda_qrcode2.png) + +请扫描二维码或在手机上直接访问:[http://liriliri.github.io/eruda/](http://liriliri.github.io/eruda/) + +如果想在其它页面尝试,请在浏览器地址栏上输入以下代码。 + +```javascript +javascript:(function () { var script = document.createElement('script'); script.src="//liriliri.github.io/eruda/eruda.min.js"; document.body.appendChild(script); script.onload = function () { eruda.init() } })(); +``` diff --git a/doc/TOOL_API.md b/doc/TOOL_API.md new file mode 100644 index 0000000..0de19bf --- /dev/null +++ b/doc/TOOL_API.md @@ -0,0 +1,156 @@ +# Tool Api + +Each default tool provided by eruda can be accessed by `eruda.get('Tool Name')`. + +## Console + +Display console logs. Implementation detail follows the [console api spec](https://github.com/DeveloperToolsWG/console-object/blob/master/api.md). + +### Config + +|Name |Type |Desc | +|-------------------|-------|-------------------------------| +|catchGlobalErr |boolean|Catch global errors | +|overrideConsole |boolean|Override console | +|displayExtraInfo |boolean|Display extra information | +|displayUnenumerable|boolean|Display unenumerable properties| +|displayGetterVal |boolean|Access getter value | +|viewLogInSources |boolean|View log in sources panel | +|displayIfErr |boolean|Auto display if error occurs | +|maxLogNum |string |Max log number | + +```javascript +var console = eruda.get('console'); +console.config.set('catchGlobalErr', true); +``` + +### log, error, info, warn, dir, time/timeEnd, clear, count, assert, table + +All these methods can be used in the same way as window.console object. + +```javascript +var console = eruda.get('console'); +console.log('eruda is a console for %s.', 'mobile browsers'); +console.table([{test: 1}, {test: 2}, {test2: 3}], 'test'); +console.error(new Error('eruda')); +``` + +### filter + +Filter logs. + +|Name |Type |Desc | +|------|----------------------|-------------| +|filter|string regexp function|Custom filter| + +```javascript +console.filter('all'); // String parameter. Log, warn, debug, error is also supported. +console.filter(/^eruda/); +console.filter(function (log) +{ + return log.type === 'error'; +}); +``` + +### html + +Log out html content. + +|Name|Type |Desc | +|----|------|-----------| +|html|string|Html string| + +```javascript +console.html('Red'); +``` + +## Elements + +## Network + +## Resources + +## Sources + +## Info + +Display special information, could be used for displaying user info to track +user logs. + +By default, page url and browser user agent is shown. + +### clear + +Clear infos. + +### add + +Add info. + +|Name |Type |Desc | +|-------|------|------------| +|name |string|Info name | +|content|string|Info content| + +```javascript +info.add('title', 'content'); +``` + +### remove + +Remove specified info. + +|Name|Type |Desc | +|----|------|---------| +|name|string|Info name| + +```javascript +info.remove('title'); +``` + +## Snippets + +Allow you to register small functions that can be triggered multiple times. + +### clear + +Clear Snippets. + +### add + +Add Snippet. + +|Name|Type |Desc | +|----|--------|------------------------| +|name|string |Snippet name | +|fn |function|Function to be triggered| +|desc|string |Snippet description | + +```javascript +snippets.add('hello', function () +{ + console.log('Hello World!'); +}, 'Display hello on console'); +``` + +### remove + +Remove specified snippet. + +|Name|Type |Desc | +|----|------|-----------------| +|name|string|Snippet to remove| + +```javascript +snippets.remove('hello'); +``` + +## Features + +Browser feature detections, thanks to +[modernizr](https://github.com/Modernizr/Modernizr) project. + +Red means unsupported, otherwise ok. All buttons is linked directly to +related materials in [Can I Use](http://caniuse.com/) website. + +## Settings diff --git a/doc/UTIL_API.md b/doc/UTIL_API.md new file mode 100644 index 0000000..ad13f32 --- /dev/null +++ b/doc/UTIL_API.md @@ -0,0 +1,1347 @@ +# Eruda Util Documentation + +## $ + +jQuery like style dom manipulator. TODO + +```javascript +var $btn = $('#btn'); +$btn.html('eustia'); +``` + +## $attr + +Element attribute manipulation. + +Get the value of an attribute for the first element in the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|--------------------------------| +|element|string array element|Elements to manipulate | +|name |string |Attribute name | +|return |string |Attribute value of first element| + +Set one or more attributes for the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|name |string |Attribute name | +|value |string |Attribute value | + +|Name |Type |Desc | +|----------|--------------------|--------------------------------------| +|element |string array element|Elements to manipulate | +|attributes|object |Object of attribute-value pairs to set| + +### remove + +Remove an attribute from each element in the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|name |string |Attribute name | + +```javascript +$attr('#test', 'attr1', 'test'); +$attr('#test', 'attr1'); // -> test +$attr.remove('#test', 'attr1'); +$attr('#test', { + 'attr1': 'test', + 'attr2': 'test' +}); +``` + +## $class + +Element class manipulations. + +### add + +Add the specified class(es) to each element in the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|names |string array |Classes to add | + +### has + +Determine whether any of the matched elements are assigned the given class. + +|Name |Type |Desc | +|-------|--------------------|-------------------------------------| +|element|string array element|Elements to manipulate | +|name |string |Class name | +|return |boolean |True if elements has given class name| + +### toggle + +Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|name |string |Class name to toggle | + +### remove + +Remove a single class, multiple classes, or all classes from each element in the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|names |string |Class names to remove | + +```javascript +$class.add('#test', 'class1'); +$class.add('#test', ['class1', 'class2']); +$class.has('#test', 'class1'); // -> true +$class.remove('#test', 'class1'); +$class.has('#test', 'class1'); // -> false +$class.toggle('#test', 'class1'); +$class.has('#test', 'class1'); // -> true +``` + +## $css + +Element css manipulation. + +Get the computed style properties for the first element in the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|--------------------------| +|element|string array element|Elements to manipulate | +|name |string |Property name | +|return |string |Css value of first element| + +Set one or more CSS properties for the set of matched elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|name |string |Property name | +|value |string |Css value | + +|Name |Type |Desc | +|----------|--------------------|--------------------------------| +|element |string array element|Elements to manipulate | +|properties|object |Object of css-value pairs to set| + +```javascript +$css('#test', { + 'color': '#fff', + 'background': 'black' +}); +$css('#test', 'display', 'block'); +$css('#test', 'color'); // -> #fff +``` + +## $data + +Wrapper of $attr, adds data- prefix to keys. + +```javascript +$data('#test', 'attr1', 'eustia'); +``` + +## $event + +bind events to certain dom elements. TODO + +```javascript +event.on('#test', 'click', function () +{ + // ... +}); +``` + +## $insert + +Insert html on different position. + +### before + +Insert content before elements. + +### after + +Insert content after elements. + +### prepend + +Insert content to the beginning of elements. + +### append + +Insert content to the end of elements. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to manipulate| +|content|string |Html strings | + +```javascript +//
+$insert.before('#test', '
eris
'); +// ->
eris
+$insert.after('#test', '
eris
'); +// ->
eris
+$insert.prepend('#test', '
eris
'); +// ->
eris
+$insert.append('#test', '
eris
'); +// ->
eris
+``` + +## $offset + +Get the position of the element in document. + +|Name |Type |Desc | +|-------|--------------------|----------------------| +|element|string array element|Elements to get offset| + +```javascript +$offset('#test'); // -> {left: 0, top: 0, width: 0, height: 0} +``` + +## $property + +Element property html, text, val getter and setter. + +### html + +Get the HTML contents of the first element in the set of matched elements or +set the HTML contents of every matched element. + +### text + +Get the combined text contents of each element in the set of matched +elements, including their descendants, or set the text contents of the +matched elements. + +### val + +Get the current value of the first element in the set of matched elements or +set the value of every matched element. + +```javascript +$property.html('#test', 'eris'); +$property.html('#test'); // -> eris +``` + +## $remove + +Remove the set of matched elements from the DOM. + +|Name |Type |Desc | +|-------|--------------------|------------------| +|element|string array element|Elements to delete| + +```javascript +$remove('#test'); +``` + +## $safeEls + +Convert value into an array, if it's a string, do querySelector. + +|Name |Type |Desc | +|------|--------------------|-----------------| +|value |element array string|Value to convert | +|return|array |Array of elements| + +```javascript +$safeEls('.test'); // -> Array of elements with test class +``` + +## $show + +Show elements. + +|Name |Type |Desc | +|-------|--------------------|----------------| +|element|string array element|Elements to show| + +```javascript +$show('#test'); +``` + +## Class + +Create JavaScript class. + +|Name |Type |Desc | +|---------|--------|---------------------------------| +|methods |object |Public methods | +|[statics]|object |Static methods | +|return |function|Function used to create instances| + +```javascript +var People = Class({ + initialize: function (name, age) + { + this.name = name; + this.age = age; + }, + introduce: function () + { + return 'I am ' + this.name + ', ' + this.age + ' years old.'. + } +}); + +var Student = People.extend({ + initialize: function (name, age, school) + { + this.callSuper('initialize', name, age); + + this.school = school. + }, + introduce: function () + { + return this.callSuper('introduce') + '\n I study at ' + this.school + '.'. + } +}, { + is: function (obj) + { + return obj instanceof Student; + } +}); + +var a = new Student('allen', 17, 'Hogwarts'); +a.introduce(); // -> 'I am allen, 17 years old. \n I study at Hogwarts.' +Student.is(a); // -> true +``` + +## Emitter + +Event emitter class which provides observer pattern. + +### on + +Bind event. + +### off + +Unbind event. + +### once + +Bind event that trigger once. + +|Name |Type |Desc | +|--------|--------|--------------| +|event |string |Event name | +|listener|function|Event listener| + +### emit + +Emit event. + +|Name |Type |Desc | +|-------|------|----------------------------| +|event |string|Event name | +|...args|* |Arguments passed to listener| + +### mixin + +[static] Mixin object class methods. + +|Name|Type |Desc | +|----|------|---------------| +|obj |object|Object to mixin| + +```javascript +var event = new Emitter(); +event.on('test', function () { console.log('test') }); +event.emit('test'); // Logs out 'test'. +Emitter.mixin({}); +``` + +## Select + +Simple wrapper of querySelectorAll to make dom selection easier. + +### constructor + +|Name |Type |Desc | +|--------|------|-------------------| +|selector|string|Dom selector string| + +### find + +Get desdendants of current matched elements. + +|Name |Type |Desc | +|--------|------|-------------------| +|selector|string|Dom selector string| + +### each + +Iterate over matched elements. + +|Name|Type |Desc | +|----|--------|------------------------------------| +|fn |function|Function to execute for each element| + +```javascript +var $test = new Select('#test'); +$test.find('.test').each(function (idx, element) +{ + // Manipulate dom nodes +}); +``` + +## allKeys + +Retrieve all the names of object's own and inherited properties. + +|Name |Type |Desc | +|------|------|---------------------------| +|obj |object|Object to query | +|return|array |Array of all property names| + +> Members of Object's prototype won't be retrieved. + +```javascript +var obj = Object.create({zero: 0}); +obj.one = 1; +allKeys(obj) // -> ['zero', 'one'] +``` + +## before + +Create a function that invokes less than n times. + +|Name |Type |Desc | +|------|--------|------------------------------------------------| +|n |number |Number of calls at which fn is no longer invoked| +|fn |function|Function to restrict | +|return|function|New restricted function | + +Subsequent calls to the created function return the result of the last fn invocation. + +```javascript +$(element).on('click', before(5, function() {})); +// -> allow function to be call 4 times at last. +``` + +## camelCase + +Convert string to "camelCase". + +|Name |Type |Desc | +|------|------|------------------| +|str |string|String to convert | +|return|string|Camel cased string| + +```javascript +camelCase('foo-bar'); // -> fooBar +camelCase('foo bar'); // -> fooBar +camelCase('foo_bar'); // -> fooBar +camelCase('foo.bar'); // -> fooBar +``` + +## contain + +Check if the value is present in the list. + +|Name |Type |Desc | +|------|-------|------------------------------------| +|array |array |Target list | +|value |* |Value to check | +|return|boolean|True if value is present in the list| + +```javascript +contain([1, 2, 3], 1); // -> true +``` + +## cookie + +Simple api for handling browser cookies. + +### get + +Get cookie value. + +|Name |Type |Desc | +|------|------|--------------------------| +|key |string|Cookie key | +|return|string|Corresponding cookie value| + +### set + +Set cookie value. + +|Name |Type |Desc | +|---------|-------|--------------| +|key |string |Cookie key | +|val |string |Cookie value | +|[options]|object |Cookie options| +|return |exports|Module cookie | + +### remove + +Remove cookie value. + +|Name |Type |Desc | +|---------|-------|--------------| +|key |string |Cookie key | +|[options]|object |Cookie options| +|return |exports|Module cookie | + +```javascript +cookie.set('a', '1', {path: '/'}); +cookie.get('a'); // -> '1' +cookie.remove('a'); +``` + +## createAssigner + +Used to create extend, extendOwn and defaults. + +|Name |Type |Desc | +|--------|--------|------------------------------| +|keysFn |function|Function to get object keys | +|defaults|boolean |No override when set to true | +|return |function|Result function, extend... | + +## defaults + +Fill in undefined properties in object with the first value present in the following list of defaults objects. + +|Name |Type |Desc | +|------|------|------------------| +|obj |object|Destination object| +|*src |object|Sources objects | +|return|object|Destination object| + +```javascript +defaults({name: 'RedHood'}, {name: 'Unknown', age: 24}); // -> {name: 'RedHood', age: 24} +``` + +## delegate + +TODO + +## each + +Iterates over elements of collection and invokes iteratee for each element. + +|Name |Type |Desc | +|--------|------------|------------------------------| +|obj |object array|Collection to iterate over | +|iteratee|function |Function invoked per iteration| +|[ctx] |* |Function context | + +```javascript +each({'a': 1, 'b': 2}, function (val, key) {}); +``` + +## endWith + +Check if string ends with the given target string. + +|Name |Type |Desc | +|------|-------|-------------------------------| +|str |string |The string to search | +|suffix|string |String suffix | +|return|boolean|True if string ends with target| + +```javascript +endWith('ab', 'b'); // -> true +``` + +## escape + +Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' characters. + +|Name |Type |Desc | +|------|------|----------------| +|str |string|String to escape| +|return|string|Escaped string | + +```javascript +escape('You & Me'); -> // -> 'You & Me' +``` + +## escapeRegExp + +Escape special chars to be used as literals in RegExp constructors. + +|Name |Type |Desc | +|------|------|----------------| +|str |string|String to escape| +|return|string|Escaped string | + +```javascript +escapeRegExp('[eris]'); // -> '\\[eris\\]' +``` + +## evalCss + +No documentation. + +## extend + +Copy all of the properties in the source objects over to the destination object. + +|Name |Type |Desc | +|------|------|------------------| +|obj |object|Destination object| +|*src |object|Sources objects | +|return|object|Destination object| + +```javascript +extend({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24} +``` + +## extendOwn + +Like extend, but only copies own properties over to the destination object. + +|Name |Type |Desc | +|------|------|------------------| +|obj |object|Destination object| +|*src |object|Sources objects | +|return|object|Destination object| + +```javascript +extendOwn({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24} +``` + +## filter + +Iterates over elements of collection, returning an array of all the values that pass a truth test. + +|Name |Type |Desc | +|---------|--------|---------------------------------------| +|obj |array |Collection to iterate over | +|predicate|function|Function invoked per iteration | +|[ctx] |* |Predicate context | +|return |array |Array of all values that pass predicate| + +```javascript +filter([1, 2, 3, 4, 5], function (val) +{ + return val % 2 === 0; +}); // -> [2, 4] +``` + +## get + +No documentation. + +## getFileName + +No documentation. + +## has + +Checks if key is a direct property. + +|Name |Type |Desc | +|------|-------|--------------------------------| +|obj |object |Object to query | +|key |string |Path to check | +|return|boolean|True if key is a direct property| + +```javascript +has({one: 1}, 'one'); // -> true +``` + +## identity + +Return the first argument given. + +|Name |Type|Desc | +|------|----|-----------| +|val |* |Any value | +|return|* |Given value| + +```javascript +identity('a'); // -> 'a' +``` + +## idxOf + +Get the index at which the first occurrence of value. TODO + +|Name |Type |Desc | +|-----------|------|--------------------| +|arr |array |Array to search | +|val |* |Value to search for | +|[fromIdx=0]|number|Index to search from| + +```javascript +idxOf([1, 2, 1, 2], 2, 2); // -> 3 +``` + +## inherits + +Inherit the prototype methods from one constructor into another. + +|Name |Type |Desc | +|----------|--------|-----------| +|Class |function|Child Class| +|SuperClass|function|Super Class| + +```javascript +function People(name) +{ + this._name = name; +} +People.prototype = { + getName: function () + { + return this._name; + } +}; +function Student(name) +{ + this._name = name; +} +inherits(Student, People); +var s = new Student('RedHood'); +s.getName(); // -> 'RedHood' +``` + +## isArgs + +Check if value is classified as an arguments object. + +|Name |Type |Desc | +|------|-------|------------------------------------| +|value |* |Value to check | +|return|boolean|True if value is an arguments object| + +```javascript +(function () { + isArgs(arguments); // -> true +})(); +``` + +## isArr + +Check if value is an `Array` object. + +|Name |Type |Desc | +|------|-------|----------------------------------| +|val |* |The value to check | +|return|boolean|True if value is an `Array` object| + +```javascript +isArr([]); // -> true +isArr({}); // -> false +``` + +## isArrLike + +Check if value is array-like. + +|Name |Type |Desc | +|------|-------|---------------------------| +|value |* |Value to check | +|return|boolean|True if value is array like| + +> Function returns false. + +```javascript +isArrLike('test'); // -> true +isArrLike(document.body.children); // -> true; +isArrLike([1, 2, 3]); // -> true +``` + +## isBool + +Check if value is a boolean primitive. + +|Name |Type |Desc | +|------|-------|--------------------------| +|val |* |Value to check | +|return|boolean|True if value is a boolean| + +```javascript +isBool(true); // -> true +isBool(false); // -> true +isBool(1); // -> false +``` + +## isCrossOrig + +No documentation. + +## isEl + +Check if value is a DOM element. + +|Name |Type |Desc | +|------|-------|------------------------------| +|val |* |Value to check | +|return|boolean|True if value is a DOM element| + +```javascript +isEl(document.body); // -> true +``` + +## isEmpty + +Check if value is an empty object or array. + +|Name |Type |Desc | +|------|-------|----------------------| +|val |* |Value to check | +|return|boolean|True if value is empty| + +```javascript +isEmpty([]); // -> true +isEmpty({}); // -> true +``` + +## isErr + +Check if value is an error. + +|Name |Type |Desc | +|------|-------|-------------------------| +|val |* |Value to check | +|return|boolean|True if value is an error| + +```javascript +isErr(new Error()); // -> true +``` + +## isErudaEl + +No documentation. + +## isFn + +Check if value is a function. + +|Name |Type |Desc | +|------|-------|---------------------------| +|val |* |Value to check | +|return|boolean|True if value is a function| + +Generator function is also classified as true. + +```javascript +isFn(function() {}); // -> true +isFn(function*() {}); // -> true +``` + +## isMatch + +Check if keys and values in src are contained in obj. + +|Name |Type |Desc | +|------|-------|----------------------------------| +|obj |object |Object to inspect | +|src |object |Object of property values to match| +|return|boolean|True if object is match | + +```javascript +isMatch({a: 1, b: 2}, {a: 1}); // -> true +``` + +## isNull + +Check if value is an Null. + +|Name |Type |Desc | +|------|-------|-----------------------| +|value |* |Value to check | +|return|boolean|True if value is an Null| + +```javascript +isNull(null); // -> true +``` + +## isNum + +Checks if value is classified as a Number primitive or object. + +|Name |Type |Desc | +|------|-------|-------------------------------------| +|value |* |Value to check | +|return|boolean|True if value is correctly classified| + +## isObj + +Check if value is the language type of Object. + +|Name |Type |Desc | +|------|-------|--------------------------| +|val |* |Value to check | +|return|boolean|True if value is an object| + +[Language Spec](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) + +```javascript +isObj({}); // -> true +isObj([]); // -> true +``` + +## isRegExp + +Check if value is a regular expression. + +|Name |Type |Desc | +|------|-------|-------------------------------------| +|val |* |Value to check | +|return|boolean|True if value is a regular expression| + +```javascript +isRegExp(/a/); // -> true +``` + +## isStr + +Check if value is a string primitive. + +|Name |Type |Desc | +|------|-------|-----------------------------------| +|val |* |Value to check | +|return|boolean|True if value is a string primitive| + +```javascript +isStr('eris'); // -> true +``` + +## isUndef + +Check if value is undefined. + +|Name |Type |Desc | +|------|-------|--------------------------| +|val |* |Value to check | +|return|boolean|True if value is undefined| + +```javascript +isUndef(void 0); // -> true +isUndef(null); // -> false +``` + +## kebabCase + +Convert string to "kebabCase". + +|Name |Type |Desc | +|------|------|------------------| +|str |string|String to convert | +|return|string|Kebab cased string| + +```javascript +kebabCase('fooBar'); // -> foo-bar +kebabCase('foo bar'); // -> foo-bar +kebabCase('foo_bar'); // -> foo-bar +kebabCase('foo.bar'); // -> foo-bar +``` + +## keys + +Create an array of the own enumerable property names of object. + +|Name |Type |Desc | +|------|------|-----------------------| +|obj |object|Object to query | +|return|array |Array of property names| + +## last + +Get the last element of array. + +|Name |Type |Desc | +|------|-----|-------------------------| +|arr |array|The array to query | +|return|* |The last element of array| + +```javascript +last([1, 2]); // -> 2 +``` + +## loadJs + +Inject script tag into page with given src value. TODO + +## lpad + +Pad string on the left side if it's shorter than length. + +|Name |Type |Desc | +|-------|------|----------------------| +|str |string|String to pad | +|len |number|Padding length | +|[chars]|string|String used as padding| +|return |string|Resulted string | + +```javascript +lpad('a', 5); // -> ' a' +lpad('a', 5, '-'); // -> '----a' +lpad('abc', 3, '-'); // -> 'abc' +lpad('abc', 5, 'ab'); // -> 'ababc' +``` + +## ltrim + +Remove chars or white-spaces from beginning of string. + +|Name |Type |Desc | +|------|------------|------------------| +|str |string |String to trim | +|chars |string array|Characters to trim| +|return|string |Trimmed string | + +```javascript +ltrim(' abc '); // -> 'abc ' +ltrim('_abc_', '_'); // -> 'abc_' +ltrim('_abc_', ['a', '_']); // -> 'bc_' +``` + +## map + +Create an array of values by running each element in collection through iteratee. + +|Name |Type |Desc | +|--------|------------|------------------------------| +|obj |array object|Collection to iterate over | +|iteratee|function |Function invoked per iteration| +|[ctx] |* |Function context | +|return |array |New mapped array | + +```javascript +map([4, 8], function (n) { return n * n; }); // -> [16, 64] +``` + +## matcher + +TODO + +## noop + +A no-operation function. + +```javascript +noop(); // Does nothing +``` + +## now + +Gets the number of milliseconds that have elapsed since the Unix epoch. + +```javascript +now(); // -> 1468826678701 +``` + +## objToStr + +Alias of Object.prototype.toString. + +|Name |Type |Desc | +|------|------|------------------------------------| +|value |* |Source value | +|return|string|String representation of given value| + +```javascript +objToStr(5); // -> '[object Number]' +``` + +## once + +Create a function that invokes once. + +|Name |Type |Desc | +|------|--------|-----------------------| +|fn |function|Function to restrict | +|return|function|New restricted function| + +```javascript +function init() {}; +var initOnce = once(init); +initOnce(); +initOnce(); // -> init is invoked once +``` + +## optimizeCb + +TODO + +## orientation + +No documentation. + +## partial + +Partially apply a function by filling in given arguments. + +|Name |Type |Desc | +|--------|--------|----------------------------------------| +|fn |function|Function to partially apply arguments to| +|partials|...* |Arguments to be partially applied | +|return |function|New partially applied function | + +```javascript +var sub5 = partial(function (a, b) { return b - a }, 5); +sub(20); // -> 15 +``` + +## pxToNum + +No documentation. + +## repeat + +Repeat string n-times. + +|Name |Type |Desc | +|------|------|----------------| +|str |string|String to repeat| +|n |number|Repeat times | +|return|string|Repeated string | + +```javascript +repeat('a', 3); // -> 'aaa' +repeat('ab', 2); // -> 'abab' +repeat('*', 0); // -> '' +``` + +## restArgs + +This accumulates the arguments passed into an array, after a given index. + +|Name |Type |Desc | +|----------|--------|---------------------------------------| +|function |function|Function that needs rest parameters | +|startIndex|number |The start index to accumulates | +|return |function|Generated function with rest parameters| + +```javascript +var paramArr = _.restArgs(function (rest) { return rest }); +paramArr(1, 2, 3, 4); // -> [1, 2, 3, 4] +``` + +## rtrim + +Remove chars or white-spaces from end of string. + +|Name |Type |Desc | +|------|------------|------------------| +|str |string |String to trim | +|chars |string array|Characters to trim| +|return|string |Trimmed string | + +```javascript +rtrim(' abc '); // -> ' abc' +rtrim('_abc_', '_'); // -> '_abc' +rtrim('_abc_', ['c', '_']); // -> '_ab' +``` + +## safeCb + +Create callback based on input value. TODO + +## slice + +Create slice of source array or array-like object. + +|Name |Type |Desc | +|------------------|------|--------------------------| +|array |array |Array to slice | +|[start=0] |number|Start position | +|[end=array.length]|number|End position, not included| + +```javascript +slice([1, 2, 3, 4], 1, 2); // -> [2] +``` + +## some + +Check if predicate return truthy for any element. + +|Name |Type |Desc | +|---------|------------|----------------------------------------------| +|obj |array object|Collection to iterate over | +|predicate|function |Function to invoked per iteration | +|ctx |* |Predicate context | +|return |boolean |True if any element passes the predicate check| + +```javascript +some([2, 5], function (val) +{ + return val % 2 === 0; +}); // -> true +``` + +## splitCase + +Split different string case to an array. + +|Name |Type |Desc | +|------|------|---------------| +|str |string|String to split| +|return|array |Result array | + +```javascript +splitCase('foo-bar'); // -> ['foo', 'bar'] +splitCase('foo bar'); // -> ['foo', 'bar'] +splitCase('foo_bar'); // -> ['foo', 'bar'] +splitCase('foo.bar'); // -> ['foo', 'bar'] +splitCase('fooBar'); // -> ['foo', 'bar'] +splitCase('foo-Bar'); // -> ['foo', 'bar'] +``` + +## startWith + +Check if string starts with the given target string. + +|Name |Type |Desc | +|------|-------|---------------------------------| +|str |string |String to search | +|prefix|string |String prefix | +|return|boolean|True if string starts with prefix| + +```javascript +startWith('ab', 'a'); // -> true +``` + +## stripHtmlTag + +Strip html tags from a string. + +|Name |Type |Desc | +|------|------|---------------| +|str |string|String to strip| +|return|string|Resulted string| + +```javascript +stripHtmlTag('

Hello

'); // -> 'Hello' +``` + +## toArr + +Convert value to an array. + +|Name |Type |Desc | +|------|-----|----------------| +|val |* |Value to convert| +|return|array|Converted array | + +```javascript +toArr({a: 1, b: 2}); // -> [{a: 1, b: 2}] +toArr('abc'); // -> ['abc'] +toArr(1); // -> [] +toArr(null); // -> [] +``` + +## toInt + +Convert value to an integer. + +|Name |Type |Desc | +|------|------|-----------------| +|val |* |Value to convert | +|return|number|Converted integer| + +```javascript +toInt(1.1); // -> 1 +``` + +## toNum + +Convert value to a number. + +|Name |Type |Desc | +|------|------|----------------| +|val |* |Value to process| +|return|number|Resulted number | + +```javascript +toNum('5'); // -> 5 +``` + +## toStr + +Convert value to a string. + +|Name |Type |Desc | +|------|------|----------------| +|val |* |Value to convert| +|return|string|Resulted string | + +```javascript +toStr(null); // -> '' +toStr(1); // -> '1' +toStr(false); // -> 'false' +toStr([1, 2, 3]); // -> '1,2,3' +``` + +## trim + +Remove chars or white-spaces from beginning end of string. + +|Name |Type |Desc | +|------|------------|------------------| +|str |string |String to trim | +|chars |string array|Characters to trim| +|return|string |Trimmed string | + +```javascript +trim(' abc '); // -> 'abc' +trim('_abc_', '_'); // -> 'abc' +trim('_abc_', ['a', 'c', '_']); // -> 'b' +``` + +## uniqId + +Generate a globally-unique id. + +|Name |Type |Desc | +|------|------|------------------| +|prefix|string|Id prefix | +|return|string|Globally-unique id| + +```javascript +uniqueId('eusita_'); // -> 'eustia_xxx' +``` + +## unique + +Create duplicate-free version of an array. + +|Name |Type |Desc | +|---------|--------|-----------------------------| +|arr |array |Array to inspect | +|[compare]|function|Function for comparing values| +|return |array |New duplicate free array | + +```javascript +unique([1, 2, 3, 1]); // -> [1, 2, 3] +``` + +## upperFirst + +Convert the first character of string to upper case. + +|Name |Type |Desc | +|------|------|-----------------| +|str |string|String to convert| +|return|string|Converted string | + +```javascript +upperFirst('red'); // -> RED +``` + +## values + +Creates an array of the own enumerable property values of object. + +|Name |Type |Desc | +|------|------|------------------------| +|obj |object|Object to query | +|return|array |Array of property values| + +```javascript +values({one: 1, two: 2}); // -> [1, 2] +```