How to use natsort - 4 common examples

To help you get started, we’ve selected a few natsort examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cruise-automation / webviz / packages / webviz-core / src / util / naturalSort.js View on Github external
// @flow
//
//  Copyright (c) 2018-present, Cruise LLC
//
//  This source code is licensed under the Apache License, Version 2.0,
//  found in the LICENSE file in the root directory of this source tree.
//  You may not use this file except in compliance with the License.

import natsort from "natsort";

const sortFn = natsort({ insensitive: true });
export default function naturalSort(key?: string) {
  return key ? (a: any, b: any) => sortFn(a[key], b[key]) : sortFn;
}
github cloudfour / drizzle-builder / src / utils / list.js View on Github external
import R from 'ramda';
import natsort from 'natsort';

const sortObjects = natsort();

/**
 * Sort an array of objects by property.
 *
 * @param {String|Array} prop
 * A property to sort by. If passed as an array, it
 * will be treated as a deep property path.
 *
 * @param {Array} list
 * An array of objects to sort.
 *
 * @return {Array}
 * A sorted copy of the passed array.
 *
 * @example
 * sortByProp('order', items);
github facette / facette / ui / src / views / admin / common / form / template-variables.vue View on Github external
(): Array => {
                const sorter = natsort();
                return cloneDeep(props.value.concat(available.value)).sort((a: TemplateVariable, b: TemplateVariable) =>
                    sorter(a.name, b.name),
                );
            },
        );
github derhuerst / casket / lib / fs.js View on Github external
'use strict'

const fs = require('mz/fs')
const natsort = require('natsort').default({insensitive: true})
const file = require('random-access-file')



const isDir = (dir) =>
	fs.stat(dir)
	.then((s) => s.isDirectory())

const sortFiles = (fileA, fileB) => {
	if (fileA.isDir && !fileB.isDir) return -1
	if (fileB.isDir && !fileA.isDir) return 1
	return natsort(fileA.name, fileB.name)
}

const slice = (path, bytes, offset = 0) => {
	return fs.stat(path)

natsort

Javascript natural sort algorithm with unicode support.

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular natsort functions