utility-hand
Advanced tools
Comparing version 1.0.2 to 1.0.3
34
index.js
@@ -1,19 +0,25 @@ | ||
Array.prototype.numSort = function () { | ||
for (let i = 0; i < this.length; i++) { | ||
for (let j = 0; j < this.length - i - 1; j++) { | ||
if (this[j] > this[j + 1]) { | ||
let temp = this[j]; | ||
this[j] = this[j + 1]; | ||
this[j + 1] = temp; | ||
} | ||
Array.prototype.numSort = function (order = 'ascending') { | ||
return this.sort((a, b) => { | ||
if (order === 'ascending') { | ||
return a - b; | ||
} else if (order === 'descending') { | ||
return b - a; | ||
} else { | ||
throw new Error("Order must be 'ascending' or 'descending'"); | ||
} | ||
} | ||
return this; | ||
}); | ||
} | ||
// Exporting a function that uses the Array.prototype.numSort | ||
function sortArray(arr) { | ||
return arr.numSort(); | ||
function numSort(arr, order = 'ascending') { | ||
return arr.numSort(order); | ||
} | ||
module.exports = { sortArray }; | ||
String.prototype.trimAll = function () { | ||
return this.replace(/\s+/g, ' ').trim(); | ||
} | ||
function trimAll(str) { | ||
return str.trimAll() | ||
} | ||
module.exports = { numSort, trimAll }; |
{ | ||
"name": "utility-hand", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "index.js", | ||
@@ -9,2 +9,2 @@ "scripts": {}, | ||
"description": "" | ||
} | ||
} |
@@ -1,1 +0,15 @@ | ||
# utility-hand | ||
# utility-hand | ||
This module provides utility functions for sorting arrays and manipulating strings. It extends the native JavaScript `Array` and `String` prototypes with custom methods and includes standalone functions for use in various JavaScript applications. | ||
## Features | ||
- **Array.prototype.numSort**: Sorts an array of numbers in ascending or descending order. | ||
- **String.prototype.trimAll**: Removes extra whitespace from a string, collapsing multiple spaces into a single space and trimming leading/trailing spaces. | ||
## Installation | ||
To use these functions, simply require the module in your JavaScript file: | ||
```javascript | ||
const { numSort, trimAll } = require('utility-hand'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1471
21
16