From 249666a2065b867fa8af2724e16340d69f5ee0ad Mon Sep 17 00:00:00 2001 From: Ardalan Amini Date: Fri, 1 Jun 2018 17:07:17 +0430 Subject: [PATCH] Update version to `0.10.0` --- API.md | 168 +++++++++++++++++++-------------- CHANGELOG.md | 4 +- lib/globals/intex.ts | 2 +- lib/globals/isBrowser/index.ts | 2 +- package-lock.json | 14 +-- package.json | 6 +- 6 files changed, 111 insertions(+), 85 deletions(-) diff --git a/API.md b/API.md index 65c40ac8..9ab120a0 100644 --- a/API.md +++ b/API.md @@ -9,6 +9,8 @@
Function : object
+
global : object
+
Math : object
Number : object
@@ -32,7 +34,7 @@ * [.all([fn])](#Array+all) ⇒ boolean * [.any([fn])](#Array+any) ⇒ boolean * [.append(value)](#Array+append) - * [.average([key])](#Array+average) ⇒ number + * [.average([path])](#Array+average) ⇒ number * [.chunk(size)](#Array+chunk) ⇒ [Array.<Array>](#Array) * [.clone()](#Array+clone) ⇒ [Array](#Array) * [.compact()](#Array+compact) ⇒ [Array](#Array) @@ -49,26 +51,26 @@ * [.flatten([depth])](#Array+flatten) ⇒ [Array](#Array) * [.get(index, [def])](#Array+get) ⇒ \* * [.groupBy(fn)](#Array+groupBy) ⇒ [Object](#Object) - * [.implode(key, [separator])](#Array+implode) ⇒ [String](#String) + * [.implode(path, [separator])](#Array+implode) ⇒ [String](#String) * [.indexOfAll(value)](#Array+indexOfAll) ⇒ Array.<number> * [.initial()](#Array+initial) ⇒ [Array](#Array) * [.intersect(array)](#Array+intersect) ⇒ [Array](#Array) * [.last()](#Array+last) ⇒ \* * [.limit([limit])](#Array+limit) ⇒ [Array](#Array) - * [.max([key])](#Array+max) ⇒ number - * [.median()](#Array+median) ⇒ [Array](#Array) - * [.min([key])](#Array+min) ⇒ number + * [.max([path])](#Array+max) ⇒ number + * [.median([path])](#Array+median) ⇒ number + * [.min([path])](#Array+min) ⇒ number * [.nest(id, link)](#Array+nest) ⇒ [Array.<Object>](#Object) * [.orderBy([field], [order])](#Array+orderBy) ⇒ [Array](#Array) * [.pad(size, [value])](#Array+pad) ⇒ [Array](#Array) * [.partition(fn)](#Array+partition) ⇒ [Array](#Array) - * [.pluck(key)](#Array+pluck) ⇒ [Array](#Array) + * [.pluck(path)](#Array+pluck) ⇒ [Array](#Array) * [.prepend(value)](#Array+prepend) * [.pull(args)](#Array+pull) * [.sample()](#Array+sample) ⇒ \* * [.shuffle()](#Array+shuffle) ⇒ [Array](#Array) * [.skip([offset])](#Array+skip) ⇒ [Array](#Array) - * [.sum([key])](#Array+sum) ⇒ number + * [.sum([path])](#Array+sum) ⇒ number * [.tail()](#Array+tail) ⇒ [Array](#Array) * [.union(array)](#Array+union) ⇒ [Array](#Array) * [.where(field, [operator], [value])](#Array+where) ⇒ [Array](#Array) @@ -83,7 +85,6 @@ * [.zip(array)](#Array+zip) ⇒ [Array](#Array) * [.zipObject(array)](#Array+zipObject) ⇒ [Array](#Array) * _static_ - * [.isInstance](#Array.isInstance) ⇒ boolean * [.range](#Array.range) ⇒ Array.<number> * [.repeat](#Array.repeat) ⇒ [Array](#Array) @@ -96,7 +97,7 @@ An alias of Array.prototype.average | Param | Type | | --- | --- | -| [key] | [String](#String) | +| [path] | [String](#String) | **Example** ```javascript @@ -185,14 +186,14 @@ myArray.append(0); // myArray => [1, 2, 3, 0] ``` -### array.average([key]) ⇒ number -Returns the average value of a given key +### array.average([path]) ⇒ number +Returns the average value of a given path **Kind**: instance method of [Array](#Array) | Param | Type | | --- | --- | -| [key] | [String](#String) | +| [path] | [String](#String) | **Example** ```javascript @@ -417,14 +418,14 @@ Groups the elements of an array based on the given function ``` -### array.implode(key, [separator]) ⇒ [String](#String) +### array.implode(path, [separator]) ⇒ [String](#String) It's like join but u get to git it which keys to join **Kind**: instance method of [Array](#Array) | Param | Type | Default | | --- | --- | --- | -| key | [String](#String) | | +| path | [String](#String) | | | [separator] | [String](#String) | ", " | **Example** @@ -499,14 +500,14 @@ limits the array ``` -### array.max([key]) ⇒ number -Returns the maximum value of a given key +### array.max([path]) ⇒ number +Returns the maximum value of a given path **Kind**: instance method of [Array](#Array) | Param | Type | | --- | --- | -| [key] | [String](#String) | +| [path] | [String](#String) | **Example** ```javascript @@ -516,10 +517,15 @@ Returns the maximum value of a given key ``` -### array.median() ⇒ [Array](#Array) -Returns the median value of a given key +### array.median([path]) ⇒ number +Returns the median value of a given path **Kind**: instance method of [Array](#Array) + +| Param | Type | +| --- | --- | +| [path] | string | + **Example** ```javascript [1, 1, 2, 4].median(); // 1.5 @@ -527,14 +533,14 @@ Returns the median value of a given key ``` -### array.min([key]) ⇒ number -Returns the minimum value of a given key +### array.min([path]) ⇒ number +Returns the minimum value of a given path **Kind**: instance method of [Array](#Array) | Param | Type | | --- | --- | -| [key] | [String](#String) | +| [path] | [String](#String) | **Example** ```javascript @@ -621,14 +627,14 @@ users.partition(o => o.active); // [ ``` -### array.pluck(key) ⇒ [Array](#Array) -Returns all of the values for the given key +### array.pluck(path) ⇒ [Array](#Array) +Returns all of the values for the given path **Kind**: instance method of [Array](#Array) | Param | Type | | --- | --- | -| key | string | +| path | string | **Example** ```javascript @@ -705,14 +711,14 @@ skips the array ``` -### array.sum([key]) ⇒ number -Returns the minimum value of a given key +### array.sum([path]) ⇒ number +Returns the minimum value of a given path **Kind**: instance method of [Array](#Array) | Param | Type | | --- | --- | -| [key] | [String](#String) | +| [path] | [String](#String) | **Example** ```javascript @@ -933,22 +939,6 @@ Creates an array of elements, grouped based on the position in the original arra ['a', 'b', 'c'].zipObject([1, 2]); // {a: 1, b: 2, c: undefined} ['a', 'b'].zipObject([1, 2, 3]); // {a: 1, b: 2} ``` - - -### Array.isInstance ⇒ boolean -An alias of Array.isArray - -**Kind**: static property of [Array](#Array) - -| Param | Type | -| --- | --- | -| arg | \* | - -**Example** -```javascript -Array.isInstance(2); // false -Array.isInstance([7, 3]); // true -``` ### Array.range ⇒ Array.<number> @@ -989,9 +979,9 @@ Array.repeat(5, 2); // [2,2,2,2,2] ## Boolean : object **Kind**: global namespace - + -### Boolean.isInstance ⇒ boolean +### Boolean.isBoolean ⇒ boolean Returns true if the given argument is a boolean **Kind**: static property of [Boolean](#Boolean) @@ -1002,16 +992,16 @@ Returns true if the given argument is a boolean **Example** ```javascript -Boolean.isInstance('foo bar'); // false -Boolean.isInstance(flase); // true +Boolean.isBoolean('foo bar'); // false +Boolean.isBoolean(flase); // true ``` ## Date : object **Kind**: global namespace - + -### Date.isInstance ⇒ boolean +### Date.isDate ⇒ boolean Returns true if the given argument is an instance of Date **Kind**: static property of [Date](#Date) @@ -1022,8 +1012,8 @@ Returns true if the given argument is an instance of Date **Example** ```javascript -Date.isInstance('foo bar'); // false -Date.isInstance(new Date()); // true +Date.isDate('foo bar'); // false +Date.isDate(new Date()); // true ``` @@ -1036,7 +1026,7 @@ Date.isInstance(new Date()); // true * [.defer(args)](#Function+defer) ⇒ \* * [.once(args)](#Function+once) ⇒ \* * _static_ - * [.isInstance](#Function.isInstance) ⇒ boolean + * [.isFunction](#Function.isFunction) ⇒ boolean @@ -1088,9 +1078,9 @@ const test = (msg) => console.log(msg); test.once('a'); // logs 'a' test.once('b'); // no log this time ``` - + -### Function.isInstance ⇒ boolean +### Function.isFunction ⇒ boolean Returns true if the given argument is a function **Kind**: static property of [Function](#Function) @@ -1101,8 +1091,23 @@ Returns true if the given argument is a function **Example** ```javascript -Function.isInstance(2); // false -Function.isInstance((() => {})); // true +Function.isFunction(2); // false +Function.isFunction((() => {})); // true +``` + + +## global : object +**Kind**: global namespace + + +### global.isBrowser ⇒ boolean +Determines if the current runtime environment is a browser, +so that front-end modules can run on the server (Node) without throwing errors + +**Kind**: static property of [global](#global) +**Example** +```javascript +isBrowser(); // false ``` @@ -1250,7 +1255,7 @@ Math.lcm(...[1, 3, 4, 5]); // 60 * [Number](#Number) : object * [.digitize](#Number.digitize) ⇒ Array.<number> - * [.isInstance](#Number.isInstance) ⇒ boolean + * [.isNumber](#Number.isNumber) ⇒ boolean @@ -1267,9 +1272,9 @@ Converts the number to an array of digits ```javascript Number.digitize(123); // [1, 2, 3] ``` - + -### Number.isInstance ⇒ boolean +### Number.isNumber ⇒ boolean Returns true if the given argument is a number **Kind**: static property of [Number](#Number) @@ -1280,8 +1285,8 @@ Returns true if the given argument is a number **Example** ```javascript -Number.isInstance('foo bar'); // false -Number.isInstance(2); // true +Number.isNumber('foo bar'); // false +Number.isNumber(2); // true ``` @@ -1302,10 +1307,11 @@ Number.isInstance(2); // true * [.$mapKeys(fn)](#Object+$mapKeys) ⇒ [Object](#Object) * [.$merge(...objects)](#Object+$merge) ⇒ [Object](#Object) * [.$omit(arr)](#Object+$omit) ⇒ [Object](#Object) + * [.$set(path, value)](#Object+$set) * [.$size()](#Object+$size) ⇒ [Object](#Object) * [.$snakeCaseKeys()](#Object+$snakeCaseKeys) ⇒ [Object](#Object) * _static_ - * [.isInstance](#Object.isInstance) ⇒ boolean + * [.isObject](#Object.isObject) ⇒ boolean @@ -1485,6 +1491,24 @@ The function is invoked with two arguments: (value, key) { a: 1, b: '2', c: 3 }.$omit(['b']); // { a: 1, c: 3 } { a: 1, b: '2', c: 3 }.$omit((x) => typeof x === 'number'); // { b: '2' } ``` + + +### object.$set(path, value) +Puts the property value indicated by the given selector into the object + +**Kind**: instance method of [Object](#Object) + +| Param | Type | +| --- | --- | +| path | string | +| value | \* | + +**Example** +```javascript +const obj = { selector: { to: { val: 'val to select' } } }; +obj.$set('selector.to.val'); +// obj -> { selector: { to: { val: 'val to select' } } } +``` ### object.$size() ⇒ [Object](#Object) @@ -1506,9 +1530,9 @@ Creates a new object from the specified object, where all the keys are in snake- const myObj = { FirstName: "Adam", "last-name": "Smith" }; const myObjLower = myObj.$snakeCaseKeys(); // {first_name: "Adam", last_name: "Smith"} ``` - + -### Object.isInstance ⇒ boolean +### Object.isObject ⇒ boolean Returns true if the given argument is an object **Kind**: static property of [Object](#Object) @@ -1519,8 +1543,8 @@ Returns true if the given argument is an object **Example** ```javascript -Object.isInstance(2); // false -Object.isInstance({foo: 'bar'}); // true +Object.isObject(2); // false +Object.isObject({foo: 'bar'}); // true ``` @@ -1551,7 +1575,7 @@ Object.isInstance({foo: 'bar'}); // true * [.truncate(num, [truncateString])](#String+truncate) ⇒ string * [.words(pattern)](#String+words) ⇒ Array.<string> * _static_ - * [.isInstance](#String.isInstance) ⇒ boolean + * [.isString](#String.isString) ⇒ boolean * [.repeat](#String.repeat) ⇒ [String](#String) @@ -1846,9 +1870,9 @@ Converts a given string into an array of words 'I love javaScript!!'.words(); // ["I", "love", "javaScript"] 'python, javaScript & coffee'.words(); // ["python", "javaScript", "coffee"] ``` - + -### String.isInstance ⇒ boolean +### String.isString ⇒ boolean Returns true if the given argument is an string **Kind**: static property of [String](#String) @@ -1859,8 +1883,8 @@ Returns true if the given argument is an string **Example** ```javascript -String.isInstance(2); // false -String.isInstance("foo bar"); // true +String.isString(2); // false +String.isString("foo bar"); // true ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 60be9f15..d58d6ac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog -## [next](https://github.com/ardalanamini/prototyped.js/releases/tag/next) *(2018-__-__)* +## [v0.10.0](https://github.com/ardalanamini/prototyped.js/releases/tag/v0.10.0) *(2018-06-01)* **Implemented enhancements:** - better object value path handling - `Array` @@ -12,6 +12,8 @@ - renamed `isInstance` to `isDate` - `Function` - renamed `isInstance` to `isFunction` +- `Global` + - Added `isBrowser` - `Number` - renamed `isInstance` to `isNumber` - `Object` diff --git a/lib/globals/intex.ts b/lib/globals/intex.ts index 98a12ce1..b9907b04 100644 --- a/lib/globals/intex.ts +++ b/lib/globals/intex.ts @@ -1,3 +1,3 @@ -/** @namespace Global */ +/** @namespace global */ import "./isBrowser"; diff --git a/lib/globals/isBrowser/index.ts b/lib/globals/isBrowser/index.ts index f2dff584..1e61c920 100644 --- a/lib/globals/isBrowser/index.ts +++ b/lib/globals/isBrowser/index.ts @@ -13,7 +13,7 @@ declare global { /** * Determines if the current runtime environment is a browser, * so that front-end modules can run on the server (Node) without throwing errors - * @memberof Global + * @memberof global * @returns {boolean} * @example * isBrowser(); // false diff --git a/package-lock.json b/package-lock.json index 8d965de3..56aaab76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prototyped.js", - "version": "0.9.0", + "version": "0.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -62,9 +62,9 @@ "dev": true }, "@types/node": { - "version": "10.1.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.1.4.tgz", - "integrity": "sha512-GpQxofkdlHYxjHad98UUdNoMO7JrmzQZoAaghtNg14Gwg7YkohcrCoJEcEMSgllx4VIZ+mYw7ZHjfaeIagP/rg==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.0.tgz", + "integrity": "sha512-hWzNviaVFIr1TqcRA8ou49JaSHp+Rfabmnqg2kNvusKqLhPU0rIsGPUj5WJJ7ld4Bb7qdgLmIhLfCD1qS08IVA==", "dev": true }, "@types/pluralize": { @@ -6449,9 +6449,9 @@ } }, "typescript": { - "version": "2.8.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.4.tgz", - "integrity": "sha512-IIU5cN1mR5J3z9jjdESJbnxikTrEz3lzAw/D0Tf45jHpBp55nY31UkUvmVHoffCfKHTqJs3fCLPDxknQTTFegQ==", + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.1.tgz", + "integrity": "sha512-h6pM2f/GDchCFlldnriOhs1QHuwbnmj6/v7499eMHqPeW4V2G0elua2eIc2nu8v2NdHV0Gm+tzX83Hr6nUFjQA==", "dev": true }, "typical": { diff --git a/package.json b/package.json index be5fc8fa..9350687a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prototyped.js", - "version": "0.9.0", + "version": "0.10.0", "description": "Common typescript ready prototypes available in both es5 and es6", "author": "Ardalan Amini ", "license": "MIT", @@ -131,7 +131,7 @@ }, "devDependencies": { "@types/jest": "^22.2.3", - "@types/node": "^10.1.4", + "@types/node": "^10.3.0", "@types/pluralize": "0.0.28", "babel-core": "^6.26.3", "babel-preset-env": "^1.7.0", @@ -142,7 +142,7 @@ "jsdoc-to-markdown": "^4.0.1", "rimraf": "^2.6.2", "tslint": "^5.10.0", - "typescript": "^2.8.4", + "typescript": "^2.9.1", "uglify-es": "^3.3.9", "uglify-js": "^3.3.28" },