5.6.84 • Published 11 months ago

@hishprorg/quis-est v5.6.84

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

@hishprorg/quis-est

License: MIT Build Version Known Vulnerabilities GitHub last commit (branch) npm npm total codecov

Blazing fast, tree-shakeable, type-safe, modern utility library to sort any type of array

Docs : https://@hishprorg/quis-est.netlify.app/

Getting started

installation

The library is available as a npm package. To install the package, run:

npm install @hishprorg/quis-est
# or
yarn add @hishprorg/quis-est

Start using:

import {byString} from '@hishprorg/quis-est'

const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"];
const sorted = unsorted.sort(byString());

console.log(sorted); //(5) ["aaa", "bbbb", "cccc", "xxx", "zzz"]

Use directly in the browser

<script src='https://cdn.jsdelivr.net/npm/@hishprorg/quis-est/dist/index.umd.js'></script>
<script>
  const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"];
  const sorted = unsorted.sort(sort.byString());

  console.log(sorted); //(5) ["aaa", "bbbb", "cccc", "xxx", "zzz"]
</script>

//or via browser modules

<script type='module'>
  import {byString} from 'https://cdn.jsdelivr.net/npm/@hishprorg/quis-est/dist/index.mjs'

  const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"];
  const sorted = unsorted.sort(byString());

  console.log(sorted); //(5) ["aaa", "bbbb", "cccc", "xxx", "zzz"]
</script>

Some mind-blowing example

sort by a single property

//js or ts file
import {byValue, byNumber, byString} from '@hishprorg/quis-est'

const arrayUnsorted = [
  {prop: "xxx", foo: 34},
  {prop: "aaa", foo: 325},
  {prop: "zzz", foo: 15},
  {prop: "ccc", foo: 340},
  {prop: "bbb", foo: 0}
];

//this sort by the foo property ascending
const sortedByFoo = arrayUnsorted.sort(byValue((i) => i.foo, byNumber()));
console.log(sortedByFoo); //(5) [{prop: "bbb", foo : 0}, {prop: "zzz", foo: 15}, .....];

//this sort by the prop property descending
const sortedByProp = arrayUnsorted.sort(byValue((i) => i.prop, byString({desc: true})));
console.log(sortedByProp); //(5) [{prop: "zzz", foo : 15}, {prop: "xxx", foo: 34}, .....];

sort by a multiple property

//js or ts file
import {byNumber, byString, byValues} from "@hishprorg/quis-est";

const objsToSort = [
  {id: 2, name: 'teresa'},
  {id: 3, name: 'roberto'},
  {id: 2, name: 'roberto'}
];

//i sort by THEIR NAMES and THEN by their ids
const sortedObject = objsToSort.sort(byValues([
  [(x) => x.name, byString()],
  [(x) => x.id, byNumber()]
]));

console.log(sortedObject); //[{roberto, 2}, {roberto, 3}, {teresa, 2}];

//i sort by THEIR IDS and THEN by their names
const sortedObject2 = objsToSort.sort(byValues([
  [(x) => x.id, byNumber()],
  [(x) => x.name, byString()]
]));
console.log(sortedObject2); //[{roberto, 2}, {teresa, 2}, {roberto, 3}];

//i sort by THEIR IDS and THEN by their names DESCENDING
const sortedObject3 = objsToSort.sort(byValues([
  [(x) => x.id, byNumber()],
  [(x) => x.name, byString({desc: true})],
]));
console.log(sortedObject3); //[{teresa, 2}, {roberto, 2}, {roberto, 3}];

typescript types check

//ts file
import {byValue, byNumber, byString} from '@hishprorg/quis-est'

const objsArray = [{numbProp: 2, stringProp: 'a'}, {numbProp: 3, stringProp: 'f'}];

//Incorrect sort property
const incorrectSortedArray = objsArray.sort(byValue(i => i.numbProp, byString()));
//ts check error : Type 'number' is not assignable to type 'string'.

//Correct sort type
const sortedArray = objsArray.sort(byValue(i => i.numbProp, byNumber()))
//ts check ok

See full Docs

@hishprorg/quis-est.netlify.app

License

MIT © Cosimo chellini

5.6.84

11 months ago

5.6.83

11 months ago

5.6.82

11 months ago

5.6.81

11 months ago

5.6.80

11 months ago

5.6.79

11 months ago

5.6.78

11 months ago

5.6.77

11 months ago

5.6.76

11 months ago

5.6.75

11 months ago

5.6.74

11 months ago

5.6.73

11 months ago

5.6.72

11 months ago

5.5.72

11 months ago

5.5.71

11 months ago

5.5.70

11 months ago

5.5.69

11 months ago

5.5.68

11 months ago

5.5.67

11 months ago

5.5.66

11 months ago

5.5.65

11 months ago

5.5.64

11 months ago

5.5.63

11 months ago

5.5.62

11 months ago

5.5.61

11 months ago

5.5.60

11 months ago

5.5.59

11 months ago

5.5.58

12 months ago

5.5.57

12 months ago

5.5.56

12 months ago

5.4.56

12 months ago

5.3.56

12 months ago

5.3.55

12 months ago

5.3.54

12 months ago

5.3.53

12 months ago

5.3.52

12 months ago

5.3.51

12 months ago

4.3.51

12 months ago

4.3.50

12 months ago

4.2.50

12 months ago

4.1.50

12 months ago

4.1.49

12 months ago

4.1.48

12 months ago

3.1.48

12 months ago

3.1.47

12 months ago

3.1.46

12 months ago

3.1.45

12 months ago

3.1.44

1 year ago

3.1.43

1 year ago

3.1.42

1 year ago

3.1.41

1 year ago

3.1.40

1 year ago

3.1.39

1 year ago

3.1.38

1 year ago

3.0.38

1 year ago

2.0.38

1 year ago

2.0.37

1 year ago

2.0.36

1 year ago

2.0.35

1 year ago

2.0.34

1 year ago

2.0.33

1 year ago

2.0.32

1 year ago

2.0.31

1 year ago

2.0.30

1 year ago

2.0.29

1 year ago

2.0.28

1 year ago

2.0.27

1 year ago

2.0.26

1 year ago

2.0.25

1 year ago

2.0.24

1 year ago

2.0.23

1 year ago

2.0.22

1 year ago

2.0.21

1 year ago

2.0.20

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago