npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kingjs/linq.order-by

v1.0.7

Published

Generates a sequence of elements in ascending order according to a key.

Downloads

16

Readme

@kingjs/linq.order-by

Generates a sequence of elements in ascending order according to a key.

Usage

Sort the numbers 1, 0, 2 like this:

var orderBy = require('@kingjs/linq.order-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var numbers = sequence(1, 0, 2);

var result = orderBy.call(numbers);

toArray.call(result);

result:

[0, 1, 2]

Sort the same numbers as before, but now wrapped in objects, like this:

var orderBy = require('@kingjs/linq.order-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var numbers = sequence({ value: 1 }, { value: 0 }, { value: 2 });
var keySelector = function(x) { return x.value; };

var result = orderBy.call(numbers, keySelector);

toArray.call(result);

result:

[{ value: 0 }, { value: 1 }, { value: 2 }]

Sort the numbers 1, 0, 2 and letters b, a so letters come first like this:

var orderBy = require('@kingjs/linq.order-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var numbers = sequence(1, 0, 2, `b`, `a`);
var keySelector = null;
var lessThan = function(l, r) {
  if (typeof l != typeof r)
    return typeof l == 'string';
  return l < r;
};

var result = orderBy.call(numbers, keySelector, lessThan);

toArray.call(result);

result:

['a', 'b', 0, 1, 2]

Sort Bob Smith, Alice Smith, and Chris King by last name then first name like this:

var orderBy = require('@kingjs/linq.order-by');
var sequence = require('@kingjs/enumerable.create');
var toArray = require('@kingjs/linq.to-array');

var people = sequence(
  { first: 'Bob', last: 'Smith' },
  { first: 'Alice', last: 'Smith' },
  { first: 'Chris', last: 'King' },
);

var lastSelector = function(x) { return x.last; }
var firstSelector = function(x) { return x.first; }

var sortedSequence = orderBy
  .call(people, lastSelector)
  .createOrderedEnumerable(firstSelector);

toArray.call(sortedSequence);

result:

[
  { first: 'Chris', last: 'King' },
  { first: 'Alice', last: 'Smith' },
  { first: 'Bob', last: 'Smith' },
]

API

declare function orderBy(
  this: Enumerable, 
  keySelector?: (x) => any,
  lessThan?: (l, r) => boolean,
  descending?: boolean
): SortedEnumerable

declare interface SortedEnumerable extends Enumerable {
  createOrderedEnumerable(
    keySelector?: (x) => any,
    lessThan?: (l, r) => boolean,
    descending?: boolean
  ): SortedEnumerable
}

Interfaces

  • Enumerable: See @kingjs/enumerable.define.
  • SortedEnumerable: Allows further sorting of elements that have compared equal thus far. The arguments have the same semantics as the OrderBy arguments.

Parameters

  • this: A sequence of element to sort.
  • keySelector: Select a value by which to sort. By default, returns the element.
  • lessThan: Compare if one key is less than another. By default, uses the < operator.
  • descending: If true, then sorts in descending order. Default is false.

Return Value

A sorted sequence.

See Also

Install

With npm installed, run

$ npm install @kingjs/link.order-by

Acknowledgments

Like Enumerable.OrderBy

License

MIT

Analytics