UNPKG

seeq

Version:

Search or detect name on some resource (GitHub, NPM, Bower, ...)

468 lines (379 loc) 15.3 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>seeq Source: seeq.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: seeq.js</h1> <section> <article> <pre class="sunlight-highlight-javascript linenums">/* * seeq * https://github.com/gamtiq/seeq * * Copyright (c) 2014 Denis Sikuler * Licensed under the MIT license. */ /** * Detect whether a name is registered or present on some resource, or make search for string on specified resources. * * @module seeq */ "use strict"; var mixing = require("mixing"), resourceLib = require("./resource"), resourceUtil = require("./resource/util"); function getCheckNameCallback(resource, position, callback) { return function(err, result) { callback(err, result, resource, position); }; } /** * Check existence of name or search for given string on specified resources. * * Result of checking/searching will be passed into callback as object. * Each field of the object is name of resource that was checked/searched. * Value of result's field is object with the following fields (name - type - description): &lt;ul> &lt;li>&lt;code>name&lt;/code> - &lt;code>String&lt;/code> - resource name &lt;li>&lt;code>description&lt;/code> - &lt;code>String&lt;/code> - resource description &lt;li>&lt;code>url&lt;/code> - &lt;code>String&lt;/code> - URL of resource &lt;li>&lt;code>query&lt;/code> - &lt;code>String&lt;/code> - name/string that was checked/searched &lt;li>&lt;code>result&lt;/code> - &lt;code>Array&lt;/code> - result that was received from resource; each item in the array is object that represents data about found element &lt;li>&lt;code>error&lt;/code> - &lt;code>Object | String&lt;/code> - error that was got while checking resource; this field is present only when there was an error &lt;/ul> * * &lt;code>null&lt;/code> will be passed into callback when the name is not given or resources with specified names are not found. * * @param {String} name * The name that should be checked/searched. * @param {Function} callback * Function that should be called to process operation's result. * @param {Object} [settings] * Operation settings. The following settings are supported (name - type - description): &lt;ul> &lt;li>&lt;code>progressCallback&lt;/code> - &lt;code>Function&lt;/code> - function that should be called after getting result from each resource; object with the following fields will be passed into callback: &lt;ul> &lt;li>&lt;code>name&lt;/code> - &lt;code>String&lt;/code> - name that was checked/searched &lt;li>&lt;code>resource&lt;/code> - &lt;code>String&lt;/code> - resource that was checked &lt;li>&lt;code>result&lt;/code> - &lt;code>Object&lt;/code> - result of checking/searching (see above) &lt;li>&lt;code>number&lt;/code> - &lt;code>Integer&lt;/code> - index number of checking/searching &lt;li>&lt;code>total&lt;/code> - &lt;code>Integer&lt;/code> - total number of checks/searches &lt;li>&lt;code>error&lt;/code> - &lt;code>Object | String&lt;/code> - error that was got while checking/searching resource; this field is present only when there was an error &lt;/ul> &lt;li>&lt;code>resource&lt;/code> - &lt;code>Array | String&lt;/code> - specifies filter for available resources by name; list of names of resources or name of resource (case-insensitive) that should be checked/searched &lt;li>&lt;code>resourceTag&lt;/code> - &lt;code>Array | String&lt;/code> - specifies filter for available resources by tag; list of tags or tag (case-insensitive) that should be used to select resources; resources that satisfy to specified tags (depending on &lt;code>checkAllTags&lt;/code> setting) will be checked/searched; see {@link module:resource.checkResourceTags checkResourceTags} for details &lt;li>&lt;code>checkAllTags&lt;/code> - &lt;code>Boolean&lt;/code> - whether all tags specified in &lt;code>resourceTag&lt;/code> should be used to select resources; see {@link module:resource.checkResourceTags checkResourceTags} for details &lt;li>&lt;code>search&lt;/code> - &lt;code>Boolean&lt;/code> - whether search should be made instead of check; it is used only when &lt;code>search&lt;/code> setting for a resource is not specified (see below) &lt;li>&lt;code>settings&lt;/code> - &lt;code>Object&lt;/code> - settings for resources usage; fields are resource identifiers, values are objects representing settings for the corresponding resources; value of &lt;code>_general&lt;/code> field can be used to specify settings that should be applied to all resources &lt;/ul> Filter by name (&lt;code>resource&lt;/code>) and filter by tag (&lt;code>resourceTag&lt;/code>) can be used separately or together. If no filter is specified, all resources will be checked/searched. * @alias module:seeq.searchName */ function searchName(name, callback, settings) { /*jshint laxbreak:true*/ // Gather results from resources function resultCallback(err, result, resource, position) { /*jshint boss:true*/ var sResourceName = resource.name, data, item, nI, nK, resultMap; nC--; item = resultList[position] = { name: sResourceName, description: resource.description, url: resource.url, query: name, result: result }; if (err) { item.error = err; } if (settings.progressCallback) { data = { name: name, resource: sResourceName, result: item, number: nTotal - nC, total: nTotal }; if (err) { data.error = err; } settings.progressCallback(data); } if (nC === 0) { // Form result resultMap = {}; for (nI = 0, nK = resultList.length; nI &lt; nK; nI++) { if (resource = resultList[nI]) { resultMap[resource.name] = resource; } } callback(resultMap); } } var resultList = [], api, generalSettings, nC, nI, nTotal, realSettings, resource, resourceList, resourceSettings; if (! settings) { settings = {}; } resourceSettings = settings.settings || {}; generalSettings = resourceSettings._general; resourceList = resourceLib.getList({ selectName: settings.resource, selectTag: settings.resourceTag, checkAllTags: settings.checkAllTags, includeApi: true }); if (name && (nC = resourceList.length)) { // Request data from resources for (nI = 0, nTotal = nC; nI &lt; nTotal; nI++) { resource = resourceList[nI]; realSettings = generalSettings ? mixing({}, [resourceSettings[resource.id], generalSettings]) : (resourceSettings[resource.id] || {}); if (! ("search" in realSettings) && ("search" in settings)) { realSettings.search = settings.search; } api = resource.api; api[resourceUtil.isRealSearchSet(realSettings) && typeof api.search === "function" ? "search" : "detect"] (name, getCheckNameCallback(resource, nI, resultCallback), realSettings); } } else { callback(null); } } /** * Check existence of each name from the list on specified resources * or search for each string on specified resources. * * Result of checking/searching will be passed into callback as object. * Each field of the object is a name that was checked/searched. * Value of result's field is object that is returned by {@link module:seeq.searchName searchName} function. * * &lt;code>null&lt;/code> will be passed into callback when no name is specified to check/search. * * @param {Array | String} names * The list of names or a name that should be checked/searched. * @param {Function} callback * Function that should be called to process operation's result. * @param {Object} [settings] * Operation settings. See {@link module:seeq.searchName searchName} for details. * @alias module:seeq.search */ function search(names, callback, settings) { /*jshint boss:true*/ // Notify about operation progress function searchNameProgress(data) { data.number += data.total * nI; data.total *= nK; progressCallback(data); } // Gather results for each name function resultCallback(result) { resultMap[ names[nI] ] = result; nI++; if (nI &lt; nK) { // Get results for the next name searchName(names[nI], resultCallback, settings); } else { // Return collected data callback(resultMap); } } var progressCallback = settings && settings.progressCallback, resultMap = {}, nI, nK; if (names && typeof names === "string") { names = [names]; } if (names && (nK = names.length)) { if (progressCallback) { settings = mixing({progressCallback: searchNameProgress}, settings, {except: "progressCallback"}); } // Get results for the first name searchName(names[nI = 0], resultCallback, settings); } else { callback(null); } } // Exports exports.search = search; exports.searchName = searchName; /** * Reference to {@link module:resource resource} module. */ exports.resource = resourceLib; /** * Reference to {@link module:format format} module. */ exports.format = require("./format"); </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>