New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ayonli/jsext

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ayonli/jsext - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

error/augment.js

26

array/augment.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
Array.prototype.first = function () {
Array.prototype.first = function first() {
return this[0];
};
Array.prototype.last = function () {
Array.prototype.last = function last() {
return this[this.length - 1];
};
Array.prototype.count = function (ele) {
Array.prototype.count = function count(ele) {
return (0, _1.count)(this, ele);
};
Array.prototype.equals = function (another) {
Array.prototype.equals = function equals(another) {
return (0, _1.equals)(this, another);
};
Array.prototype.split = function (delimiter) {
Array.prototype.split = function split(delimiter) {
return (0, _1.split)(this, delimiter);
};
Array.prototype.chunk = function (length) {
Array.prototype.chunk = function chunk(length) {
return (0, _1.chunk)(this, length);
};
Array.prototype.uniq = function () {
Array.prototype.uniq = function uniq() {
return (0, _1.uniq)(this);
};
Array.prototype.shuffle = function () {
Array.prototype.shuffle = function shuffle() {
return (0, _1.shuffle)(this);
};
Array.prototype.toShuffled = function () {
Array.prototype.toShuffled = function toShuffled() {
return this.slice().shuffle();
};
if (!Array.prototype.toReversed) {
Array.prototype.toReversed = function () {
Array.prototype.toReversed = function toReversed() {
return this.slice().reverse();

@@ -37,12 +37,12 @@ };

if (!Array.prototype.toSorted) {
Array.prototype.toSorted = function (fn) {
Array.prototype.toSorted = function toSorted(fn) {
return this.slice().sort(fn);
};
}
Array.prototype.orderBy = function (key, order = "asc") {
Array.prototype.orderBy = function orderBy(key, order = "asc") {
return (0, _1.orderBy)(this, key, order);
};
Array.prototype.groupBy = function (fn, type = Object) {
Array.prototype.groupBy = function orderBy(fn, type = Object) {
return (0, _1.groupBy)(this, fn, type);
};
//# sourceMappingURL=augment.js.map

@@ -1,2 +0,11 @@

import { chunk, count, equals, groupBy, orderBy, shuffle, split, uniq } from ".";
import {
chunk as _chunk,
count as _count,
equals as _equals,
groupBy as _groupBy,
orderBy as _orderBy,
shuffle as _shuffle,
split as _split,
uniq as _uniq
} from ".";

@@ -47,35 +56,35 @@ declare global {

Array.prototype.first = function () {
Array.prototype.first = function first() {
return this[0];
};
Array.prototype.last = function () {
Array.prototype.last = function last() {
return this[this.length - 1];
};
Array.prototype.count = function (ele) {
return count(this, ele);
Array.prototype.count = function count(ele) {
return _count(this, ele);
};
Array.prototype.equals = function (another) {
return equals(this, another);
Array.prototype.equals = function equals(another) {
return _equals(this, another);
};
Array.prototype.split = function (delimiter) {
return split(this, delimiter) as any[];
Array.prototype.split = function split(delimiter) {
return _split(this, delimiter) as any[];
};
Array.prototype.chunk = function (length) {
return chunk(this, length) as any[];
Array.prototype.chunk = function chunk(length) {
return _chunk(this, length) as any[];
};
Array.prototype.uniq = function () {
return uniq(this);
Array.prototype.uniq = function uniq() {
return _uniq(this);
};
Array.prototype.shuffle = function () {
return shuffle(this);
Array.prototype.shuffle = function shuffle() {
return _shuffle(this);
};
Array.prototype.toShuffled = function () {
Array.prototype.toShuffled = function toShuffled() {
return this.slice().shuffle();

@@ -85,3 +94,3 @@ };

if (!Array.prototype.toReversed) {
Array.prototype.toReversed = function () {
Array.prototype.toReversed = function toReversed() {
return this.slice().reverse();

@@ -92,3 +101,3 @@ };

if (!Array.prototype.toSorted) {
Array.prototype.toSorted = function (fn) {
Array.prototype.toSorted = function toSorted(fn) {
return this.slice().sort(fn);

@@ -98,11 +107,11 @@ };

Array.prototype.orderBy = function (key, order = "asc") {
return orderBy(this, key, order);
Array.prototype.orderBy = function orderBy(key, order = "asc") {
return _orderBy(this, key, order);
};
Array.prototype.groupBy = function (
Array.prototype.groupBy = function orderBy(
fn: (item: any, i: number) => any,
type: ObjectConstructor | MapConstructor = Object
): any {
return groupBy(this, fn, type as any);
return _groupBy(this, fn, type as any);
};

@@ -11,2 +11,3 @@ "use strict";

require("./collections/augment");
require("./error/augment");
//# sourceMappingURL=augment.js.map

@@ -9,1 +9,2 @@ import "./string/augment";

import "./collections/augment";
import "./error/augment";

@@ -6,2 +6,3 @@ "use strict";

Number.random = _1.random;
Number.sequence = _1.sequence;
//# sourceMappingURL=augment.js.map

@@ -1,2 +0,2 @@

import { isFloat, random } from ".";
import { isFloat, random, sequence } from ".";

@@ -7,4 +7,6 @@ declare global {

isFloat(value: unknown): boolean;
/** Returns a random integer ranged from `min` to `max`. */
/** Returns a random integer ranged from `min` to `max` (inclusive). */
random(min: number, max: number): number;
/** Creates a generator that produces sequential numbers from `min` to `max` (inclusive). */
sequence(min: number, max: number, step?: number, loop?: boolean): Generator<number, void, unknown>;
}

@@ -15,1 +17,2 @@ }

Number.random = random;
Number.sequence = sequence;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.random = exports.isFloat = void 0;
exports.sequence = exports.random = exports.isFloat = void 0;
/** Returns true if the given value is a float, false otherwise. */

@@ -14,2 +14,21 @@ function isFloat(value) {

exports.random = random;
/** Creates a generator that produces sequential numbers from `min` to `max` (inclusive). */
function* sequence(min, max, step = 1, loop = false) {
let id = min;
while (true) {
yield id;
if (id >= max) {
if (loop) {
id = min;
}
else {
break;
}
}
else {
id += step;
}
}
}
exports.sequence = sequence;
//# sourceMappingURL=index.js.map

@@ -10,1 +10,20 @@ /** Returns true if the given value is a float, false otherwise. */

}
/** Creates a generator that produces sequential numbers from `min` to `max` (inclusive). */
export function* sequence(min: number, max: number, step = 1, loop = false) {
let id = min;
while (true) {
yield id;
if (id >= max) {
if (loop) {
id = min;
} else {
break;
}
} else {
id += step;
}
}
}

@@ -23,3 +23,3 @@ import { hasOwn, omit, patch, pick } from ".";

* NOTE: this function only collect keys from the object's own properties, except for type
* Error, whose `name` and `message` are always collected.
* Error, whose `name`, `message` and `cause` are always collected.
*/

@@ -26,0 +26,0 @@ omit<T extends object, U extends keyof T>(obj: T, keys: U[]): Omit<T, U>;

@@ -36,3 +36,3 @@ "use strict";

if (obj instanceof Error) {
["name", "message"].forEach(key => {
["name", "message", "cause"].forEach(key => {
if (!keys.includes(key) &&

@@ -39,0 +39,0 @@ obj[key] !== undefined &&

@@ -44,3 +44,3 @@ export function hasOwn(obj: any, key: string | number | symbol): boolean {

* NOTE: this function only collect keys from the object's own properties, except for type
* Error, whose `name` and `message` are always collected.
* Error, whose `name`, `message` and `cause` are always collected.
*/

@@ -56,3 +56,3 @@ export function omit<T extends object, U extends keyof T>(obj: T, keys: U[]): Omit<T, U>;

if (obj instanceof Error) {
["name", "message"].forEach(key => {
["name", "message", "cause"].forEach(key => {
if (!keys.includes(key) &&

@@ -59,0 +59,0 @@ (obj as any)[key] !== undefined &&

{
"name": "@ayonli/jsext",
"version": "0.2.0",
"version": "0.3.0",
"description": "Additional functions for JavaScript builtin types that are frequently used in practice.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -77,3 +77,6 @@ # JsExt

- `random(min: number, max: number): number`
- `sequence(min: number, max: number, step?: number, loop?: boolean): Generator<number, void, unknown>`
*When augment, these functions will be attached to the `Number` constructor.*
### array

@@ -162,2 +165,4 @@

*When augment, these functions will be attached to the `Object` constructor.*
### math

@@ -177,2 +182,4 @@

*When augment, these functions will be attached to the `Math` namespace.*
### promise

@@ -192,2 +199,4 @@

*When augment, these functions will be attached to the `Promise` constructor.*
### collections

@@ -204,2 +213,4 @@

**Types**
- `BiMap<K, V>` (extends `Map<K, V>`) Bi-directional map, keys and values are unique and map to each

@@ -214,2 +225,35 @@ other.

*When augment, these types will be exposed to the global namespace.*
### error
```ts
import Exception from "@ayonli/jsext/error/Exception";
// or
import { Exception } from "@ayonli/jsext/error";
// or
import "@ayonli/jsext/error/augment";
```
**Types**
- `Exception` (extends `Error`)
- `cause?: unknown`
- `code: number`
*When augment, these types will be exposed to the global namespace.*
**Functions**
- `toObject<T extends Error>(err: T): { [x: string | symbol]: any; }`
- `fromObject<T extends Error>(obj: { [x: string | symbol]: any; }): T`
**Augment**
- `Error`
- `toObject<T extends Error>(err: T): { [x: string | symbol]: any; }`
- `fromObject<T extends Error>(obj: { [x: string | symbol]: any; }): T`
- `prototype`
- `toJSON(): { [x: string | symbol]: any; }`
## Import All Sub-package Augments At Once

@@ -216,0 +260,0 @@

@@ -6,23 +6,23 @@ "use strict";

String.random = _1.random;
String.prototype.count = function (sub) {
String.prototype.count = function count(sub) {
return (0, _1.count)(String(this), sub);
};
String.prototype.capitalize = function (all) {
String.prototype.capitalize = function capitalize(all) {
return (0, _1.capitalize)(String(this), all);
};
String.prototype.hyphenate = function () {
String.prototype.hyphenate = function capitalize() {
return (0, _1.hyphenate)(String(this));
};
String.prototype.words = function () {
String.prototype.words = function words() {
return (0, _1.words)(String(this));
};
String.prototype.chunk = function (length) {
String.prototype.chunk = function chunk(length) {
return (0, _1.chunk)(String(this), length);
};
String.prototype.truncate = function (length) {
String.prototype.truncate = function truncate(length) {
return (0, _1.truncate)(String(this), length);
};
String.prototype.byteLength = function () {
String.prototype.byteLength = function byteLength() {
return (0, _1.byteLength)(String(this));
};
//# sourceMappingURL=augment.js.map

@@ -1,2 +0,12 @@

import { byteLength, capitalize, chunk, compare, count, hyphenate, random, truncate, words } from ".";
import {
compare,
random,
byteLength as _byteLength,
capitalize as _capitalize,
chunk as _chunk,
count as _count,
hyphenate as _hyphenate,
truncate as _truncate,
words as _words
} from ".";

@@ -37,28 +47,28 @@ declare global {

String.prototype.count = function (sub) {
return count(String(this), sub);
String.prototype.count = function count(sub) {
return _count(String(this), sub);
};
String.prototype.capitalize = function (all) {
return capitalize(String(this), all);
String.prototype.capitalize = function capitalize(all) {
return _capitalize(String(this), all);
};
String.prototype.hyphenate = function () {
return hyphenate(String(this));
String.prototype.hyphenate = function capitalize() {
return _hyphenate(String(this));
};
String.prototype.words = function () {
return words(String(this));
String.prototype.words = function words() {
return _words(String(this));
};
String.prototype.chunk = function (length) {
return chunk(String(this), length);
String.prototype.chunk = function chunk(length) {
return _chunk(String(this), length);
};
String.prototype.truncate = function (length) {
return truncate(String(this), length);
String.prototype.truncate = function truncate(length) {
return _truncate(String(this), length);
};
String.prototype.byteLength = function () {
return byteLength(String(this));
String.prototype.byteLength = function byteLength() {
return _byteLength(String(this));
};

@@ -5,11 +5,11 @@ "use strict";

Uint8Array.compare = _1.compare;
Uint8Array.prototype.equals = function (another) {
Uint8Array.prototype.equals = function equals(another) {
return (0, _1.equals)(this, another);
};
Uint8Array.prototype.split = function (delimiter) {
Uint8Array.prototype.split = function split(delimiter) {
return (0, _1.split)(this, delimiter);
};
Uint8Array.prototype.chunk = function (length) {
Uint8Array.prototype.chunk = function chunk(length) {
return (0, _1.chunk)(this, length);
};
//# sourceMappingURL=augment.js.map

@@ -1,2 +0,2 @@

import { chunk, compare, equals, split } from ".";
import { compare, equals as _equals, split as _split, chunk as _chunk } from ".";

@@ -24,12 +24,12 @@ declare global {

Uint8Array.prototype.equals = function (another) {
return equals(this, another);
Uint8Array.prototype.equals = function equals(another) {
return _equals(this, another);
};
Uint8Array.prototype.split = function (delimiter) {
return split(this, delimiter);
Uint8Array.prototype.split = function split(delimiter) {
return _split(this, delimiter);
};
Uint8Array.prototype.chunk = function (length) {
return chunk(this, length);
Uint8Array.prototype.chunk = function chunk(length) {
return _chunk(this, length);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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