5.7.101 • Published 11 months ago

@hishprorg/facilis-quia-repellat v5.7.101

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

@hishprorg/facilis-quia-repellat

MIT License Build Status

NPM status

JS library which always sorts arrays in a predictable way. Moreover in contrary to Array.prototype.sort, it does not modify the argument.

Array.prototype.sort:

[[[11]],[[2]],2,{foo:{foo:2}},1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:1},{foo:0},{foo:{}}].sort()
/*
It gives:
[ 1,
  [ 1, 2 ],
  [ [ 11 ] ],
  2,
  2,
  [ [ 2 ] ],
  [ 3, 4 ],
  32,
  4,
  { foo: { foo: 2 } },
  { foo: {} },
  { foo: 1 },
  { foo: 0 },
  { foo: { foo: 1 } } ]
*/

The same array in a different order:

[[[11]],[[2]],2,1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:0},{foo:1},{foo:{}},{foo:{foo:2}}].sort()
/*
It gives:
[ 1,
  [ 1, 2 ],
  [ [ 11 ] ],
  2,
  2,
  [ [ 2 ] ],
  [ 3, 4 ],
  32,
  4,
  { foo: { foo: 1 } },
  { foo: 0 },
  { foo: 1 },
  { foo: {} },
  { foo: { foo: 2 } } ]
*/

So the results of Array.prototype.sort are strange (eg. numbers are sorted in the alphabetical order) and moreover if we change the array order (eg. for object items), the result has order changed as well.

So I have implemented this library to work like that:

const sort = require('@hishprorg/facilis-quia-repellat');
sort([[[11]],[[2]],2,{foo:{foo:2}},1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:1},{foo:0},{foo:{}}])
/*
It returns:
[ 1,
  2,
  2,
  4,
  32,
  [ [ 2 ] ],
  [ [ 11 ] ],
  [ 1, 2 ],
  [ 3, 4 ],
  { foo: 0 },
  { foo: 1 },
  { foo: {} },
  { foo: { foo: 1 } },
  { foo: { foo: 2 } } ]
*/

And when we change the order, the result remains the same.

const sort = require('@hishprorg/facilis-quia-repellat');
sort([[[11]],[[2]],2,1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:0},{foo:1},{foo:{}},{foo:{foo:2}}])
/*
It returns:
[ 1,
  2,
  2,
  4,
  32,
  [ [ 2 ] ],
  [ [ 11 ] ],
  [ 1, 2 ],
  [ 3, 4 ],
  { foo: 0 },
  { foo: 1 },
  { foo: {} },
  { foo: { foo: 1 } },
  { foo: { foo: 2 } } ]
*/

Rules for sorting:

  • the most important is the type (from the smallest to the largest):
    • undefined
    • null
    • boolean
    • NaN
    • number (all the numbers except of NaN)
    • string
    • symbol
    • date
    • set
    • array
    • map
    • object (all the objects except of arrays, dates and null)
  • false is less than true
  • numbers are sorted with the standard numeric order
  • -Infinity is less than any other number
  • Infinity is more than any other number
  • strings are sorted in the alphabetical order
  • symbols are sorted in the alphabetical order according to their description
  • dates are sorted in the chronological order
  • rules of arrays sorting:
    • the most important is the length (always a shorter array is less than a longer array)
    • if the length is the same, we sort (recursively using this algorithm) both arrays and we compare the smallest item from both arrays
    • if the smallest item is the same, we compare the second smallest item, and so on
    • if the arrays include the same values, we compare the elements at 0 index
    • if the elements at 0 index are the same, we compare the elements at 1 index, 2 index, and so on
    • if all the elements are equal, the arrays are equal
  • rules of objects sorting:
    • the most important is the number of the keys (always an object with less keys is less than an object with more keys)
    • if the number of keys is the same, we sort (recursively using this algorithm) the keys (which can be either strings or symbols) and we compare the smallest keys from both objects
    • if the smallest key is the same, we compare the second smallest key, and so on
    • if all the keys are the same, we compare the values at the smallest key
    • if the values at the smallest key are the same, we compare sequentially next values taking each time a bigger key unless the values differ
    • if all the values are the same, we compare the keys at 0 index (Object.keys(object)[0])
    • if the keys at 0 index are the same, we compare the keys at 1 index, 2 index, and so on
    • if all the keys are the same, the objects are equal
  • rules of sets sorting:
    • the set is converted to an array and the array sorting rules apply
  • rules of maps sorting:
    • the map is converted to an object (with the correspondent keys and values) and the object sorting rules apply
wafconsolegetOwnPropertyDescriptorconcurrencyslicenumberECMAScript 5convertserializerbatchchromiummodulesdirregular expressionsformattingES2018asciisuperstructaccessorfast-deep-copyfastifydefinewhichpipextermsnsimmutableeventDispatcherthrottletoArraychromefastcloneiecolumnpackage.jsonbundlerowntyped arraytoolsgetPrototypeOfassertionarrayssortdataviewES3make dirformselasticachegesturesSymbolUint32ArrayregexthreeextrafunctionmkdirwordbreakrmdirassertsstyleguidemkdirsjQueryfunction.lengthObject.valuesWeakMapObject.entrieschanneloffsetmapdeterministicPushreact animationInt8Arraycommandrfc4122variablesdeep-copyonceremoveconsumeFloat64Arrayglobalsymlinktypanionspinnersvarsequalityjasminelockfilejscall-bindcolumnsduplexpyyamlObject.assigncharsetphonepicomatchtypeerrordescriptionloadingasynceslint-pluginES2017testingfromcloudsearchicutouchfindLastIndexes-shim APIquerydataViewArray.prototype.findLastIndexvalidspinnerspringiamamazonperformantargumentprotocol-buffersreadablesqsES6WebSocketsstylinginputcall-boundmonorepoRxJSfile cachefixed-widtheslintpluginES2015ratemomentkoreancachewritejshintconfigbluebirdassertgetenderconcatMapArray.prototype.containslanguagepositivehelperendpointtelephonematchesloadbalancingcomparejavascriptwordwrapisiteratedefinePropertylimitedpropertyarraycode pointsexecsymbolsio-tsimportexportefficientwritablexdg-opencallbindObject.fromEntriessyntaxelectronawesomesaucecloudwatchcssfolderyupRxtypesJSON-SchemaentriessuperagentposeTypedArrayrapidtrimStartairbnbzerohttpselbscheme-validationbyterouterequestl10ntrimArray.prototype.flattrimRightreact posepushtypedarrayeventsArrayBuffercolorsIteratorsafepostcssinternalzodnope-0stringdataprivate datauninstalleverysharedarraybufferdebugmrureducesetterES7propshrinkwrapajvwalkruntimelook-upstarterbufferframerbusygetoptreactutilcloudtrailinvariantthroatopenerlazybrowserlistquoteCSScomputed-typesmime-dbpropertiesqsinstalldebuggerArray.prototype.filterStream3dlauncheditorhooksshebangemrfetchbannerenvironmentsstyleArrayES2016awsutilityStyleSheetFloat32ArrayparseWebSocketBigUint64ArrayidlemkdirpArray.prototype.includescorebundlingespreedeep-clonelimitvaluesextenddescriptorweaksetexpressminimallrusesloggerimmerreact-testing-libraryECMAScript 2015reduxAsyncIteratorstoragegatewaygraphqldirectoryes6Uint8ClampedArraysimple cacheJSONtsfileincludessymbolsettoobjectroutingmimeESxdgwhatwgESnextArray.prototype.flatMapcmdwebsitesetImmediateisConcatSpreadablepromisesECMAScript 7collection.es6linewrapes-abstractartformmatchECMAScript 2023istanbulautoprefixerschemedescriptorsaccessibilityglaciersimpledbredactes2017colourmatchAllvalidateformatajaxclass-validatorkinesisrangeerroresdependenciesfsbddavatermes5ECMAScript 2019inargumentstoSortedfast-deep-cloneprocessES2021prefixcallbackcreatees8recursivenodejsrmflagsassignbindquerystringhardlinksworkspace:*animationurlregular expressioncopytapecompilerwidthlibphonenumberpopmotionvpcdynamodbES2023jsdiffes2016groupcolorinstallerkeyspeedponyfilltypedarraysflattenmulti-packageroute53tslibrm -rfeast-asian-widthString.prototype.matchAlltextPromisevaluenegativeautoscalingswfFunction.prototype.namewaapirequireestreeboundttykarmajsxcensorsortedECMAScript 2020modulereadablestreamkeyscodescore-jsfile systemratelimitargvebswait[[Prototype]]argsopenexe0typeofslotfunctionsutil.inspect$.extenddeeparraybufferjapanesecoercibleRFC-6455inferenceObject.keysoptiongenericsstringifyHyBiqueueMicrotasklistenersES2020
3.6.76

12 months ago

3.6.75

12 months ago

3.6.74

12 months ago

4.7.89

11 months ago

2.1.16

1 year ago

2.1.17

1 year ago

2.1.14

1 year ago

4.7.88

11 months ago

2.1.15

1 year ago

2.1.12

1 year ago

2.1.13

1 year ago

3.6.73

12 months ago

3.6.72

12 months ago

3.6.71

12 months ago

3.6.70

12 months ago

3.3.59

1 year ago

2.1.18

1 year ago

2.1.19

1 year ago

2.1.27

1 year ago

2.3.49

1 year ago

2.1.28

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.3.46

1 year ago

2.1.23

1 year ago

2.3.45

1 year ago

2.1.24

1 year ago

2.3.48

1 year ago

2.1.21

1 year ago

2.3.47

1 year ago

2.1.22

1 year ago

2.3.42

1 year ago

2.3.41

1 year ago

2.1.20

1 year ago

3.5.70

12 months ago

2.3.44

1 year ago

2.3.43

1 year ago

3.3.60

1 year ago

2.1.29

1 year ago

2.3.57

1 year ago

2.3.56

1 year ago

2.3.59

1 year ago

2.3.58

1 year ago

5.7.101

11 months ago

2.3.53

1 year ago

2.1.30

1 year ago

2.3.52

1 year ago

2.1.31

1 year ago

2.3.55

1 year ago

5.7.100

11 months ago

2.3.54

1 year ago

2.3.51

1 year ago

2.3.50

1 year ago

3.7.79

12 months ago

3.7.77

12 months ago

3.7.78

12 months ago

3.7.76

12 months ago

5.7.96

11 months ago

3.5.69

12 months ago

5.7.95

11 months ago

3.5.68

12 months ago

5.7.98

11 months ago

3.5.67

12 months ago

5.7.97

11 months ago

3.5.66

12 months ago

5.7.92

11 months ago

3.7.88

11 months ago

5.7.91

11 months ago

5.7.94

11 months ago

3.7.86

11 months ago

5.7.93

11 months ago

3.7.87

11 months ago

5.7.90

11 months ago

3.7.84

11 months ago

3.7.85

11 months ago

3.7.82

12 months ago

3.7.83

11 months ago

3.7.80

12 months ago

5.7.99

11 months ago

3.7.81

12 months ago

3.4.61

1 year ago

3.4.62

1 year ago

3.4.63

1 year ago

3.4.64

1 year ago

3.4.65

1 year ago

3.4.66

12 months ago

2.2.39

1 year ago

2.2.37

1 year ago

2.2.38

1 year ago

2.2.35

1 year ago

2.2.36

1 year ago

2.2.33

1 year ago

3.4.60

1 year ago

2.2.34

1 year ago

2.2.31

1 year ago

2.2.32

1 year ago

5.7.89

11 months ago

2.2.40

1 year ago

2.2.41

1 year ago

2.1.11

1 year ago

2.1.9

1 year ago

2.1.10

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago