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 🙏

© 2024 – Pkg Stats / Ryan Hefner

anysort-typed

v3.3.1

Published

Flexible and Full Typed multi-properties sorter for nested objects

Downloads

573

Readme

Anysort

Why Anysort

A picture is worth a thousand words.

Install

npm install --save anysort-typed

Why Anysort

  • Anysort can sort with multi-attributes
// select articles which has 'it' tag, put ahead,
// then move articles which status is 'editing' at the begining
anysort(articles)
  .tag.has('it')
  .status.is('editing')
  .map(print)
  • Intuitive
// Array.prototype.sort: what hell the result is!
[].sort.apply([0, '0', 1, 'd', '1', '0', 0, ''])
// ['', 0, '0', '0', 0, 1, '1', 'd']

// Anysort:the result is intuitive
anysort([0, '0', 1, undefined, 'd', '1', '0', null, 0, '', undefined])
// [0, 0, 1, '', '0', '0', '1', 'd']
  • Flexible API
// proxy chain api
anysort(articles).created.date.reverse()

// or
anysort(articles, 'created.date-reverse()')
  • Full typed, even in call-with-string-mode, AMAZING!
// @ts-expect-error
anysort(articles).tag.hass('it')
// @ts-expect-error
anysort(articles, 'created.date-unknownPlugin()')
// OK!
anysort(articles).created.date.reverse()
// OK!
anysort(articles, 'created.date-reverse()')
// @ts-expect-error
anysort(articles).created.date.reverse(123)
// @ts-expect-error
anysort(articles, 'created.date-reverse(123)')
  • Zero dependencies(minifized + gzip ≈ 3KB)

  • Well tested, logic and type

  • WIP: Full API document, help wanted

  • WIP: Benchmark, help wanted

Usage

Short instruction。

const posts = getPosts()
const print = (x) => console.log(JSON.stringify(x))

// select articles being edited with IT tags,
// sorted by date in reverse order and time in positive order
anysort(posts, [
  'status-is(editing)',
  'tag-has(it)',
  'created.date-reverse()',
  'created.hour'
]).map(print)

// {"tag":["it"],"status":"editing","created":{"date":"2021-01-02T00:00:00.000Z","hour":23}}
// {"tag":["it"],"status":"editing","created":{"date":"2021-01-01T00:00:00.000Z","hour":16}}
// {"tag":["game","it"],"status":"editing","created":{"date":"2021-01-01T00:00:00.000Z","hour":23}}
// {"tag":["mp3"],"status":"","created":{"date":"2019-08-01T00:00:00.000Z","hour":23}}

// sick of using string manipulation?
// try this!
anysort(getPosts())
  .created.hour.result()
  .created.date.reverse()
  .tag.has('it')
  .status.is('editing')
  .map(print)

// {"tag":["it"],"status":"editing","created":{"date":"2021-01-02T00:00:00.000Z","hour":23}}
// {"tag":["it"],"status":"editing","created":{"date":"2021-01-01T00:00:00.000Z","hour":16}}
// {"tag":["game","it"],"status":"editing","created":{"date":"2021-01-01T00:00:00.000Z","hour":23}}
// {"tag":["mp3"],"status":"","created":{"date":"2019-08-01T00:00:00.000Z","hour":23}}

function getPosts () {
  return [
    {
      tag: ['mp3'],
      status: '',
      created: {
        date: new Date('2019-08-01'),
        hour: 23
      }
    },
    {
      tag: ['game', 'it'],
      status: 'editing',
      created: {
        date: new Date('2021-01-01'),
        hour: 23
      }
    },
    {
      tag: ['it'],
      status: 'editing',
      created: {
        date: new Date('2021-01-01'),
        hour: 16
      }
    },
    {
      tag: ['it'],
      status: 'editing',
      created: {
        date: new Date('2021-01-02'),
        hour: 23
      }
    }
  ]
}

Full API Doc

TODO

Change Log

See ChangeLog.md

Dev & Test

# run test when files change in directory build
npm run watch:test

# modify source code then build
npm run build

How this work

《🌐 Anysort:灵活、优雅的多属性排序》

Pull & Request

See TODO.MD,help wanted!

Related Projects

License

Copyright © 2021, Lionad-Morotar. Released under the MIT License.