# helper-sort-items

> Helper for filtering and sorting an assemble collection based on an array of strings.

Latest version **0.1.0** (published 2017-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install helper-sort-items
pnpm add helper-sort-items
yarn add helper-sort-items
bun add helper-sort-items
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-02-20 |
| First published | 2017-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | compile, filter, helper, helpers, items, render, template, templates |

## Links

- npm: https://www.npmjs.com/package/helper-sort-items
- Repository: https://github.com/helpers/helper-sort-items
- Issues: https://github.com/helpers/helper-sort-items/issues
- npm.io page: https://npm.io/package/helper-sort-items

## Dependencies (3)

- [isobject](https://npm.io/package/isobject.md) ^3.0.0
- [markdown-slug](https://npm.io/package/markdown-slug.md) ^0.1.1
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-02-20

## README

# helper-sort-items [![NPM version](https://img.shields.io/npm/v/helper-sort-items.svg?style=flat)](https://www.npmjs.com/package/helper-sort-items) [![NPM monthly downloads](https://img.shields.io/npm/dm/helper-sort-items.svg?style=flat)](https://npmjs.org/package/helper-sort-items)  [![NPM total downloads](https://img.shields.io/npm/dt/helper-sort-items.svg?style=flat)](https://npmjs.org/package/helper-sort-items) [![Linux Build Status](https://img.shields.io/travis/helpers/helper-sort-items.svg?style=flat&label=Travis)](https://travis-ci.org/helpers/helper-sort-items)

> Helper for filtering and sorting an assemble collection based on an array of strings.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save helper-sort-items
```

## Usage

This is designed with [assemble](https://github.com/assemble/assemble) collections in mind, but it's generic enough that it should work with an array of strings too.

**Example**

The following example shows how to sort and filter the items in an [assemble](https://github.com/assemble/assemble) collection.

```js
var assemble = require('assemble');
var app = assemble();

app.helper('sortItems', require('helper-sort-items'));
app.pages('templates/*.hbs');
```

Given that four pages have been loaded: `foo.hbs`, `bar.hbs`, `baz.hbs`, and `some-file.hbs`, the following:

```handlebars
<!-- in "some-file.hbs" -->
{{#pages}}
  {{#each (sortItems items) as |item|}}
    {{item.basename}}
  {{/each}}
{{/pages}}
```

When rendered with these options:

```js
var locals = {order: ['baz', 'bar', 'foo']};

app.render('some-file.hbs', locals, function(err, view) {
  if (err) {
    console.log(err);
    process.exit(1);
  }
  console.log(view.contents.toString());
});
```

Would result in:

```
baz.hbs
bar.hbs
foo.hbs
```

## Sort order

You can also pass the sort order as the last argument as a comma-separated string:

```handlebars
{{#pages}}
  {{#each (sortItems items "baz,foo,bar") as |item|}}
    {{item.basename}}
  {{/each}}
{{/pages}}
```

Or when used as a [handlebars](http://www.handlebarsjs.com/) helper, you can pass the sort order on the options hash as a comma-separated string:

```handlebars
{{#pages}}
  {{#each (sortItems items order="baz,foo,bar") as |item|}}
    {{item.basename}}
  {{/each}}
{{/pages}}
```

## About

### Related projects

* [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers): More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… [more](https://github.com/assemble/handlebars-helpers) | [homepage](https://github.com/assemble/handlebars-helpers "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.")
* [template-helpers](https://www.npmjs.com/package/template-helpers): Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… [more](https://github.com/jonschlinkert/template-helpers) | [homepage](https://github.com/jonschlinkert/template-helpers "Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
MIT

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 19, 2017._

---
_Source: https://npm.io/package/helper-sort-items · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
