1.1.18 • Published 11 months ago

sort-by-chapter v1.1.18

Weekly downloads
13
License
MIT
Repository
github
Last release
11 months ago

sort-by-chapter

Creates an array of elements, sorted in ascending order by the element chapter number string or by specific attribute chapter number string.

Inline docs Coverage Status

Examples

Basic

import sortByChapter from 'sort-by-chapter';

const arr = [
  'Goal 1',
  'Goal 2',
  'Goal 3',
  'Strategy 1.1',
  'Strategy 1.2',
  'Strategy 1.3',
  'Activity 1.1.1',
  'Activity 1.1.2',
  'Activity 1.1.3',
];
const newArr = sortByChapter(arr);
console.log(newArr);
[ 'Goal 1',
  'Strategy 1.1',
  'Activity 1.1.1',
  'Activity 1.1.2',
  'Activity 1.1.3',
  'Strategy 1.2',
  'Strategy 1.3',
  'Goal 2',
  'Goal 3' ]

Specify Attribute

import sortByChapter from 'sort-by-chapter';

const arr = [
  { title: 'Goal 1',
  { title: 'Goal 2' },
  { title: 'Goal 3' },
  { title: 'Strategy 1.1' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' }
];
const newArr = sortByChapter(arr, { attribute: 'title' });
console.log(newArr);

or

import sortByChapter from 'sort-by-chapter';

const arr = [
  { title: 'Goal 1',
  { title: 'Goal 2' },
  { title: 'Goal 3' },
  { title: 'Strategy 1.1' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' }
];
const newArr = sortByChapter(arr, 'title');
console.log(newArr);
[ { title: 'Goal 1' },
  { title: 'Strategy 1.1' },
  { title: 'Activity 1.1.1' },
  { title: 'Activity 1.1.2' },
  { title: 'Activity 1.1.3' },
  { title: 'Strategy 1.2' },
  { title: 'Strategy 1.3' },
  { title: 'Goal 2' },
  { title: 'Goal 3' } ]
1.1.15

11 months ago

1.1.14

11 months ago

1.1.18

11 months ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.15

5 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.11

6 years ago

1.0.12

6 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.0

7 years ago