Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iguntur/obj-sort
Order object by ascending or descending
https://github.com/iguntur/obj-sort
Last synced: about 11 hours ago
JSON representation
Order object by ascending or descending
- Host: GitHub
- URL: https://github.com/iguntur/obj-sort
- Owner: iguntur
- License: mit
- Created: 2017-01-13T15:41:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-13T15:58:03.000Z (almost 8 years ago)
- Last Synced: 2024-04-23T22:39:43.903Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# obj-sort [![Build Status](https://travis-ci.org/iguntur/obj-sort.svg?branch=master)](https://travis-ci.org/iguntur/obj-sort)
> Order object by ascending or descending
## Install
```
$ npm install --save obj-sort
```## Usage
```js
const objSort = require('obj-sort');// ascending by default
objSort({
b: 'b',
c: ['y', 'x'],
a: {y: 'x', x: 'y', n: {foo: 'foo', bar: 'bar'}}
});
/*
{
a: {n: {bar: 'bar', foo: 'foo'}, x: 'y', y: 'x'},
b: 'b',
c: ['y', 'x']
}
*/// descending
objSort({
a: {n: {bar: 'bar', foo: 'foo'}, x: 'y'},
c: ['y', 'x'],
b: 'b'
}, 'desc');
/*
{
c: ['y', 'x'],
b: 'b',
a: {x: 'y', n: {foo: 'foo', bar: 'bar'}}
}
*/
```## API
### objSort(obj, order)
Returns an object
#### obj
Type: `object`
#### order
Type: `string`
Options: `asc`, `desc`
Default: `asc`Set order type object
## License
MIT © [Guntur Poetra](http://iguntur.starmediateknik.com)