takes a sort configuration object and returns a sort function operating on arrays (returning a new array without modifying the input array). For nodejs and browsers.
npm install smart-table-sort --save
yarn add smart-table-sort
importsorterfrom'smart-table-sort';constinput=[{prop: 'foo'},{prop: 'bar'},{prop: 'woot'}];constsort=sorter({pointer:'prop',direction:'desc'})// default direction is "asc"constoutput=sort(input);// > [{foo: 'woot'}, {prop: 'foo'}, {prop: 'bar'}]it works on nested properties as well
importsorterfrom'smart-table-sort';constinput=[{foo: {bar: 'bcd'}},{foo: {bar: 'acd'}},{foo: {bar: 'abd'}}];constoutput=sorter({pointer: 'foo.bar'})(input);// > [{foo: {bar: 'abd'}},{foo: {bar: 'acd'}},{foo: {bar: 'bcd'}}]);- pointer: the property to use for ordering the collection (can be a nested property)
- direction: 'asc', 'desc', 'none' (default is 'asc', 'none' will returned in the order of the input array untouched)
npm test
or
yarn test
Only bugs and must come with a running reproduction of the issue