Giter Club home page Giter Club logo

naturalsort.js's Introduction

Simple numerics

['10',9,2,'1','4'].sort(naturalSort);
// ['1',2,'4',9,'10']

Floats

['10.0401',10.022,10.042,'10.021999'].sort(naturalSort);
// ['10.021999',10.022,'10.0401',10.042]

Float & decimal notation

['10.04f','10.039F','10.038d','10.037D'].sort(naturalSort);
// ['10.037D','10.038d','10.039F','10.04f']

Scientific notation

['1.528535047e5','1.528535047e7','1.528535047e3'].sort(naturalSort);
// ['1.528535047e3','1.528535047e5','1.528535047e7']

IP addresses

['192.168.0.100','192.168.0.1','192.168.1.1'].sort(naturalSort);
// ['192.168.0.1','192.168.0.100','192.168.1.1']

Filenames

['car.mov','01alpha.sgi','001alpha.sgi','my.string_41299.tif'].sort(naturalSort);
// ['001alpha.sgi','01alpha.sgi','car.mov','my.string_41299.tif'

Dates

['10/12/2008','10/11/2008','10/11/2007','10/12/2007'].sort(naturalSort);
// ['10/11/2007', '10/12/2007', '10/11/2008', '10/12/2008']

Money

['$10002.00','$10001.02','$10001.01'].sort(naturalSort);
// ['$10001.01','$10001.02','$10002.00']

Movie Titles

['1 Title - The Big Lebowski','1 Title - Gattaca','1 Title - Last Picture Show'].sort(naturalSort);
// ['1 Title - Gattaca','1 Title - Last Picture Show','1 Title - The Big Lebowski']

By default - case-sensitive sorting

['a', 'B'].sort(naturalSort);
// ['B', 'a']

To enable case-insensitive sorting

naturalSort.insensitive = true;
['a', 'B'].sort(naturalSort);
// ['a', 'B']

Authors

  • Original Author: Jim Palmer (based on chunking idea from Dave Koelle)
  • Optimizations and safari fix by Mike Grier (mgrier.com)
  • Scientific notation and alphanumeric sorting fixes by @Mottie

Original code

naturalsort.js's People

Contributors

overset avatar jarinudom avatar mottie avatar

Watchers

James Cloos avatar zhanggj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.