瀏覽代碼

add jsdoc comments

mightyplow 7 年之前
父節點
當前提交
f53261299a

+ 4 - 0
src/array/_checkArray.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf array
+ * @param val
+ */
 const checkArray = val => {
     if (!Array.isArray(val)) {
         throw Error('value must be an array');

+ 4 - 0
src/array/ensureArray.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf array
+ * @param val
+ */
 const ensureArray = (val = []) => Array.isArray(val) ? val : [val];
 
 export default ensureArray;

+ 5 - 0
src/array/flatten.js

@@ -1,5 +1,10 @@
 import checkArray  from './_checkArray';
 
+/**
+ * @memberOf array
+ * @param ar
+ * @return {*}
+ */
 export default (ar) => {
     checkArray(ar);
 

+ 5 - 0
src/array/head.js

@@ -1,5 +1,10 @@
 import checkArray from "./_checkArray";
 
+/**
+ * @memberOf array
+ * @param ar
+ * @return {*}
+ */
 const head = (ar) => {
     checkArray(ar);
 

+ 3 - 0
src/array/index.js

@@ -1,3 +1,6 @@
+/**
+ * @namespace array
+ */
 export { default as ensureArray} from './ensureArray';
 export { default as flatten } from './flatten';
 export { default as head } from './head';

+ 5 - 0
src/array/tail.js

@@ -1,5 +1,10 @@
 import checkArray from "./_checkArray";
 
+/**
+ * @memberOf array
+ * @param ar
+ * @return {T}
+ */
 const tail = (ar) => {
     checkArray(ar);
 

+ 4 - 0
src/array/toArray.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf array
+ * @param arraylike
+ */
 const toArray = (arraylike = []) => [...arraylike];
 
 export default toArray;

+ 4 - 0
src/array/unique.js

@@ -1,5 +1,9 @@
 import checkArray from "./_checkArray";
 
+/**
+ * @memberOf array
+ * @param ar
+ */
 export default (ar) => {
     checkArray(ar);
     return ar.filter((val, i, input) => i === input.indexOf(val));

+ 6 - 8
src/function/argsToArray.js

@@ -1,10 +1,8 @@
-import toArray from "../array/toArray";
-
-const argsToArray = fn => {
-    // must not be a fat arrow since it breaks the arguments
-    return function () {
-        return fn(toArray(arguments));
-    };
-};
+/**
+ * @memberOf function
+ * @param fn
+ * @return {Function}
+ */
+const argsToArray = fn => (...args) => fn(args);
 
 export default argsToArray;

+ 4 - 0
src/function/combine.js

@@ -1,5 +1,9 @@
 import argsToArray from './argsToArray';
 
+/**
+ * @memberOf function
+ * @type {Function}
+ */
 const combine = argsToArray(fns => fns.reverse().reduce((fnc, fn) => val => fnc(fn(val))));
 
 export default combine;

+ 5 - 0
src/function/curry.js

@@ -1,3 +1,8 @@
+/**
+ * @memberOf function
+ * @param fn
+ * @return {curried}
+ */
 const curry = fn => {
     return function curried (...args) {
         const that = this;

+ 2 - 0
src/function/enqueue.js

@@ -1,5 +1,7 @@
 /**
  returns a function which executes promises one after another
+
+ @memberOf function
  @param promiseGenerators an array of functions which return a promise
  @return function which executes the promises
  */

+ 2 - 0
src/function/enqueueWithResults.js

@@ -1,6 +1,8 @@
 /**
  Returns a function which executes promises one after another. The resulting function
  returns a promise, which gets filled with an array of the results of the single promises.
+
+ @memberOf function
  @param promiseGenerators an array of functions which return a promise
  @return function which executes the promises
  */

+ 7 - 1
src/function/identity.js

@@ -1 +1,7 @@
-export default arg => arg;
+/**
+ * @memberOf function
+ * @param arg
+ */
+const indentity = arg => arg;
+
+export default indentity;

+ 3 - 0
src/function/index.js

@@ -1,3 +1,6 @@
+/**
+ * @namespace function
+ */
 export { default as argsToArray } from './argsToArray';
 export { default as combine } from './combine';
 export { default as curry } from './curry';

+ 6 - 1
src/function/noop.js

@@ -1 +1,6 @@
-export default Function.prototype
+/**
+ * @memberOf function
+ */
+const noop = Function.prototype;
+
+export default noop

+ 6 - 0
src/function/promisify.js

@@ -1,5 +1,11 @@
+/**
+ * @memberOf function
+ * @param fn
+ * @param context
+ */
 // cannot use fat arrow function since we don't get the arguments, then
 const promisify = (fn, context = null) => function () {
+
     // copy passed arguments to a new array
     const args = toArray(arguments);
 

+ 6 - 0
src/html/createLinkTag.js

@@ -1,3 +1,9 @@
+/**
+ * @memberOf html
+ * @param filename
+ * @param mediaQuery
+ * @return {string}
+ */
 const createLinkTag = (filename, mediaQuery) => {
     if (mediaQuery) {
         return `<link rel="stylesheet" type="text/css" href="${filename}" media="${mediaQuery}" />`;

+ 3 - 0
src/html/index.js

@@ -1 +1,4 @@
+/**
+ * @namespace html
+ */
 export { default as createLinkTag } from './createLinkTag';

+ 1 - 0
src/object/defaults.js

@@ -1,6 +1,7 @@
 /**
  * Populates an object with default values.
  *
+ * @memberOf object
  * @param {Object} obj - the object to populate the values on
  * @param {Object} values - the default values to populate on the target object
  * @return {Object} a new object with the default values and the object values

+ 6 - 0
src/object/filter.js

@@ -1,3 +1,9 @@
+/**
+ * @memberOf object
+ * @param obj
+ * @param pred
+ * @return {*}
+ */
 const filter = (obj, pred) => {
     return Object.keys(obj).reduce((filtered, key) => {
         const value = obj[key];

+ 7 - 4
src/object/fromArray.js

@@ -1,16 +1,17 @@
+import checkArray from '../array/_checkArray';
+
 /**
  * Receives an array of objects and extracts an object with the given key as index. The key
  * must be a property of the array items. If the property is not found on the item, the item
  * is omitted.
  *
+ * @memberOf object
  * @param {Object[]} array
  * @param {string} key
  * @param {boolean} keep - should the extracted prop be kept in the result object
  * @returns {*}
  */
-import checkArray from '../array/_checkArray';
-
-export default (array, key, keep = true) => {
+const fromArray = (array, key, keep = true) => {
     checkArray(array);
 
     if (!(typeof key === 'string')) {
@@ -27,4 +28,6 @@ export default (array, key, keep = true) => {
         object[prop] = keep ? item : rest;
         return object;
     }, {});
-};
+};
+
+export default fromArray;

+ 3 - 0
src/object/index.js

@@ -1,3 +1,6 @@
+/**
+ * @namespace object
+ */
 export { default as defaults } from './defaults';
 export { default as fromArray } from './fromArray';
 export { default as filter } from './filter';

+ 2 - 1
src/object/prop.js

@@ -1,8 +1,9 @@
 /**
  * Creates a function which returns a property of a passed object.
  *
+ * @memberOf object
  * @param {string} prop - the property to return from the passed object
- * @return {function(obj: Object)} function to return a property from a passed object
+ * @return {function({object})} function to return a property from a passed object
  */
 const prop = prop => obj => obj[prop];
 

+ 5 - 0
src/string/append.js

@@ -1,3 +1,8 @@
+/**
+ * @memberOf string
+ * @param str
+ * @param append
+ */
 const append = (str, append) => str + append;
 
 export default append;

+ 5 - 0
src/string/ciCompare.js

@@ -1,3 +1,8 @@
+/**
+ * @memberOf string
+ * @param val1
+ * @param val2
+ */
 const ciCompare = (val1 = '', val2 = '') => val1.toLowerCase() === val2.toLowerCase();
 
 export default ciCompare;

+ 3 - 0
src/string/index.js

@@ -1,3 +1,6 @@
+/**
+ * @namespace string
+ */
 export { default as append } from './append';
 export { default as ciCompare } from './ciCompare';
 export { default as toBool } from './toBool';

+ 4 - 0
src/string/toBool.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf string
+ * @param val
+ */
 const toBool = val => val === 'true';
 
 export default toBool;

+ 5 - 0
src/stylesheet/createStylesheetAst.js

@@ -1,3 +1,8 @@
+/**
+ * @memberOf stylesheet
+ * @param rules
+ * @return {{type: string, stylesheet: {rules: *}}}
+ */
 const createStylesheetAst = rules => {
     return {
         type: 'stylesheet',

+ 4 - 0
src/stylesheet/getRules.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf stylesheet
+ * @param css
+ */
 const getRules = css => css.stylesheet.rules;
 
 export default getRules;

+ 3 - 0
src/stylesheet/index.js

@@ -1,3 +1,6 @@
+/**
+ * @namespace stylesheet
+ */
 export { default as createStylesheetAst } from './createStylesheetAst';
 export { default as getRules } from './getRules';
 export { default as isRuleType } from './isRuleType';

+ 4 - 0
src/stylesheet/isRuleType.js

@@ -1,3 +1,7 @@
+/**
+ * @memberOf stylesheet
+ * @param type
+ */
 const isRuleType = type => rule => rule.type === type;
 
 export default isRuleType;