diff --git a/README.md b/README.md index 40fa884..52ca885 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # alphanum-compare +[![npm version](https://badge.fury.io/js/alphanum-compare.svg)](https://badge.fury.io/js/alphanum-compare) [![Node.js CI](https://github.com/tsekityam/alphanum-compare/actions/workflows/test.yml/badge.svg)](https://github.com/tsekityam/alphanum-compare/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/tsekityam/alphanum-compare/branch/main/graph/badge.svg?token=DHFqZcVnZR)](https://codecov.io/gh/tsekityam/alphanum-compare) [![Known Vulnerabilities](https://snyk.io/test/github/tsekityam/alphanum-compare/badge.svg)](https://snyk.io/test/github/tsekityam/alphanum-compare) @@ -16,10 +17,18 @@ Compare function extrated from [alphanum-sort](https://github.com/trysound/alpha ```ts import compareFn from "alphanum-compare"; -const result = ["item20", "item19", "item1", "item10", "item2"].sort(compareFn); +console.log("5".localeCompare("10")); // 1, NO GOOD +console.log(compareFn("5", "10")); // -1, GOOD + +console.log(compareFn("-5", "5")); // 1, NO GOOD +console.log(compareFn("-5", "5", { sign: true })); // -1, GOOD + +console.log(["item20", "item19", "item1", "item10", "item2"].sort(compareFn)); // ['item1', 'item2', 'item10', 'item19', 'item20'] ``` +[CodeSandbox](https://codesandbox.io/s/alphanum-compare-demo-bfhln) + ### `compareFn(a: string, b: string, opts?: { sign?: boolean }): number` It returns a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise.