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.6.26 to 0.6.27

6

array/augment.ts
import {
first as _first,
last as _last,
chunk as _chunk,

@@ -71,7 +73,7 @@ count as _count,

Array.prototype.first = function first() {
return this[0];
return _first(this);
};
Array.prototype.last = function last() {
return this[this.length - 1];
return _last(this);
};

@@ -78,0 +80,0 @@

@@ -8,2 +8,12 @@ import { isSubclassOf } from "../mixins.ts";

/** Returns the first element of the array, or `undefined` if the array is empty. */
export function first<T>(arr: T[]): T | undefined {
return arr[0];
}
/** Returns the last element of the array, or `undefined` if the array is empty. */
export function last<T>(arr: T[]): T | undefined {
return arr.length > 0 ? arr[arr.length - 1] : undefined;
}
/** Returns a random element of the array, or `undefined` if the array is empty. */

@@ -10,0 +20,0 @@ export function random<T>(arr: T[], remove = false): T | undefined {

@@ -6,6 +6,6 @@ 'use strict';

Array.prototype.first = function first() {
return this[0];
return array_index.first(this);
};
Array.prototype.last = function last() {
return this[this.length - 1];
return array_index.last(this);
};

@@ -12,0 +12,0 @@ Array.prototype.random = function random(remove = false) {

@@ -6,2 +6,10 @@ 'use strict';

/** Returns the first element of the array, or `undefined` if the array is empty. */
function first(arr) {
return arr[0];
}
/** Returns the last element of the array, or `undefined` if the array is empty. */
function last(arr) {
return arr.length > 0 ? arr[arr.length - 1] : undefined;
}
/** Returns a random element of the array, or `undefined` if the array is empty. */

@@ -205,4 +213,6 @@ function random(arr, remove = false) {

exports.equals = equals;
exports.first = first;
exports.groupBy = groupBy;
exports.keyBy = keyBy;
exports.last = last;
exports.orderBy = orderBy;

@@ -209,0 +219,0 @@ exports.random = random;

@@ -12,8 +12,17 @@ 'use strict';

* number, a bigint, or a string that can be converted to a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
function isNumeric(value) {
function isNumeric(value, strict = false) {
const type = typeof value;
if (type === "number" || type === "bigint") {
if (strict) {
return type === "number" && !Number.isNaN(value);
}
else if (type === "bigint") {
return true;
}
else if (type === "number") {
return !Number.isNaN(value);
}
else if (type === "string" && value) {

@@ -20,0 +29,0 @@ try {

@@ -1,8 +0,8 @@

import { random, count, equals, split, chunk, uniq, shuffle, orderBy, groupBy, keyBy } from './index.js';
import { first, last, random, count, equals, split, chunk, uniq, shuffle, orderBy, groupBy, keyBy } from './index.js';
Array.prototype.first = function first() {
return this[0];
Array.prototype.first = function first$1() {
return first(this);
};
Array.prototype.last = function last() {
return this[this.length - 1];
Array.prototype.last = function last$1() {
return last(this);
};

@@ -9,0 +9,0 @@ Array.prototype.random = function random$1(remove = false) {

import { isSubclassOf } from '../mixins.js';
import { random as random$1 } from '../number/index.js';
/** Returns the first element of the array, or `undefined` if the array is empty. */
function first(arr) {
return arr[0];
}
/** Returns the last element of the array, or `undefined` if the array is empty. */
function last(arr) {
return arr.length > 0 ? arr[arr.length - 1] : undefined;
}
/** Returns a random element of the array, or `undefined` if the array is empty. */

@@ -199,3 +207,3 @@ function random(arr, remove = false) {

export { chunk, count, equals, groupBy, keyBy, orderBy, random, shuffle, split, uniq };
export { chunk, count, equals, first, groupBy, keyBy, last, orderBy, random, shuffle, split, uniq };
//# sourceMappingURL=index.js.map

@@ -10,8 +10,17 @@ /** Returns `true` if the given value is a float number, `false` otherwise. */

* number, a bigint, or a string that can be converted to a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
function isNumeric(value) {
function isNumeric(value, strict = false) {
const type = typeof value;
if (type === "number" || type === "bigint") {
if (strict) {
return type === "number" && !Number.isNaN(value);
}
else if (type === "bigint") {
return true;
}
else if (type === "number") {
return !Number.isNaN(value);
}
else if (type === "string" && value) {

@@ -18,0 +27,0 @@ try {

@@ -5,3 +5,3 @@ import { isBetween, isFloat, isNumeric, random, sequence } from "./index.ts";

interface NumberConstructor {
/** Returns true if the given value is a float, false otherwise. */
/** Returns `true` if the given value is a float, `false` otherwise. */
isFloat(value: unknown): boolean;

@@ -11,4 +11,7 @@ /**

* is a number, a bigint, or a string that can be converted as a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
isNumeric(value: unknown): boolean;
isNumeric(value: unknown, strict?: boolean): boolean;
/** Return `true` if a number is between the given range (inclusive). */

@@ -15,0 +18,0 @@ isBetween(value: number, [min, max]: [number, number]): boolean;

@@ -11,8 +11,15 @@ /** Returns `true` if the given value is a float number, `false` otherwise. */

* number, a bigint, or a string that can be converted to a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
export function isNumeric(value: unknown): boolean {
export function isNumeric(value: unknown, strict = false): boolean {
const type = typeof value;
if (type === "number" || type === "bigint") {
if (strict) {
return type === "number" && !Number.isNaN(value)
} else if (type === "bigint") {
return true;
} else if (type === "number") {
return !Number.isNaN(value);
} else if (type === "string" && value) {

@@ -19,0 +26,0 @@ try {

{
"name": "@ayonli/jsext",
"version": "0.6.26",
"version": "0.6.27",
"description": "Additional functions for JavaScript to build strong applications.",

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

@@ -1024,2 +1024,4 @@ # JsExt

- `first<T>(arr: T[]): T | undefined`
- `last<T>(arr: T[]): T | undefined`
- `random<T>(arr: T[], remove?: boolean): T | undefined`

@@ -1026,0 +1028,0 @@ - `count<T>(arr: RealArrayLike<T>, ele: T): number`

export interface RealArrayLike<T> extends ArrayLike<T> {
slice(start?: number, end?: number): RealArrayLike<T>;
}
/** Returns the first element of the array, or `undefined` if the array is empty. */
export declare function first<T>(arr: T[]): T | undefined;
/** Returns the last element of the array, or `undefined` if the array is empty. */
export declare function last<T>(arr: T[]): T | undefined;
/** Returns a random element of the array, or `undefined` if the array is empty. */

@@ -5,0 +9,0 @@ export declare function random<T>(arr: T[], remove?: boolean): T | undefined;

declare global {
interface NumberConstructor {
/** Returns true if the given value is a float, false otherwise. */
/** Returns `true` if the given value is a float, `false` otherwise. */
isFloat(value: unknown): boolean;

@@ -8,4 +8,7 @@ /**

* is a number, a bigint, or a string that can be converted as a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
isNumeric(value: unknown): boolean;
isNumeric(value: unknown, strict?: boolean): boolean;
/** Return `true` if a number is between the given range (inclusive). */

@@ -12,0 +15,0 @@ isBetween(value: number, [min, max]: [number, number]): boolean;

@@ -6,4 +6,7 @@ /** Returns `true` if the given value is a float number, `false` otherwise. */

* number, a bigint, or a string that can be converted to a number or bigint.
*
* NOTE: `NaN` is not considered a number.
* @param strict Only returns `true` when the value is of type `number`.
*/
export declare function isNumeric(value: unknown): boolean;
export declare function isNumeric(value: unknown, strict?: boolean): boolean;
/** Return `true` if a number is between the given range (inclusive). */

@@ -10,0 +13,0 @@ export declare function isBetween(value: number, [min, max]: [number, number]): boolean;

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