2.0.0 • Published 15 days ago

compare-func v2.0.0

Weekly downloads
1,500,794
License
MIT
Repository
github
Last release
15 days ago

NPM version Build Status Dependency Status Coverage Status

Get a compare function for array to sort

Install

$ npm install --save compare-func

Usage

var compareFunc = require('compare-func');

// sort by an object property
[{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc('x'));
//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]

// sort by a nested object property
[{x: {y: 'b'}}, {x: {y: 'a'}}].sort(compareFunc('x.y'));
//=> [{x: {y: 'a'}}, {x: {y: 'b'}}]

// sort by the `x` propery, then `y`
[{x: 'c', y: 'c'}, {x: 'b', y: 'a'}, {x: 'b', y: 'b'}].sort(compareFunc(['x', 'y']));
//=> [{x: 'b', y: 'a'}, {x: 'b', y: 'b'}, {x: 'c', y: 'c'}]

// sort by the returned value
[{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc(function(el) {
  return el.x;
}));
//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]

API

compareFunc(property)

Returns a compare function for array to sort

property

Type: string, function or array of either

If missing it sorts on itself.

The string can be a dot path to a nested object property.

Related

  • sort-on - Sort an array on an object property

License

MIT © Steve Mao

conventional-changelog-angularconventional-changelog-writer@boundless-inc/mobiledoc-dom-renderer@vue/conventional-changelog@w12/conventional-changelog@x-copy/conventional-changelog-angular@vendys/conventional-changelog-preset@yoitsro/conventional-changelog-angular@jaszczakw/conventional-changelog-angular@huzan/hz-cz@interaktiv/conventional-changelog-dia@interaktiv/conventional-changelog-dia-bitbucket@jimistore/web-changelog@nhi/conventional-changelog-preset@nodepack/conventional-changelog@marcotan/conventional-changelog@hawkingnetwork/react-native-tab-viewchangelog-sncs-gitmoji-changelogconventional-changelog-acteconventional-changelog-alifdconventional-changelog-anansiconventional-changelog-angular-allconventional-changelog-angular-all-2conventional-changelog-angular-bitbucketconventional-changelog-angular-bitbucket-cloudconventional-changelog-angular-bitbucket-presetconventional-changelog-angular-cz-emojiconventional-changelog-angular-emojiconventional-changelog-angular-redmineconventional-changelog-angular-vstsconventional-changelog-angular-vststconventional-changelog-angular-zeroconventional-changelog-angularxconventional-changelog-atomixconventional-changelog-befeconventional-changelog-bitbucket-customconventional-changelog-blackieconventional-changelog-blacklakeconventional-changelog-c3conventional-changelog-cobconventional-changelog-commonconventional-changelog-configconventional-changelog-conventionalcommitsconventional-changelog-conventionalcommits-parseroptsconventional-changelog-custom-angular-pomconventional-changelog-custom-bugsconventional-changelog-cz-emojiconventional-changelog-docsconventional-changelog-sprucelabsconventional-changelog-stalinkayconventional-changelog-standardconventional-changelog-themeisleconventional-changelog-ui-router-coreconventional-changelog-videojsconventional-changelog-vue-materialconventional-changelog-weaveabilityconventional-changelog-webcastudioconventional-changelog-wormiecorpconventional-changelog-yygameconventional-changelor-releaseconventional-commits-templateconventional-commits-writerconventional-changelog-emojiconventional-changelog-emojisconventional-changelog-esdocconventional-changelog-factorioconventional-changelog-gzbconventional-changelog-insurgentconventional-changelog-jiraconventional-changelog-jshintconventional-changelog-keep-changelogconventional-changelog-kronosconventional-changelog-medipassconventional-changelog-mnuboconventional-changelog-monorepoconventional-changelog-releaseconventional-changelog-release-meconventional-changelog-semf-configconventional-changelog-simple-presetconventional-changelog-spm@uedlinker/conventional-changelog-uedlinker@zazen/conventional-changelogcz-commit-emojibeta-changelogmiguelcostero-ng2-toastylazy-bee-uiphabricator-conventional-changelogplaykit-js-hls-sondq@anteriovieira/conventional-changelogstroganoff@eric.dahlseng/conventional-changelog-config@cobnl/conventional-changelog@colisweb/conventional-changelog-colisweb@bravura/conventional-changelog-jirajimi-web-changelogwd-web-changelogwii-changelog@ckeditor/ckeditor5-dev-env@codoonfxd/changelog-config
1.3.4

15 days ago

1.3.3

15 days ago

2.0.0

15 days ago

1.3.2

4 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.0

5 years ago