seeq
Version:
Search or detect name on some resource (GitHub, NPM, Bower, ...)
418 lines (336 loc) • 11.9 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>seeq Source: resource/util.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.spacelab.css">
</head>
<body>
<div class="container-fluid">
<div class="navbar navbar-fixed-top ">
<div class="navbar-inner">
<a class="brand" href="index.html">seeq</a>
<ul class="nav">
<li class="dropdown">
<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="module-bower.html">bower</a>
</li>
<li>
<a href="module-cdn.html">cdn</a>
</li>
<li>
<a href="module-cdnjs.html">cdnjs</a>
</li>
<li>
<a href="module-cli.html">cli</a>
</li>
<li>
<a href="module-component.html">component</a>
</li>
<li>
<a href="module-customelements.html">customelements</a>
</li>
<li>
<a href="module-format.html">format</a>
</li>
<li>
<a href="util.html">format/util</a>
</li>
<li>
<a href="module-github.html">github</a>
</li>
<li>
<a href="module-grunt.html">grunt</a>
</li>
<li>
<a href="module-gulp.html">gulp</a>
</li>
<li>
<a href="module-jam.html">jam</a>
</li>
<li>
<a href="module-jsdelivr.html">jsdelivr</a>
</li>
<li>
<a href="module-json.html">json</a>
</li>
<li>
<a href="module-jster.html">jster</a>
</li>
<li>
<a href="module-markdown.html">markdown</a>
</li>
<li>
<a href="module-microjs.html">microjs</a>
</li>
<li>
<a href="module-npm.html">npm</a>
</li>
<li>
<a href="module-raw.html">raw</a>
</li>
<li>
<a href="module-resource.html">resource</a>
</li>
<li>
<a href="util_.html">resource/util</a>
</li>
<li>
<a href="module-seeq.html">seeq</a>
</li>
<li>
<a href="module-spm.html">spm</a>
</li>
<li>
<a href="module-text.html">text</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="util-FailedHttpRequestError.html">FailedHttpRequestError</a>
</li>
<li>
<a href="util-IncorrectResponseError.html">IncorrectResponseError</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: resource/util.js</h1>
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* Helper functions.
*
* @module resource/util
*/
var he = require("he"),
util = require("util");
/**
* Decode HTML entities in given string.
*
* @param {String} str
* String that should be processed.
* @return {String}
* Decoded string.
*/
exports.decodeHtmlEntity = function(str) {
return he.decode(str);
};
/**
* Return value of <code>limit</code> setting.
*
* Default value will be returned if <code>limit</code> field is not present in <code>settings</code> parameter.
*
* @param {Object} [settings]
* Operation settings. The object can have numeric <code>limit</code> field which value will be returned
* if the value is positive number and not greater than maximum value.
* Otherwise value of <code>defaultValue</code> parameter will be returned.
* @param {Number} [defaultValue]
* Default value of limit. <code>maxValue</code> is used when parameter value is not passed or 0.
* @param {Number} [maxValue]
* Maximum value of limit. <code>Number.MAX_VALUE</code> is used when parameter value is not passed.
* @return {Number}
* Value that corresponds to <code>limit</code> setting.
*/
exports.getLimit = function(settings, defaultValue, maxValue) {
/*jshint laxbreak:true*/
var nLimit = settings ? settings.limit : null;
if (! maxValue) {
maxValue = Number.MAX_VALUE;
}
return typeof nLimit === "number" && nLimit > 0 && nLimit <= maxValue
? nLimit
: defaultValue || maxValue;
};
/**
* Determine whether search should be made instead of check according to operation settings.
*
* @param {Object} [settings]
* Operation settings.
* The following settings are used to specify real search (name - type - description):
<ul>
<li><code>search</code> - <code>Boolean</code> - Whether search should be made instead of check
</ul>
* @return {Boolean}
* <code>true</code> if real search should be made according to settings,
* <code>false</code> otherwise.
*/
exports.isRealSearchSet = function(settings) {
return Boolean( settings && settings.search );
};
/**
* Check whether search should be made according to operation settings.
*
* @param {Object} [settings]
* Operation settings.
* The following settings are used to specify search (name - type - description):
<ul>
<li><code>caseSensitive</code> - <code>Boolean</code> - Whether case-sensitive check/search should be used
<li><code>partialMatch</code> - <code>Integer</code> - Allow partial matching: 0 - disallow (by default),
1 - allow at the beginning of matching strings, 2 - allow substring matching
<li><code>search</code> - <code>Boolean</code> - Whether search should be made instead of check
</ul>
* @return {Boolean}
* <code>true</code> if search should be made according to settings,
* <code>false</code> otherwise.
*/
exports.isSearchSet = function(settings) {
return Boolean( settings && (settings.caseSensitive || settings.partialMatch || settings.search) );
};
/**
* Check whether one of given strings is similar to the searched string.
*
* @param {Array | String} value
* String or array of strings that should be checked.
* @param {String} searchValue
* Value that is searched for.
* @param {Object} [settings]
* Operation settings.
* The following settings are supported (name - type - description):
<ul>
<li><code>caseSensitive</code> - <code>Boolean</code> - Whether case-sensitive check should be used
<li><code>partialMatch</code> - <code>Integer</code> - Allow partial matching: 0 - disallow (by default),
1 - allow at the beginning of matching strings, 2 - allow substring matching
<li><code>search</code> - <code>Boolean</code> - Whether search should be made instead of check
</ul>
* @return {Boolean}
* <code>true</code> if one of given strings is similar to the searched string according to settings,
* <code>false</code> otherwise.
*/
exports.isStringMatch = function(value, searchValue, settings) {
/*jshint laxbreak:true*/
if (! Array.isArray(value)) {
value = [value];
}
if (! settings) {
settings = {};
}
var bInsensitive = ! settings.caseSensitive,
nPartMatch = "partialMatch" in settings
? settings.partialMatch
: (settings.search ? 2 : 0),
nL = value.length,
item, nI, nP;
if (bInsensitive) {
searchValue = searchValue.toLowerCase();
}
for (nI = 0; nI < nL; nI++) {
item = value[nI];
if (bInsensitive) {
item = item.toLowerCase();
}
if ((! nPartMatch && item === searchValue)
|| (nPartMatch && (nP = item.indexOf(searchValue)) > -1 && (nPartMatch > 1 || nP === 0))) {
return true;
}
}
return false;
};
/**
* Class for errors of failed HTTP requests.
*
* @param {http.IncomingMessage} response
* Represents data about response.
* @param {String} [message]
* Error message.
* @constructor
*/
function FailedHttpRequestError(response, message) {
Error.call(this, message || "Http request failed");
this.response = response;
}
util.inherits(FailedHttpRequestError, Error);
exports.FailedHttpRequestError = FailedHttpRequestError;
/**
* Class for errors of incorrect response data.
*
* @param {String} responseData
* Received response data.
* @param {String} [message]
* Error message.
* @constructor
*/
function IncorrectResponseError(responseData, message) {
Error.call(this, message || "Incorrect response data");
this.responseData = responseData;
}
util.inherits(IncorrectResponseError, Error);
exports.IncorrectResponseError = IncorrectResponseError;
/**
* Return object that represents data about error of HTTP request.
* <br>
* If <code>err</code> parameter is set then it will be returned.
* Otherwise instance of {@link resource/util.FailedHttpRequestError FailedHttpRequestError} will be returned.
*
* @param {Error} err
* Represents data about error.
* @param {http.IncomingMessage} response
* Represents data about response.
* @return {Error}
* Error object.
*/
exports.getHttpRequestError = function(err, response) {
/*jshint laxbreak:true*/
return err
? err
: new FailedHttpRequestError(response);
};
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
Copyright (c) 2014 Denis Sikuler
</span>
<br />
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a>
on Thu Aug 21 2014 23:46:51 GMT+0400 (MSK) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>
<br clear="both">
</div>
</div>
<script src="scripts/sunlight.js"></script>
<script src="scripts/sunlight.javascript.js"></script>
<script src="scripts/sunlight-plugin.doclinks.js"></script>
<script src="scripts/sunlight-plugin.linenumbers.js"></script>
<script src="scripts/sunlight-plugin.menu.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.scrollTo.js"></script>
<script src="scripts/jquery.localScroll.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
<script>
$( function () {
$( "#toc" ).toc( {
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
</script>
</body>
</html>