1.0.0 • Published 2 months ago

@devtea2025/aliquam-impedit-inventore-eius v1.0.0

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

@devtea2025/aliquam-impedit-inventore-eius

ts Npm package yearly downloads Quality Gate Status Coverage Duplicated Lines (%) Lines of Code Maintainability Rating Reliability Rating Security Rating

@devtea2025/aliquam-impedit-inventore-eius is a versatile utility library that simplifies sorting arrays of objects by one or multiple object keys. It allows you to specify the sort direction for each key, providing fine-grained control over the sorting process.

Table of Contents

Installation

You can install @devtea2025/aliquam-impedit-inventore-eius via yarn or npm:

Using yarn

yarn add @devtea2025/aliquam-impedit-inventore-eius

Using npm

npm install @devtea2025/aliquam-impedit-inventore-eius

Usage

Here's how you can use @devtea2025/aliquam-impedit-inventore-eius:

import { compareBy } from '@devtea2025/aliquam-impedit-inventore-eius';
const arr = [{
    name: {
      first: 'John',
      last: 'Doe'
    },
    birthday: new Date(1998, 10, 20),
    profileConfirmed: true,
    age: 24
  },
  /* ... */
];

// sort by single key
arr.sort(compareBy({
  key: 'age',
  dir: 'desc', // 'asc' | 'desc', default: 'asc'
}));

// sort by nested key
arr.sort(compareBy({
  key: (obj) => obj.name.first,
}));

// sort by multiple keys
arr.sort(compareBy([
  { key: 'profileCreated' },
  { key: (obj) => obj.name.last, dir: 'desc' }
]));

Examples

Sort by a Single Object Key

Ascending Order

const arr = [{ x: 'b' }, { x: 'a' }, { x: 'c' }];
arr.sort(compareBy({ key: 'x' }));
console.log(arr); // [{ x: 'a' }, { x: 'b' }, { x: 'c' }]

Descending Order

const arr = [{ x: 'b' }, { x: 'a' }, { x: 'c' }];
arr.sort(compareBy({ key: 'x', dir: 'desc' }));
console.log(arr); // [{ x: 'c' }, { x: 'b' }, { x: 'a' }]

Sort by a Nested Object Key

Ascending Order

const arr = [{ x: { y: 'b' } }, { x: { y: 'a' } }];
arr.sort(compareBy({ key: (el) => el.x.y }));
console.log(arr); // [{ x: { y: 'a' } }, { x: { y: 'b' } }]

Descending Order

const arr = [{ x: { y: 'a' } }, { x: { y: 'b' } }];
arr.sort(compareBy({ key: (el) => el.x.y, dir: 'desc' }));
console.log(arr); // [{ x: { y: 'b' } }, { x: { y: 'a' } }]

Sort by Multiple Keys

const arr = [
	{ x: 'c', y: 'c' },
	{ x: 'b', y: 'a' },
	{ x: 'b', y: 'b' },
];
arr.sort(compareBy([
  { key: 'x' }, // sort by 'x' in ascending order
  { key: 'y', dir: 'desc' } // sort by 'y' in descending order
]));

console.log(arr);
/**
 * [
 *   { x: 'b', y: 'b' },
 *   { x: 'b', y: 'a' },
 *   { x: 'c', y: 'c' },
 * ]
 */

Project Badges

  • Npm Package Version: The current version of the npm package.
  • Quality Gate Status: Measures the quality of the code using SonarQube.
  • Coverage: Shows the code coverage of your project.
  • Duplicated Lines (%): Indicates the percentage of duplicated lines in your code.
  • Lines of Code: Displays the total lines of code in your project.
  • Maintainability Rating: Rates the maintainability of your code.
  • Reliability Rating: Rates the reliability of your code.
  • Security Rating: Rates the security of your code.

License

This project is licensed under the MIT License.

Author

Tobias Wälde

Acknowledgments

If your project is inspired by or uses other open-source projects, acknowledge them here. It's a good practice and shows respect to the open-source community.

Feel free to customize the author's name, website, license, contribution guidelines, and code of conduct links according to your project's specifics. This improved README provides more context and is well-structured to help users understand, install, and use your library effectively.

ES2023weaksetshebangArray.prototype.findLastIndexratelimitwafstylesheetflatMapclassnamedependency managercolourexecutablel10nextendTypedArraycss-in-jsforEachgetOwnPropertyDescriptorpicomatchestreephoneoptimistform-validationArray.prototype.containsECMAScript 5dependencieslintES2018writablesharedarraybufferless.js@@toStringTaglibphonenumber256ES3xdges8nopeassigncallpyyamldatastructureprivateprogresscallbindexiturlsfastifyregularoptioncontainssimpledbhelpersObject.isunicodeconfigwatchFilepasswordIteratorparsertddawaitcall-bindemrmkdirsequencethrottleUint16Arraydeepemitprototypeansiimmutablecompareeslint-pluginSymbolspinnersbindObject.keystypedtypedarraysshrinkwrapbyteOffsettermeslinttsfseventsautoscalingArrayvisuallastirqsuperstructeverycompile lessmapreducestreamssetImmediateaccessibilityflagstypesafeloggingchromiumfastelbobjnested cssObject.getPrototypeOfserializationsearchchildES5fast-clonepostcss-pluginmkdirshardlinksconsumeconcatformattingArray.prototype.flattennegativeinlessparentsECMAScript 7createObservablesconsoleclassnamescharacterWebSocketauthenticationArrayBufferworkspace:*testerframeworkmake dirkeyscodesfunctionsrapidsharedwordbreaktapesortedeventDispatcherStreambluebirdformInt16ArrayRFC-6455ES2017bootstrap lessastinstallerjwtes6pipemimetypescryptoglobalsoperating-systemObject.valuesflattenmergeemojideterministictypedarrayinstalllimitedmruextraflagutilityStyleSheetwatcherCSSRxdeepcopyECMAScript 2016ECMAScript 2020validatetoStringTagargparsereplayArray.prototype.flattraversegradients css3ES2019eslintconfigrfc4122arktypeaccessorexebusytoSortednameskarmadeletetypescriptdataviewsymboltrimStartdebuggerenvstatusnodejsTypeBoxmulti-packageESnextargvjsdomhasOwnPropertysqsextensionreducerargscolorsawesomesauceidlefullArray.prototype.includesbrowsera11ystreames-abstractstringifyinputarrayselmieJSONtrimLeftvestslotArray.prototype.findLastclassescss variablerangeerrorfile systemhasOwnArrayBuffer.prototype.sliceUint32Arrayasyncrm -frMapmovesigintless compilerstoragegatewaytyped arraycopyES2022react-hooksloadbalancingsignalargumentsfull-widthlookpushwebsitefilterECMAScript 3readabletapenumerablegenerics[[Prototype]]routerInt8Arrayyupec2regexauthapitypeerrorwgetdropdataBigUint64ArraySymbol.toStringTagFloat64ArrayspecassertECMAScript 2021omitlinewrapcolumnsbufferpackage.jsondeepclonedefinePropertydescriptionelasticacheutil.inspectprettyStreamsjQueryesgroupBy-0fpsoptimizerWeakSetassertionObject.definePropertyutilECMAScript 2017queueMicrotaskoutputArrayBuffer#sliceopenspolyfillwalking$.extendArray.prototype.flatMapquotefromtypeofopenergetoptES2015styled-componentsenderFloat32ArraytrimEndclonevariablesECMAScript 2022xhrperformancelazygetPrototypeOfURLSearchParamscheckdiffweakmapenvironmentarraycode pointsownagenttrimiamruntimeecmascriptimporttypesfindLastUnderscorepositivedynamodbintrinsicregexpeditorES2021matchAllhigher-orderjsonpathpackagemacoses2015mimeinvariantRegExp#flagsjsdiffidentifiersstarterbeanstalkglacierassertslinkprocessjestrgblimitfindLastIndexfast-deep-clonecollectionprefixreal-timeqssliceES6snsYAMLfiglet
1.0.0

2 months ago