1.0.0 • Published 7 months ago

@wemnyelezxnpm/numquam-tempora-enim v1.0.0

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

@wemnyelezxnpm/numquam-tempora-enim

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://@wemnyelezxnpm/numquam-tempora-enim.netlify.com/

Getting started

installation

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

npm install @wemnyelezxnpm/numquam-tempora-enim
# or
yarn add @wemnyelezxnpm/numquam-tempora-enim

Start using:

import {byString} from '@wemnyelezxnpm/numquam-tempora-enim'

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/@wemnyelezxnpm/numquam-tempora-enim/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/@wemnyelezxnpm/numquam-tempora-enim/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 '@wemnyelezxnpm/numquam-tempora-enim'

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 "@wemnyelezxnpm/numquam-tempora-enim";

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 '@wemnyelezxnpm/numquam-tempora-enim'

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

@wemnyelezxnpm/numquam-tempora-enim.netlify.com

License

MIT © Cosimo chellini

sanitizees7statussymlinkswordwrapsharedStreamwidthsequencepoint-freequeryconsoleInt8ArrayUint8ArraysameValueZerogradients cssreact animationgdprtypeerrorawaitformstatelessassignbootstrap cssstarterYAMLfullwidthwalkingpersistentStreamsrapidwatchingreact-hook-formECMAScript 2022inspectzodcorshandlerslesscssredactfunctional@@toStringTaglimitedponyfillkeyses5css-in-jsargumentTypeScriptlessjsonfull-widthSetwhatwgshimes-shim APIasyncmatchreadableobjtddcompareES2022lengthlookisoperating-systempostcssstylesgetintrinsicmixinspatchupjson-schemawaapiRegExp#flagsinputcallbackinvariantpositiveeslintfile systemcoercibleECMAScript 3japaneseemitclassnamexssjavascripthookscommandenumerableforEachpackagecolortakeparsesorteduuidratedomdeeppicomatchbundlerdropArray.prototype.flatMapdatastructurerangeerrorjwtexit-codeuninstalltranspilecommanderless compilerstyled-componentsasciireducereslintconfigReactiveExtensionsglobECMAScript 6lrudeepclonecall-boundsliceArray.prototype.includesWeakMapnamesES2023JSON-Schemajson-schema-validatorkarmadeep-cloneinternalwordbreakwindowspackage managerspeedarktypedeepcopyfantasy-landtypedarraymochatrimRightdescriptorsregularexec.enves6cryptvalidateRxJStapless.jssyntaxecmascriptcreatedataviewlastsettermergeregexECMAScript 2016Function.prototype.nameECMAScript 2017chromeautoprefixerpure_.extendtesterreact poseframeworkinstalldescriptorfunctionstringifierfastifyprefixqueueMicrotaskcode pointsthreeless cssl10napollocircularevents0MapsearchlistenersnodeCSSStyleDeclarationbuffersassertES2018fixed-widthrobuststringcolourcss variablejson-schema-validationPromiseratelimitpromisesPushflateslintpluginsafeIteratormake dirparserArray.prototype.findLastworkspace:*classesspinnersharedarraybufferes2018ECMAScript 2015bytemodulesspinnersgenericsweboffsetreusecharacterstaskregexppropertygraphqlwhichlintdeep-copycollectionRxextraconfigurableweaksetperformancereact-hooksremovejsonpathES8stringifytouchio-tsletdeleteauthshrinkwrapFloat32ArraylazydataViewobjectformatthroata11yprivate datatrimEndmakefastclonepluginvisualnpmbufferrequesttypanionreduceArrayBuffer.prototype.slicehigher-orderdirwriteArrayBuffer#sliceenvECMAScript 2021hashObject.entriesincludesbatchsideemojieslint-pluginargvsymbolsaccessorargparsestylemoduleES7telephonebyteOffsetpreprocessoropeni18nyamlchannelkoreanexpressformattingfullUint8ClampedArraydotenves8ECMAScript 2023eventDispatcherequaleast-asian-widthMicrosoftfseventsirqnameHyBiRegExp.prototype.flagsvestquotepropertiesmovewatchFilecore-jsairbnbfastcopyes-abstractutilstypesWeakSetformsutilitytraverserandomdiffform-validationvalidinternal sloturlposeSymbolBigUint64ArrayfindxhrcheckUint32ArrayWebSocketTypeBoxviewUnderscorenopegettestingmatchestacitimmutableprogresstostringtagwatchsetImmediatedefinetermnodejsparentdebugcensorisConcatSpreadablevalidatorlanguagerequiretslib
1.0.0

7 months ago