Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Sierociński committed Sep 15, 2018
1 parent 33d2bc4 commit 7f914ed
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 65 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#### 1.2.0 (2018-09-15)

* `Number`

* added `isNumber` static method
* static method `isInt` has been renamed to `isInteger` and now is Polyfill to
[ES2015 method](https://www.ecma-international.org/ecma-262/6.0/#sec-isinteger)
* added `isNatural` static method

* `Object`

* added `assign` which is Polyfill to
[ES2015 method](https://www.ecma-international.org/ecma-262/6.0/#sec-object.assign)
* added `deepAssign` which is similar to `assign`, but extends also deep nested Objects

* `Array`

* added tests for all methods

* added this CHANGELOG file
117 changes: 111 additions & 6 deletions dist/finka.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Finka.js v1.1.2 | (c) Bitbar Technologies and contributors | https://github.com/bitbar/finka-js/blob/master/LICENSE.md */
/* Finka.js v1.2.0 | (c) Bitbar Technologies and contributors | https://github.com/bitbar/finka-js/blob/master/LICENSE.md */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -330,13 +330,37 @@
*/

/**
* Check if given number is integer
* Check if given number is number
*
* @param {number} n Number to check
* @returns {boolean} Verdict
*/
Number.isInt = function(n) {
return Number(n) === n && n % 1 === 0;
Number.isNumber = function(n) {
return n === Number(n);
};

if(typeof Number.prototype.isInteger != 'function') {

/**
* Polyfill for ECMAScript 2015 for Number.prototype.isInteger
*
* @param {number} n Number to check
* @returns {boolean} Verdict
*/
Number.isInteger = function(n) {
return Number.isNumber(n) && n % 1 === 0;
};

}

/**
* Check if given number is natural (this function assumes that 0 is also natural)
*
* @param {number} n Number to check
* @returns {boolean} Verdict
*/
Number.isNatural = function(n) {
return Number.isInteger(n) && n >= 0;
};

/**
Expand All @@ -346,7 +370,7 @@
* @returns {boolean} Verdict
*/
Number.isFloat = function(n){
return n === Number(n) && n % 1 !== 0;
return Number.isNumber(n) && n % 1 !== 0;
};

/**
Expand Down Expand Up @@ -657,6 +681,85 @@
return items;
};

if(typeof Object.assign != 'function') {

/**
* Polyfill for ECMAScript 2015 for Object.assign
* https://www.ecma-international.org/ecma-262/6.0/#sec-object.assign
*/
Object.assign = function() {
var args = Array.prototype.slice.call(arguments, 0);
var to = Object(args[0]);

if(args.length !== 1) {
var sources = args.slice(1);
var nextSource, keys, from, nextKey, propValue;

for(var i = 0; i < sources.length; i++) {
nextSource = sources[i];
from = Object(nextSource);

if(typeof nextSource === 'undefined' || nextSource === null) {
keys = [];
} else {
keys = Object.keys(from);
}

for(var j = 0; j < keys.length; j++) {
nextKey = keys[j];
propValue = from[nextKey];
if(typeof propValue !== 'undefined' && from.propertyIsEnumerable(nextKey)) {
to[nextKey] = propValue;
}
}
}
}

return to;
};

}

/**
* This is similar to Object.assign, but extends also deep nested Objects
*
* @returns {object} Object
*/
Object.deepAssign = function() {
var args = Array.prototype.slice.call(arguments, 0);
var to = Object(args[0]);

if(args.length !== 1) {
var sources = args.slice(1);
var nextSource, keys, from, nextKey, propValue;

for(var i = 0; i < sources.length; i++) {
nextSource = sources[i];
from = Object(nextSource);

if(typeof nextSource === 'undefined' || nextSource === null) {
keys = [];
} else {
keys = Object.keys(from);
}

for(var j = 0; j < keys.length; j++) {
nextKey = keys[j];
propValue = from[nextKey];
if(typeof propValue !== 'undefined' && from.propertyIsEnumerable(nextKey)) {
if(typeof to[nextKey] === 'object' && typeof propValue === 'object') {
to[nextKey] = Object.deepAssign({}, to[nextKey], propValue);
} else {
to[nextKey] = propValue;
}
}
}
}
}

return to;
};

/**
* @namespace Array
*/
Expand Down Expand Up @@ -786,7 +889,9 @@
return [];
}

return this.filter(function(item) { return Object.isLike(item, query); });
return this.filter(function(item) {
return Object.isLike(item, query);
});
};

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/finka.min.js

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "finka",
"version": "1.1.2",
"version": "1.2.0",
"description": "Handy tool in nowadays JavaScript jungle",
"main": "dist/finka.js",
"scripts": {
"build": "npx rollup -c",
"test": "npx mocha",
"docs": "npx jsdoc -c jsdoc.json"
"docs": "npx jsdoc -c jsdoc.json",
"lint": "npx eslint ."
},
"repository": {
"type": "git",
Expand All @@ -20,7 +21,8 @@
"js",
"javascript",
"finka",
"finka-js"
"finka-js",
"prototype"
],
"author": "Marek Sierociński (https://github.com/marverix)",
"contributors": [
Expand All @@ -37,6 +39,7 @@
},
"homepage": "https://github.com/bitbar/finka-js#readme",
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^5.5.0",
"jsdoc": "^3.5.5",
"jsdoc-rtd": "^1.0.15",
Expand Down
Loading

0 comments on commit 7f914ed

Please sign in to comment.