Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
contact-sort
Advanced tools
Sort and group contacts by alphabet.
npm install contact-sort --save
# or
yarn add contact-sort
/**
* @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',
},
],
},
});
});
FAQs
Sort and group contacts by alphabet.
We found that contact-sort demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.