Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardalan Amini committed Apr 13, 2018
2 parents 10751a2 + 542fe62 commit 76e8bfd
Show file tree
Hide file tree
Showing 307 changed files with 5,204 additions and 2,490 deletions.
285 changes: 185 additions & 100 deletions API.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## [v0.5.0](https://github.com/ardalanamini/prototyped.js/releases/tag/v0.5.0) *(2018-04-13)*
**Implemented enhancements:**
- `Array.prototype`
- function `all` added
- function `any` added
- `Object.prototype`
- function `invert` renamed into `$invert`
- function `lowerCaseKeys` renamed into `$lowerCaseKeys`
- function `mapKeys` renamed into `$mapKeys`
- function `merge` renamed into `$merge`
- function `size` renamed into `$size`
- `String.prototype`
- function `base64` added
- function `base64Decode` added
- function `map` added
- function `pluralize` improved
- some general enhancements

**Fixed bugs:**
- typescript usage


## [v0.4.0](https://github.com/ardalanamini/prototyped.js/releases/tag/v0.4.0) *(2018-01-28)*
**Implemented enhancements:**
- more customizable usage
Expand Down
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,43 @@
<a href="https://www.npmjs.com/package/prototyped.js" target="_blank">
<img src="https://img.shields.io/npm/v/prototyped.js.svg" alt="npm version">
</a>
<a href="https://www.typescriptlang.org" target="_blank">
<img src="https://img.shields.io/npm/types/prototyped.js.svg" alt="typescript version">
</a>
<a href="http://packagequality.com/#?package=prototyped.js" target="_blank">
<img src="http://npm.packagequality.com/shield/prototyped.js.svg" alt="package quality">
</a>
<a href="https://www.npmjs.com/package/prototyped.js" target="_blank">
<img src="https://img.shields.io/npm/dt/prototyped.js.svg" alt="npm downloads">
</a>
<a href="https://www.npmjs.com/package/prototyped.js" target="_blank">
<img src="https://img.shields.io/npm/dm/prototyped.js.svg" alt="npm monthly downloads">
</a>
<a href="https://github.com/ardalanamini/prototyped.js/stargazers" target="_blank">
<img src="https://img.shields.io/github/stars/ardalanamini/prototyped.js.svg" alt="github stars">
<a href="https://github.com/ardalanamini/prototyped.js/issues?q=is%3Aopen+is%3Aissue" target="_blank">
<img src="https://img.shields.io/github/issues-raw/ardalanamini/prototyped.js.svg" alt="open issues">
</a>
<a href="https://github.com/ardalanamini/prototyped.js/issues?q=is%3Aissue+is%3Aclosed" target="_blank">
<img src="https://img.shields.io/github/issues-closed-raw/ardalanamini/prototyped.js.svg" alt="closed issues">
</a>
<a href="https://github.com/facebook/jest" target="_blank">
<img src="https://img.shields.io/badge/tested_with-jest-99424f.svg" alt="tested with jest">
</a><a href="https://snyk.io/test/github/ardalanamini/prototyped.js?targetFile=package.json" target="_blank">
<img src="https://snyk.io/test/github/ardalanamini/prototyped.js/badge.svg?targetFile=package.json" alt="known vulnerabilities" data-canonical-src="https://snyk.io/test/github/ardalanamini/prototyped.js?targetFile=package.json" style="max-width:100%;">
</a>
<a href="https://david-dm.org/ardalanamini/prototyped.js" target="_blank">
<img src="https://david-dm.org/ardalanamini/prototyped.js.svg" alt="dependencies status">
</a>
<a href="https://github.com/ardalanamini/prototyped.js/pulls" target="_blank">
<img src="https://img.shields.io/badge/PRs-Welcome-brightgreen.svg" alt="pull requests">
</a>
<a href="https://github.com/ardalanamini/prototyped.js/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/github/license/ardalanamini/prototyped.js.svg" alt="tested with jest">
<img src="https://img.shields.io/github/license/ardalanamini/prototyped.js.svg" alt="license">
</a>
<a href="https://github.com/ardalanamini/prototyped.js" target="_blank">
<img src="https://img.shields.io/github/stars/ardalanamini/prototyped.js.svg?style=social&label=Stars" alt="github stars">
</a>
<a href="https://github.com/ardalanamini/prototyped.js" target="_blank">
<img src="https://img.shields.io/github/forks/ardalanamini/prototyped.js.svg?style=social&label=Fork" alt="github stars">
</a>
<br>
</div>
Expand Down Expand Up @@ -55,4 +81,20 @@ require('prototyped.js/dist/string/words');
console.log('hello world!'.words()); // ['hello', 'world']
```

even better, just import the method you want

```javascript
const words = require('prototyped.js/dist/string/words/method');

