Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utility-hand

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utility-hand - npm Package Compare versions

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');
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc