Skip to content

Commit

Permalink
Adds bundler to build README.md from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrmnn committed Oct 8, 2019
1 parent 9742e7b commit bc4751a
Show file tree
Hide file tree
Showing 121 changed files with 261 additions and 350 deletions.
101 changes: 79 additions & 22 deletions README.md 100755 → 100644
Expand Up @@ -39,12 +39,13 @@ yarn add collect.js

Using Laravel as your backend? Collect.js offers an (almost) identical api to [Laravel Collections](https://laravel.com/docs/master/collections). [See differences](#strictness-and-comparisons).

### Usage
### API

All available methods

- [all](#all)
- [average](#average)
- [avg](#avg)
- [chunk](#chunk)
- [collapse](#collapse)
- [combine](#combine)
Expand All @@ -69,8 +70,8 @@ All available methods
- [flatMap](#flatmap)
- [flatten](#flatten)
- [flip](#flip)
- [forget](#forget)
- [forPage](#forpage)
- [forget](#forget)
- [get](#get)
- [groupBy](#groupby)
- [has](#has)
Expand Down Expand Up @@ -112,7 +113,7 @@ All available methods
- [reduce](#reduce)
- [reject](#reject)
- [replace](#replace)
- [replaceRecursive](#replaceecursive)
- [replaceRecursive](#replacerecursive)
- [reverse](#reverse)
- [search](#search)
- [shift](#shift)
Expand All @@ -123,6 +124,7 @@ All available methods
- [sortBy](#sortby)
- [sortByDesc](#sortbydesc)
- [sortKeys](#sortkeys)
- [sortKeysDesc](#sortkeysdesc)
- [splice](#splice)
- [split](#split)
- [sum](#sum)
Expand All @@ -135,13 +137,13 @@ All available methods
- [union](#union)
- [unique](#unique)
- [unless](#unless)
- [unlessEmpty](#unlessEmpty)
- [unlessNotEmpty](#unlessNotEmpty)
- [unlessEmpty](#unlessempty)
- [unlessNotEmpty](#unlessnotempty)
- [unwrap](#unwrap)
- [values](#values)
- [when](#when)
- [whenEmpty](#whenEmpty)
- [whenNotEmpty](#whenNotEmpty)
- [whenEmpty](#whenempty)
- [whenNotEmpty](#whennotempty)
- [where](#where)
- [whereBetween](#wherebetween)
- [whereIn](#wherein)
Expand Down Expand Up @@ -762,6 +764,20 @@ flipped.all();
// }
```

#### `forPage()`

The forPage method returns a new collection containing the items that would be present on a given page number. The method accepts the page number as its first argument and the number of items to show per page as its second argument:

```js
const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9]);

const forPage = collection.forPage(2, 3);

forPage.all();

// [4, 5, 6]
```

#### `forget()`

The forget method removes an item from the collection by its key:
Expand All @@ -783,20 +799,6 @@ collection.all();

> Unlike most other collection methods, forget does not return a new modified collection; it modifies the collection it is called on.
#### `forPage()`

The forPage method returns a new collection containing the items that would be present on a given page number. The method accepts the page number as its first argument and the number of items to show per page as its second argument:

```js
const collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9]);

const forPage = collection.forPage(2, 3);

forPage.all();

// [4, 5, 6]
```

#### `get()`

The get method returns the item at a given key or index. If the key or index does not exist, `null` is returned:
Expand Down Expand Up @@ -2057,6 +2059,61 @@ sorted.all();
// ]
```

You can use dot notation to sort by nested values
```js
const collection = collect([
{
name: 'Desk',
price: 200,
manufacturer: {
name: 'IKEA',
},
},
{
name: 'Chair',
price: 100,
manufacturer: {
name: 'Herman Miller',
},
},
{
name: 'Bookcase',
price: 150,
manufacturer: {
name: 'IKEA',
},
},
]);

const sorted = collection.sortBy('manufacturer.name');

sorted.all();

// [
// {
// name: 'Chair',
// price: 100,
// manufacturer: {
// name: 'Herman Miller',
// },
// },
// {
// name: 'Desk',
// price: 200,
// manufacturer: {
// name: 'IKEA',
// },
// },
// {
// name: 'Bookcase',
// price: 150,
// manufacturer: {
// name: 'IKEA',
// },
// },
// ]
```

You can also pass your own callback to determine how to sort the collection values:

```js
Expand Down Expand Up @@ -2772,4 +2829,4 @@ PRs are welcomed to this project, and help is needed in order to keep up with th

### License

MIT © [Daniel Eckermann](http://danieleckermann.com)
MIT © [Daniel Eckermann](https://danieleckermann.com)
60 changes: 60 additions & 0 deletions bundler/README.stub.md
@@ -0,0 +1,60 @@




### Installation

#### NPM

```bash
npm install collect.js --save
```

#### Yarn

```bash
yarn add collect.js
```

#### From CDN

1. Visit https://cdnjs.com/libraries/collect.js
2. Add CDN link to your site with `<script>`

#### Using build / minified version

1. Download [`collect.min.js`](https://github.com/ecrmnn/collect.js/blob/master/build/collect.min.js)
2. Add to your site with `<script>`

### Tip

Using Laravel as your backend? Collect.js offers an (almost) identical api to [Laravel Collections](https://laravel.com/docs/master/collections). [See differences](#strictness-and-comparisons).

### Usage

All available methods

{{ toc }}

### Strictness and comparisons

All comparisons in `collect.js` are done using strict equality. Using loose equality comparisons are generally frowned upon in JavaScript. Laravel only performs "loose" comparisons by default and offer several "strict" comparison methods. These methods have not been implemented in `collect.js` because all methods are strict by default.

##### Methods that have not been implemented:

- ~~`containsStrict`~~ use `contains()`
- ~~`duplicatesStrict`~~ use `duplicates()`
- ~~`uniqueStrict`~~ use `unique()`
- ~~`whereStrict`~~ use `where()`
- ~~`whereInStrict`~~ use `whereIn()`
- ~~`whereNotInStrict`~~ use `whereNotIn()`

{{ methods }}

### Contribute

PRs are welcomed to this project, and help is needed in order to keep up with the changes of Laravel Collections. If you want to improve the collection library, add functionality or improve the docs please feel free to submit a PR.

### License

MIT © [Daniel Eckermann](http://danieleckermann.com)
3 changes: 3 additions & 0 deletions bundler/api.md
@@ -0,0 +1,3 @@
### API

All available methods
8 changes: 8 additions & 0 deletions bundler/badges.md
@@ -0,0 +1,8 @@
[![Travis](https://img.shields.io/travis/ecrmnn/collect.js/master.svg?style=flat-square)](https://travis-ci.org/ecrmnn/collect.js/builds)
[![npm version](https://img.shields.io/npm/v/collect.js.svg?style=flat-square)](http://badge.fury.io/js/collect.js)
[![npm downloads](https://img.shields.io/npm/dm/collect.js.svg?style=flat-square)](http://badge.fury.io/js/collect.js)
[![npm license](https://img.shields.io/npm/l/collect.js.svg?style=flat-square)](http://badge.fury.io/js/collect.js)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg?style=flat-square)](https://github.com/ecrmnn/collect.js/blob/master/package.json)
[![eslint](https://img.shields.io/badge/code_style-airbnb-blue.svg?style=flat-square)](https://github.com/airbnb/javascript)
[![cdnjs version](https://img.shields.io/cdnjs/v/collect.js.svg?style=flat-square)](https://cdnjs.com/libraries/collect.js)
55 changes: 55 additions & 0 deletions bundler/bundle.js
@@ -0,0 +1,55 @@
'use strict';

const { readFileSync, readdirSync, writeFileSync } = require('fs');

// Get all markdown stubs
const header = readFileSync('bundler/header.md', 'utf-8');
const badges = readFileSync('bundler/badges.md', 'utf-8');
const installation = readFileSync('bundler/installation.md', 'utf-8');
const api = readFileSync('bundler/api.md', 'utf-8');
const strictnessAndComparisons = readFileSync('bundler/strictness_and_comparisons.md', 'utf-8');
const notImplemented = readFileSync('bundler/not_implemented.md', 'utf-8');
const contribute = readFileSync('bundler/contribute.md', 'utf-8');
const license = readFileSync('bundler/license.md', 'utf-8');

// Get all API docs
const methods = readdirSync('docs/api', 'utf-8');

// Build table of contents
const tableOfContents = methods.map((file) => {
const methodName = file.replace('.md', '');

return `- [${methodName}](#${methodName.toLowerCase()})`;
}).join('\n');

// Build methods "readme"
const methodDocumentation = methods.map((file) => {
let content = readFileSync(`docs/api/${file}`, 'utf-8');

const lines = content.split('\n');

lines[0] = `###${lines[0]}`;
lines.pop();
lines.pop();

content = lines.join('\n');
content = content.replace(/(\r\n|\r|\n){2,}/g, '$1\n');

return content;
}).join('\n\n');

writeFileSync(
'README.md',
[
header,
badges,
installation,
api,
tableOfContents,
strictnessAndComparisons,
notImplemented,
methodDocumentation,
contribute,
license,
].join('\n\n'),
);
3 changes: 3 additions & 0 deletions bundler/contribute.md
@@ -0,0 +1,3 @@
### Contribute

PRs are welcomed to this project, and help is needed in order to keep up with the changes of Laravel Collections. If you want to improve the collection library, add functionality or improve the docs please feel free to submit a PR.
3 changes: 3 additions & 0 deletions bundler/header.md
@@ -0,0 +1,3 @@
# <img src="https://raw.githubusercontent.com/ecrmnn/collect.js/master/collectjs.jpg" alt="collect.js">

> Convenient and dependency free wrapper for working with arrays and objects
27 changes: 27 additions & 0 deletions bundler/installation.md
@@ -0,0 +1,27 @@
### Installation

#### NPM

```bash
npm install collect.js --save
```

#### Yarn

```bash
yarn add collect.js
```

#### From CDN

1. Visit https://cdnjs.com/libraries/collect.js
2. Add CDN link to your site with `<script>`

#### Using build / minified version

1. Download [`collect.min.js`](https://github.com/ecrmnn/collect.js/blob/master/build/collect.min.js)
2. Add to your site with `<script>`

### Tip

Using Laravel as your backend? Collect.js offers an (almost) identical api to [Laravel Collections](https://laravel.com/docs/master/collections). [See differences](#strictness-and-comparisons).
3 changes: 3 additions & 0 deletions bundler/license.md
@@ -0,0 +1,3 @@
### License

MIT © [Daniel Eckermann](https://danieleckermann.com)
8 changes: 8 additions & 0 deletions bundler/not_implemented.md
@@ -0,0 +1,8 @@
##### Methods that have not been implemented:

- ~~`containsStrict`~~ use `contains()`
- ~~`duplicatesStrict`~~ use `duplicates()`
- ~~`uniqueStrict`~~ use `unique()`
- ~~`whereStrict`~~ use `where()`
- ~~`whereInStrict`~~ use `whereIn()`
- ~~`whereNotInStrict`~~ use `whereNotIn()`
3 changes: 3 additions & 0 deletions bundler/strictness_and_comparisons.md
@@ -0,0 +1,3 @@
### Strictness and comparisons

All comparisons in `collect.js` are done using strict equality. Using loose equality comparisons are generally frowned upon in JavaScript. Laravel only performs "loose" comparisons by default and offer several "strict" comparison methods. These methods have not been implemented in `collect.js` because all methods are strict by default.
3 changes: 0 additions & 3 deletions docs/api/all.md
Expand Up @@ -8,7 +8,4 @@ collect([1, 2, 3]).all();
// [1, 2, 3]
```




[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/all.js)
3 changes: 0 additions & 3 deletions docs/api/average.md
Expand Up @@ -2,7 +2,4 @@

Alias for the [`avg()`](#avg) method




[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/average.js)
3 changes: 0 additions & 3 deletions docs/api/avg.md
Expand Up @@ -27,7 +27,4 @@ collection.avg('pages');
// 636
```




[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/avg.js)
3 changes: 0 additions & 3 deletions docs/api/chunk.md
Expand Up @@ -12,7 +12,4 @@ chunks.all();
// [[1, 2, 3, 4], [5, 6, 7]]
```




[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/chunk.js)

0 comments on commit bc4751a

Please sign in to comment.