console.log(words('hello world!')); // ['hello', 'world']
```

All documents are available at [API.md](https://github.com/ardalanamini/prototyped.js/blob/master/API.md)

## Support

If my work helps you, please consider

<a href="https://www.buymeacoffee.com/ardalanamini" target="_blank">
<img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;">
</a>
20 changes: 20 additions & 0 deletions lib/array/all/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as method from "./method";

declare global {
interface Array<T> {
all(fn?: (value: T, index: number, array: T[]) => boolean): boolean;
}
}

/**
* Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise
* @memberof Array
* @param {function} [fn=Boolean]
* @returns {boolean}
* @example
* [4, 2, 3].all((x) => x > 1); // true
* [1, 2, 3].all(); // true
*/
Array.prototype.all = function(fn) {
return method(this, fn);
};
3 changes: 3 additions & 0 deletions lib/array/all/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const all = (arr: any[], fn: (value: any, index: number, array: any[]) => boolean = Boolean) => arr.every(fn);

export = all;
11 changes: 11 additions & 0 deletions lib/array/all/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./index";

describe("Array.prototype.all", () => {
test("[4, 2, 3].all((x) => x > 1) returns true", () => {
expect([4, 2, 3].all((x) => x > 1)).toBe(true);
});

test("[1, 2, 3].all() returns true", () => {
expect([1, 2, 3].all()).toBe(true);
});
});
21 changes: 21 additions & 0 deletions lib/array/any/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as method from "./method";

declare global {
interface Array<T> {
any(fn?: (value: T, index: number, array: T[]) => boolean): boolean;
}
}

/**
* Returns `true` if the provided predicate function returns `true` for at least one element in a collection,
* `false` otherwise
* @memberof Array
* @param {function} [fn=Boolean]
* @returns {boolean}
* @example
* [0, 1, 2, 0].any((x) => x >= 2); // true
* [0, 0, 1, 0].any(); // true
*/
Array.prototype.any = function(fn) {
return method(this, fn);
};
3 changes: 3 additions & 0 deletions lib/array/any/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const method = (arr: any[], fn: (value: any, index: number, array: any[]) => boolean = Boolean) => arr.some(fn);

export = method;
11 changes: 11 additions & 0 deletions lib/array/any/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./index";

describe("Array.prototype.any", () => {
test("[0, 1, 2, 0].any((x) => x >= 2) returns true", () => {
expect([0, 1, 2, 0].any((x) => x >= 2)).toBe(true);
});

test("[0, 0, 1, 0].any() returns true", () => {
expect([0, 0, 1, 0].any()).toBe(true);
});
});
14 changes: 5 additions & 9 deletions lib/array/append/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { }
import * as method from "./method";

declare global {
interface Array<T> {
append(value?: any): void
append(value: T): void;
}
}

Expand All @@ -14,10 +14,6 @@ declare global {
* var myArray = [1, 2, 3]
* myArray.append(0); // myArray => [1, 2, 3, 0]
*/
Array.prototype.append = function(value: any): void {
let array = this.concat([value])

this.length = 0

this.push(...array)
}
Array.prototype.append = function(value) {
return method(this, value);
};
9 changes: 9 additions & 0 deletions lib/array/append/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const method = (arr: any[], value: any) => {
const array = arr.concat([value]);

arr.length = 0;

arr.push(...array);
};

export = method;
16 changes: 9 additions & 7 deletions lib/array/append/test.js → lib/array/append/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require('../../../es6/array/append')
import "./index";

describe("Array.prototype.append", () => {
test("myArray = [1, 2, 3] & myArray.append(0) results myArray to be [1, 2, 3, 0]", () => {
expect((() => {
let myArray = [1, 2, 3]
myArray.append(0)
return myArray
})()).toEqual([1, 2, 3, 0])
})
})
const myArray = [1, 2, 3];

myArray.append(0);

return myArray;
})()).toEqual([1, 2, 3, 0]);
});
});
38 changes: 11 additions & 27 deletions lib/array/average/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { }
import * as method from "./method";

declare global {
interface Array<T> {
average(key?: string): number
avg(key?: string): number
average(key?: string): number;
avg(key?: string): number;
}
}

Expand All @@ -14,28 +14,12 @@ declare global {
* @returns {number}
* @example
* [1, 2, 3].average(); // 2
* [{a: 1}, {a: 2}, {a: 3}].average('a'); // 2
* [{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].average('a.b'); // 2
* [{a: 1}, {a: 2}, {a: 3}].average("a"); // 2
* [{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].average("a.b"); // 2
*/
Array.prototype.average = function(key?: string): number {
let sum = 0

if (key) {
let keys = key.split('.')

this.map((item) => {
keys.map((k) => item = item && item[k] || 0)

sum += item
})

return sum / this.length
}

this.map((number) => sum += number)

return sum / this.length
}
Array.prototype.average = function(key) {
return method(this, key);
};

/**
* An alias of Array.prototype.average
Expand All @@ -44,7 +28,7 @@ Array.prototype.average = function(key?: string): number {
* @returns {number}
* @example
* [1, 2, 3].avg(); // 2
* [{a: 1}, {a: 2}, {a: 3}].avg('a'); // 2
* [{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].avg('a.b'); // 2
* [{a: 1}, {a: 2}, {a: 3}].avg("a"); // 2
* [{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].avg("a.b"); // 2
*/
Array.prototype.avg = Array.prototype.average
Array.prototype.avg = Array.prototype.average;
5 changes: 5 additions & 0 deletions lib/array/average/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as sum from "../sum/method";

const method = (arr: any[], key?: string) => sum(arr, key) / arr.length;

export = method;
15 changes: 0 additions & 15 deletions lib/array/average/test.js

This file was deleted.

15 changes: 15 additions & 0 deletions lib/array/average/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "./index";

describe("Array.prototype.average", () => {
test("[1, 2, 3].average() returns 2", () => {
expect([1, 2, 3].average()).toBe(2);
});

test("[{a: 1}, {a: 2}, {a: 3}].average(\"a\") returns 2", () => {
expect([{ a: 1 }, { a: 2 }, { a: 3 }].average("a")).toBe(2);
});

test("[{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}].average(\"a.b\") returns 2", () => {
expect([{ a: { b: 1 } }, { a: { b: 2 } }, { a: { b: 3 } }].average("a.b")).toBe(2);
});
});
10 changes: 5 additions & 5 deletions lib/array/chunk/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { }
import * as method from "./method";

declare global {
interface Array<T> {
chunk(size: number): Array<Array<T>>
chunk(size: number): T[][];
}
}

Expand All @@ -14,6 +14,6 @@ declare global {
* @example
* [1, 2, 3, 4, 5].chunk(2); // [[1,2],[3,4],[5]]
*/
Array.prototype.chunk = function(size: number): Array<Array<any>> {
return Array.from({ length: Math.ceil(this.length / size) }, (value: any, index: number) => this.slice(index * size, index * size + size))
}
Array.prototype.chunk = function(size) {
return method(this, size);
};
10 changes: 10 additions & 0 deletions lib/array/chunk/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const method = (arr: any[], size: number): any[][] => {
return Array.from(
{
length: Math.ceil(arr.length / size),
},
(value: any, index: number) => arr.slice(index * size, index * size + size),
);
};

export = method;
8 changes: 4 additions & 4 deletions lib/array/chunk/test.js → lib/array/chunk/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('../../../es6/array/chunk')
import "./index";

describe("Array.prototype.chunk", () => {
test("[1, 2, 3, 4, 5].chunk(2) returns [[1,2],[3,4],[5]]", () => {
expect([1,2,3,4,5].chunk(2)).toEqual([[1,2],[3,4],[5]])
})
})
expect([1, 2, 3, 4, 5].chunk(2)).toEqual([[1, 2], [3, 4], [5]]);
});
});
10 changes: 5 additions & 5 deletions lib/array/clone/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { }
import * as method from "./method";

declare global {
interface Array<T> {
clone(): Array<T>
clone(): T[];
}
}

Expand All @@ -13,6 +13,6 @@ declare global {
* @example
* [1, 2, 3].clone(); // [1, 2, 3]
*/
Array.prototype.clone = function(): Array<any> {
return [...this]
}
Array.prototype.clone = function() {
return method(this);
};
3 changes: 3 additions & 0 deletions lib/array/clone/method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const method = (arr: any[]) => [...arr];

export = method;
Loading

0 comments on commit 76e8bfd

Please sign in to comment.