How to use natural-orderby - 4 common examples

To help you get started, we’ve selected a few natural-orderby 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 chriswhong / amazon-orders-collage / assemble-collage.js View on Github external
const fs = require('fs-extra');
const puppeteer = require('puppeteer');
const { orderBy } = require('natural-orderby');

const outputPath = './output/amazon-collage.jpg';

const filenames = fs.readdirSync('product_images');
const sortedFilenames = orderBy(filenames, [v => v], ['asc']);

const gridWidth = 16; // images per row
const gridHeight = Math.ceil(filenames.length / gridWidth); // number of rows

// dimensions and padding for each image
const cellPadding = 20;
const imageDimension = 300; // images will be scaled to this number of pixels square

const cellDimension = imageDimension + (cellPadding * 2);

// padding around the edges of the collage
const outputPadding = 200;

const takeScreenshot = async (htmlPath) => {
  // this is really just the minimum height
  const height = (cellDimension * gridHeight) + (outputPadding * 2);
github nortonandrews / kikoeru / src / server / filesystem / utils.js View on Github external
.then((files) => {
    // Filter out any files not matching these extensions
    const filteredFiles = files.filter((file) => {
      const ext = path.extname(file);

      return (ext === '.mp3' || ext === '.ogg' || ext === '.opus' || ext === '.wav' || ext === '.flac' || ext === '.webm' || ext === '.mp4');
    });

    // Sort by folder and title
    const sortedFiles = orderBy(filteredFiles.map((file) => {
      const shortFilePath = file.replace(path.join(config.rootDir, dir, '/'), '');
      const dirName = path.dirname(shortFilePath);

      return {
        title: path.basename(file),
        subtitle: dirName === '.' ? null : dirName,
      };
    }), [v => v.subtitle, v => v.title]);

    // Add hash to each file
    const sortedHashedFiles = sortedFiles.map(
      (file, index) => ({
        title: file.title,
        subtitle: file.subtitle,
        hash: `${id}/${index}`,
      }),
github dsternlicht / RESTool / src / app / components / main-view / get / get.component.ts View on Github external
this.requestsService.get(this.activeGetRequest.url, this.requestHeaders, queryParams || this.queryParams).subscribe(data => {
        this.loading = false;
        this.data = this.dataPathUtils.extractDataFromResponse(data, this.activeGetRequest.dataPath);

        let sortBy = this.activeGetRequest.display.sortBy;
        if (sortBy) {
          this.data = orderBy(this.data, sortBy);
        }

        this.filterRows();

        if (environment.logApiData) {
          console.log('Got data after dataPath: ', this.data);
        }
      }, error => {
        this.loading = false;
github jo0ger / node-server / app / lib / plugin / egg-codoon / lib / codoon.js View on Github external
let records = await getRecords()

        if (deWeighting) {
            const set = new Set()
            records = records.filter(item => {
                if (set.has(item.routeId)) return false
                return set.add(item.routeId)
            })
        }

        if (onlySupportType) {
            records = records.filter(({ type }) => this.supportSportTypes[type])
        }

        if (sort) {
            records = orderBy(
                records.reverse(),
                v => v.date,
                sort
            )
        }

        if (debug) {
            const fs = require('fs-extra')
            const path = require('path')
            fs.outputJsonSync(path.resolve(__dirname, '../../tmp/sports.json'), records)
        }
        return records
    }

natural-orderby

Lightweight and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

MIT
Latest version published 1 month ago

Package Health Score

88 / 100
Full package analysis

Popular natural-orderby functions