Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contact-sort

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contact-sort

Sort and group contacts by alphabet.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

contact-sort

Sort and group contacts by alphabet.

NPM version build status Test coverage npm download

Install

npm install contact-sort --save
# or
yarn add contact-sort

Usage

/**
 * @jest-environment jsdom
 */

import contactSort from 'contact-sort';


// field: the key of your contact data which is used for sort and group
// data: the array of you contacs whose item must have field value as key;

const mockData = {
  field: 'name',
  data: [
    {
      name: 'Tom',
      description: 'A smart boy',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
    {
      name: 'Sylvia',
      description: 'A beautiful girl',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
    {
      name: 'Jack',
      description: 'A handsome man',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
    {
      name: 'Bill Gates',
      description: 'A successful entrepreneur',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
    {
      name: 'Bryant',
      description: 'A basketball player',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
    {
      name: '小明',
      description: 'A poor guy',
      avatar: 'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
    },
  ],
};

describe('index.ts', () => {
  it('should return correct data', () => {
    expect(contactSort(mockData)).toEqual({
      catalogue: ['B', 'J', 'S', 'T', '#'],
      data: {
        B: [
          {
            name: 'Bill Gates',
            description: 'A successful entrepreneur',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
          {
            name: 'Bryant',
            description: 'A basketball player',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
        ],
        J: [
          {
            name: 'Jack',
            description: 'A handsome man',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
        ],
        S: [
          {
            name: 'Sylvia',
            description: 'A beautiful girl',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
        ],
        T: [
          {
            name: 'Tom',
            description: 'A smart boy',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
        ],
        '#': [
          {
            name: '小明',
            description: 'A poor guy',
            avatar:
              'https://avatars1.githubusercontent.com/u/26563778?s=40&v=4',
          },
        ],
      },
    });
});

Keywords

FAQs

Package last updated on 10 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc