JSPM

contact-sort

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q22984F
  • License MIT

Sort and group contacts by alphabet.

Package Exports

  • contact-sort

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (contact-sort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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',
          },
        ],
      },
    });
});