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

@steveush/utils

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@steveush/utils - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

lib/cjs/num/clamp.cjs

2

lib/es/index.js

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

export{default as combine}from"./obj/combine.js";export{default as getProperty}from"./obj/getProperty.js";export{default as hasKeys}from"./obj/hasKeys.js";export{default as merge}from"./obj/merge.js";export{default as pluck}from"./obj/pluck.js";export{default as setProperty}from"./obj/setProperty.js";export{default as someKeys}from"./obj/someKeys.js";export{default as bisect}from"./str/bisect.js";export{default as escapeHTML}from"./str/escapeHTML.js";export{default as format}from"./str/format.js";export{default as propertyPath}from"./str/propertyPath.js";export{default as toCamelCase}from"./str/toCamelCase.js";export{default as toKebabCase}from"./str/toKebabCase.js";export{default as toPartsLowerCase}from"./str/toPartsLowerCase.js";export{default as toPascalCase}from"./str/toPascalCase.js";export{default as toSnakeCase}from"./str/toSnakeCase.js";export{default as toString}from"./str/toString.js";export{default as unescapeHTML}from"./str/unescapeHTML.js";export{default as isArray}from"./type-checks/isArray.js";export{default as isBoolean}from"./type-checks/isBoolean.js";export{default as isFunction}from"./type-checks/isFunction.js";export{default as isNonNullable}from"./type-checks/isNonNullable.js";export{default as isNull}from"./type-checks/isNull.js";export{default as isNumber}from"./type-checks/isNumber.js";export{default as isObject}from"./type-checks/isObject.js";export{default as isPlainObject}from"./type-checks/isPlainObject.js";export{default as isRegExp}from"./type-checks/isRegExp.js";export{default as isString}from"./type-checks/isString.js";export{default as isSymbol}from"./type-checks/isSymbol.js";export{default as isUndefined}from"./type-checks/isUndefined.js";
export{default as clamp}from"./num/clamp.js";export{default as isNumberNotZero}from"./num/isNumberNotZero.js";export{default as isNumberWithin}from"./num/isNumberWithin.js";export{default as cleanObject}from"./obj/cleanObject.js";export{default as clone}from"./obj/clone.js";export{default as combine}from"./obj/combine.js";export{default as distinct}from"./obj/distinct.js";export{default as getProperty}from"./obj/getProperty.js";export{default as hasKeys}from"./obj/hasKeys.js";export{default as merge}from"./obj/merge.js";export{default as pluck}from"./obj/pluck.js";export{default as setProperty}from"./obj/setProperty.js";export{default as someKeys}from"./obj/someKeys.js";export{default as bisect}from"./str/bisect.js";export{default as capitalize}from"./str/capitalize.js";export{default as escapeHTML}from"./str/escapeHTML.js";export{default as format}from"./str/format.js";export{default as propertyPath}from"./str/propertyPath.js";export{default as strim}from"./str/strim.js";export{default as toCamelCase}from"./str/toCamelCase.js";export{default as toKebabCase}from"./str/toKebabCase.js";export{default as toPartsLowerCase}from"./str/toPartsLowerCase.js";export{default as toPascalCase}from"./str/toPascalCase.js";export{default as toSnakeCase}from"./str/toSnakeCase.js";export{default as toString}from"./str/toString.js";export{default as unescapeHTML}from"./str/unescapeHTML.js";export{default as isArray}from"./type-checks/isArray.js";export{default as isBoolean}from"./type-checks/isBoolean.js";export{default as isFunction}from"./type-checks/isFunction.js";export{default as isNonNullable}from"./type-checks/isNonNullable.js";export{default as isNull}from"./type-checks/isNull.js";export{default as isNumber}from"./type-checks/isNumber.js";export{default as isObject}from"./type-checks/isObject.js";export{default as isPlainObject}from"./type-checks/isPlainObject.js";export{default as isRegExp}from"./type-checks/isRegExp.js";export{default as isString}from"./type-checks/isString.js";export{default as isSymbol}from"./type-checks/isSymbol.js";export{default as isUndefined}from"./type-checks/isUndefined.js";
//# sourceMappingURL=index.js.map

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

import e from"../type-checks/isPlainObject.js";import r from"../type-checks/isUndefined.js";import t from"../type-checks/isArray.js";import i from"../type-checks/isFunction.js";import s from"../type-checks/isString.js";const c=(c,n)=>{if(e(c)){const o=Object.keys(c);if(r(n))return o.length>0;if(s(n))return o.includes(n);if(t(n))return n.every((e=>o.includes(e)));if(e(n))return Object.entries(n).every((e=>{let[r,t]=e;return!(!o.includes(r)||!i(t))&&t(c[r])}))}return!1};export{c as default};
import e from"../type-checks/isPlainObject.js";import r from"../type-checks/isUndefined.js";import t from"../type-checks/isArray.js";import s from"../type-checks/isFunction.js";import i from"../type-checks/isString.js";import c from"../type-checks/isObject.js";const n=(n,o)=>{if(c(n)){const c=Object.keys(n);if(r(o))return c.length>0;if(i(o))return c.includes(o);if(t(o))return o.every((e=>c.includes(e)));if(e(o))return Object.entries(o).every((e=>{let[r,t]=e;return!(!c.includes(r)||!s(t))&&t(n[r])}))}return!1};export{n as default};
//# sourceMappingURL=hasKeys.js.map

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

import r from"../type-checks/isArray.js";import t from"../type-checks/isPlainObject.js";const e=function(o){t(o)||(o={});for(var s=arguments.length,c=new Array(s>1?s-1:0),f=1;f<s;f++)c[f-1]=arguments[f];for(const s of c.filter(t))for(const[c,f]of Object.entries(s))t(f)?o[c]=e(o[c],f):r(f)?o[c]=f.slice():o[c]=f;return o};export{e as default};
import r from"../type-checks/isArray.js";import t from"../type-checks/isPlainObject.js";const e=function(o){t(o)||(o={});for(var s=arguments.length,c=new Array(s>1?s-1:0),f=1;f<s;f++)c[f-1]=arguments[f];for(const s of c.filter((r=>t(r))))for(const[c,f]of Object.entries(s))t(f)?o[c]=e(o[c],f):r(f)?o[c]=f.slice():o[c]=f;return o};export{e as default};
//# sourceMappingURL=merge.js.map

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

import t from"../type-checks/isPlainObject.js";import e from"../type-checks/isFunction.js";import r from"../type-checks/isArray.js";import i from"../type-checks/isString.js";const s=(s,n)=>{if(t(s)){let t=null;if(i(n)&&(t=t=>{let[e]=t;return e===n}),r(n)&&(t=t=>{let[e]=t;return n.includes(e)}),e(n)&&(t=t=>{let[e,r]=t;return n(r,e,s)}),null!==t)return Object.fromEntries(Object.entries(s).filter(t))}return{}};export{s as default};
import t from"../type-checks/isFunction.js";import e from"../type-checks/isArray.js";import r from"../type-checks/isString.js";import s from"../type-checks/isObject.js";const i=(i,c)=>{if(s(i)){let s=null;if(r(c)&&(s=t=>{let[e]=t;return e===c}),e(c)&&(s=t=>{let[e]=t;return c.includes(e)}),t(c)&&(s=t=>{let[e,r]=t;return c(r,e,i)}),null!==s)return Object.fromEntries(Object.entries(i).filter(s))}return{}};export{i as default};
//# sourceMappingURL=pluck.js.map

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

import e from"../type-checks/isPlainObject.js";import t from"../type-checks/isUndefined.js";import r from"../type-checks/isArray.js";import s from"../type-checks/isFunction.js";import i from"../type-checks/isString.js";const c=(c,n)=>{if(e(c)){const o=Object.keys(c);if(t(n))return o.length>0;if(i(n))return o.includes(n);if(r(n))return n.some((e=>o.includes(e)));if(e(n))return Object.entries(n).some((e=>{let[t,r]=e;return!(!o.includes(t)||!s(r))&&r(c[t])}))}return!1};export{c as default};
import e from"../type-checks/isPlainObject.js";import t from"../type-checks/isUndefined.js";import r from"../type-checks/isArray.js";import s from"../type-checks/isFunction.js";import i from"../type-checks/isString.js";import c from"../type-checks/isObject.js";const n=(n,o)=>{if(c(n)){const c=Object.keys(n);if(t(o))return c.length>0;if(i(o))return c.includes(o);if(r(o))return o.some((e=>c.includes(e)));if(e(o))return Object.entries(o).some((e=>{let[t,r]=e;return!(!c.includes(t)||!s(r))&&r(n[t])}))}return!1};export{n as default};
//# sourceMappingURL=someKeys.js.map
{
"name": "@steveush/utils",
"version": "0.0.1",
"version": "0.0.2",
"description": "Utility methods and classes.",

@@ -33,2 +33,3 @@ "type": "module",

"test@type-checks": "npm run test -- --group=type-checks",
"test@num": "npm run test -- --group=num",
"test@obj": "npm run test -- --group=obj",

@@ -35,0 +36,0 @@ "test@str": "npm run test -- --group=str"

@@ -16,2 +16,3 @@ # @steveush/utils

```
## Usage

@@ -47,7 +48,150 @@

## Number Helpers
<details>
<summary><code>clamp( value: number, min?: number, max?: number ): number</code></summary>
Clamp a number value within a given range.
_**Params**_
* _**value:**_ `any`
The number to clamp. If the value supplied is not a number, the `min` value is returned.
* _**min:**_ `number` _optional_
The minimum allowed value for the number. If not supplied `Number.MIN_SAFE_INTEGER` is used.
* _**max:**_ `number` _optional_
The maximum allowed value for the number. If not supplied `Number.MAX_SAFE_INTEGER` is used.
_**Returns**_
* `number`
The number clamped between the `min` and `max` values. If the number was smaller than the `min` or larger than the `max`, their respective values are instead returned.
_**Example**_
```javascript
clamp( -1, 0, 2 ); // => 0
clamp( 0, 0, 2 ); // => 0
clamp( 1, 0, 2 ); // => 1
clamp( 2, 0, 2 ); // => 2
clamp( 3, 0, 2 ); // => 2
```
</details>
<details>
<summary><code>isNumberNotZero( value: string | number ): boolean</code></summary>
Check if a value is a number and not zero.
_**Params**_
* _**value:**_ `any`
The value to check. If a string is supplied it is first parsed to a number using the `parseFloat` method.
_**Returns**_
* `boolean`
`true` if the value is a number and not zero, otherwise `false`.
_**Example**_
```javascript
isNumberNotZero( 0 ); // => false
isNumberNotZero( 1 ); // => true
isNumberNotZero( "0px" ); // => false
isNumberNotZero( "1px" ); // => true
isNumberNotZero( "0.0em" ); // => false
isNumberNotZero( "0.1em" ); // => true
```
</details>
<details>
<summary><code>isNumberWithin( value: number, min: number, max: number ): boolean</code></summary>
Check if a value is a number within the inclusive range of min to max.
_**Params**_
* _**value:**_ `any`
The value to check.
* _**min:**_ `number`
The inclusive minimum value for the range.
* _**max:**_ `number`
The inclusive maximum value for the range.
_**Returns**_
* `boolean`
`true` if the value is a number within the specified range, otherwise `false`.
_**Example**_
```javascript
isNumberWithin( -1, 0, 2 ); // => false
isNumberWithin( 0, 0, 2 ); // => true
isNumberWithin( 1, 0, 2 ); // => true
isNumberWithin( 2, 0, 2 ); // => true
isNumberWithin( 3, 0, 2 ); // => false
```
</details>
## Object Helpers
<details>
<summary><code>cleanObject( value: object | any ): object | undefined</code></summary>
Clean an object by removing any keys explicitly set to `undefined`.
If after cleaning the object is empty, `undefined` itself is returned.
_**Params**_
* _**value:**_ `object | any`
The object to clean. If a non-object value is supplied, `undefined` will be returned.
_**Returns**_
* `object | undefined`
An object containing all keys with defined values, otherwise `undefined`.
_**Example**_
```javascript
cleanObject( {} ); // => undefined
cleanObject( { empty: undefined } ); // => undefined
cleanObject( { empty: undefined, notEmpty: true } ); // => { notEmpty: true }
```
</details>
<details>
<summary><code>clone( target: any ): any</code></summary>
Creates a clone of the supplied target.
**Note**: This method will clone arrays and plain objects, all other types are set by reference.
_**Params**_
* _**target:**_ `any`
The target value to clone.
_**Returns**_
* `any`
A clone of the supplied target.
</details>
<details>
<summary><code>combine( arr1: any[], arr2: any[], comparator?: ( ( a: any, b: any ) => boolean ) ): any[]</code></summary>
Combine two arrays and return a new array containing no duplicate elements.

@@ -64,3 +208,4 @@

* _**comparator:**_ `( a: any, b: any ) => boolean` _optional_
The function used to determine element equality when removing duplicates. Defaults to a strict equality check (`a === b`).
The function used to determine element equality when removing duplicates. Defaults to a strict equality
check (`a === b`).

@@ -100,4 +245,27 @@ _**Returns**_

<details>
<summary><code>distinct( array: any[] ): any[]</code></summary>
Return the distinct elements of an array.
_**Params**_
* _**array:**_ `any[]`
The array to pluck elements from.
_**Returns**_
* `any[]`
A new array containing the distinct elements.
_**Example**_
```javascript
distinct( [ 1, 2, 2, 3 ] ); // => [ 1, 2, 3 ]
```
</details>
<details>
<summary><code>getProperty( target: object, path: string ): any</code></summary>
Get a property value from an object using a path string (`"child.prop"`).

@@ -160,3 +328,3 @@

<summary><code>hasKeys( target: object, keys?: string | string[] | Record&lt;string, ( ( value: any ) => boolean )&gt; ): boolean</code></summary>
Check if an object has keys.

@@ -170,3 +338,4 @@

* _**keys:**_ `string | string[] | Record<string, ( ( value: any ) => boolean )>` _optional_
A string key name, string array of key names, or an object containing key names to type check methods. If not supplied and the _target_ contains any keys, `true` is returned.
A string key name, string array of key names, or an object containing key names to type check methods. If not supplied
and the _target_ contains any keys, `true` is returned.

@@ -199,6 +368,7 @@ _**Returns**_

<summary><code>merge( target: object, ...source: object[] ): object</code></summary>
Recursively merge the properties of multiple source objects into the target.
**Note**: This method does not merge arrays. Any array properties of the target are replaced with shallow copies from the sources.
**Note**: This method does not merge arrays. Any array properties of the target are replaced with shallow copies from
the sources.

@@ -308,10 +478,10 @@ _**Params**_

const obj = {
name: "root",
child: {
name: "child"
},
children: [
{ name: "first" },
{ name: "second" }
]
name: "root",
child: {
name: "child"
},
children: [
{ name: "first" },
{ name: "second" }
]
};

@@ -335,2 +505,3 @@ ```

```
```javascript

@@ -349,2 +520,3 @@ setProperty( obj, "child.name", "update_child" );

```
```javascript

@@ -364,3 +536,3 @@ setProperty( obj, "children[0].name", "update_children_first" );

**_Note_**: By default, if the _path_ does not exist on the _target_, no property is set.
**_Note_**: By default, if the _path_ does not exist on the _target_, no property is set.

@@ -372,3 +544,4 @@ ```javascript

If you want to change this behavior and allow new properties to be created, then you must pass `true` for the _create_ parameter.
If you want to change this behavior and allow new properties to be created, then you must pass `true` for the _create_
parameter.

@@ -393,3 +566,4 @@ ```javascript

* _**keys:**_ `string | string[] | Record<string, ( ( value: any ) => boolean )>` _optional_
A string key name, string array of key names, or an object containing key names to type check methods. If not supplied and the _target_ contains any keys, `true` is returned.
A string key name, string array of key names, or an object containing key names to type check methods. If not supplied
and the _target_ contains any keys, `true` is returned.

@@ -405,4 +579,4 @@ _**Returns**_

const obj = {
name: "string",
checked: true
name: "string",
checked: true
};

@@ -424,3 +598,3 @@

<summary><code>bisect( str: string, searchString: string, trim?: boolean ): [ string, string ]</code></summary>
Split a string on the first occurrence of the specified search string.

@@ -444,4 +618,6 @@

The first element is the string value from before the `searchString`, or the original value if the `searchString` was not found.
The second element is the string value from after the `searchString`, or an empty string if the `searchString` was not found.
The first element is the string value from before the `searchString`, or the original value if the `searchString` was
not found.
The second element is the string value from after the `searchString`, or an empty string if the `searchString` was not
found.

@@ -459,2 +635,27 @@ _**Example**_

<details>
<summary><code>capitalize( str: string ): string</code></summary>
Capitalize the first character of a string.
_**Params**_
* _**str:**_ `string`
The string to capitalize.
_**Returns**_
* `string`
The capitalized string, otherwise an empty string if the value was not string.
_**Example**_
```javascript
capitalize(); // => ""
capitalize( "test" ); // => "Test"
capitalize( "TEST" ); // => "Test"
```
</details>
<details>
<summary><code>escapeHTML( str: string ): string</code></summary>

@@ -484,3 +685,3 @@

<summary><code>propertyPath( path: string ): string</code></summary>
Convert an array notated property path to a dot notated one.

@@ -515,4 +716,30 @@

<details>
<summary><code>strim( str: string, separator: string | RegExp ): string[]</code></summary>
Split a string into an ordered list of trimmed, non-empty, substrings.
_**Params**_
* _**str:**_ `string`
The string to split.
* _**separator:**_ `string | RegExp`
The pattern describing where each split should occur.
_**Returns**_
* `string[]`
An array containing the trimmed, non-empty, substrings, split at each point where the separator occurs in the given string.
_**Example**_
```javascript
strim( "key1: value1; key2: value2;", ";" ); // => [ "key1: value1", "key2: value2" ]
```
</details>
<details>
<summary><code>toCamelCase( str: string, uppercase?: string[], force?: boolean ): string</code></summary>
Convert a string to camelCase.

@@ -571,3 +798,3 @@

<summary><code>toKebabCase( str: string ): string</code></summary>
Convert a string to kebab-case.

@@ -599,3 +826,3 @@

<summary><code>toPascalCase( str: string, uppercase?: string[] ): string</code></summary>
Convert a string to PascalCase.

@@ -639,3 +866,3 @@

<summary><code>toSnakeCase( str: string ): string</code></summary>
Convert a string to snake_case.

@@ -667,3 +894,3 @@

<summary><code>toPartsLowerCase( str: string ): string[]</code></summary>
Convert a string into an array of its component parts.

@@ -701,3 +928,3 @@

<summary><code>toString( value: any ): string</code></summary>
Convert a value to a string using the `Object.prototype.toString()` method.

@@ -752,3 +979,3 @@

<summary><code>isArray( value: any, notEmpty?: boolean, predicate?: ( value: any, index: number, iter: any[] ) => boolean ): boolean</code></summary>
Check if a value is an array.

@@ -785,3 +1012,3 @@

<summary><code>isBoolean( value: any ): boolean</code></summary>
Check if a value is a boolean.

@@ -803,3 +1030,3 @@

<summary><code>isFunction( value: any ): boolean</code></summary>
Check if a value is a function.

@@ -820,3 +1047,5 @@

```javascript
function named(){}
function named() {
}
isFunction( named ); // => true

@@ -1058,10 +1287,10 @@

To get the project up and running for development should just require running `npm install` and then `npm run develop`.
To get the project up and running for development should just require running `npm install` and then `npm run develop`.
For more information on the configuration check out the [DEV.md](DEV.md) readme.
## Changelog
| Version | Description |
|-----------|------------------------------|
| 0.0.1 | Initial release |
| Version | Description |
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.0.1 | Initial release |
| 0.0.2 | Relaxed the value checks for `hasKeys`, `someKeys` and `pluck` methods to allow any object instead of just plain objects. Added the `cleanObject`, `clone`, `distinct`, `clamp`, `isNumberNotZero`, `isNumberWithin`, `capitalize` and `strim` methods. |
export * from "./types";
export * from "./num";
export * from "./obj";
export * from "./str";
export * from "./type-checks";

@@ -5,3 +5,3 @@ /**

* @param {object} target - The object to check.
* @param {string|string[]|Record<string,((value: any) => boolean)>} [keys] Optional. A string key name, string array of
* @param {string|string[]|{[key: string]: ((value: any) => boolean)}} [keys] Optional. A string key name, string array of
* key names, or an object containing key names to type check methods. If not supplied and the target contains any keys, `true` is returned.

@@ -12,2 +12,4 @@ * @returns {boolean} - `true` if the target has all the keys, otherwise `false`.

*/
export default function hasKeys( target: Record<string, any>, keys?: ( string | string[] | Record<string, ( ( value: any ) => boolean )> ) ): boolean;
export default function hasKeys( target: object, keys?: ( string | string[] | {
[ key: string ]: ( ( value: any ) => boolean )
} ) ): boolean;

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

export { default as cleanObject } from "./cleanObject";
export { default as clone } from "./clone";
export { default as combine } from "./combine";
export { default as distinct } from "./distinct";
export { default as getProperty } from "./getProperty";

@@ -3,0 +6,0 @@ export { default as hasKeys } from "./hasKeys";

@@ -10,2 +10,6 @@ /**

*/
export default function pluck( obj: Record<string, any>, keys: string | string[] | ( ( value: any, key: string, iter: object ) => boolean) ): Record<string, any>;
export default function pluck( obj: {
[ key: string ]: any
}, keys: string | string[] | ( ( value: any, key: string, iter: object ) => boolean ) ): {
[ key: string ]: any
};

@@ -5,3 +5,3 @@ /**

* @param {object} target - The object to check.
* @param {string|string[]|Record<string,((value: any) => boolean)>} [keys] Optional. A string key name, string array of
* @param {string|string[]|{[key: string]: ((value: any) => boolean)}} [keys] Optional. A string key name, string array of
* key names, or an object containing key names to type check methods. If not supplied and the target contains any keys, `true` is returned.

@@ -12,2 +12,4 @@ * @returns {boolean} - `true` if the target has any of the keys, otherwise `false`.

*/
export default function someKeys( target: Record<string, any>, keys?: ( string | string[] | Record<string, ( ( value: any ) => boolean )> ) ): boolean;
export default function someKeys( target: Record<string, any>, keys?: ( string | string[] | {
[ key: string ]: ( ( value: any ) => boolean )
} ) ): boolean;

@@ -15,3 +15,5 @@ /**

* This method does not perform a simultaneous replacement of placeholders.
*
* @category String Helpers
*/
export default function format( format: string, arg: any | Record<string, any>, ...argN?: any[] ): string;
export { default as bisect } from "./bisect";
export { default as capitalize } from "./capitalize";
export { default as escapeHTML } from "./escapeHTML";
export { default as format } from "./format";
export { default as propertyPath } from "./propertyPath";
export { default as strim } from "./strim";
export { default as toCamelCase } from "./toCamelCase";

@@ -6,0 +8,0 @@ export { default as toKebabCase } from "./toKebabCase";

@@ -114,2 +114,12 @@ //region General

//endregion
//endregion
//region NonUndefined<T> - Any value except undefined
type NonUndefined<T> = T extends undefined ? never : T;
//endregion
type CleanObject<T> = T extends {[key: string]: any} ? {
[ P in keyof T ]: NonUndefined<T<P>>
} : undefined;

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

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