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

@aesthetic/utils

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aesthetic/utils - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

2

dts/arrayLoop.d.ts

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

export default function arrayLoop<T>(array: ArrayLike<T>, callback: (item: T, index: number) => void, reverse?: boolean): void;
export declare function arrayLoop<T>(array: ArrayLike<T> | undefined, callback: (item: T, index: number) => void, reverse?: boolean): void;
//# sourceMappingURL=arrayLoop.d.ts.map

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

export default function arrayReduce<T>(array: ArrayLike<T>, callback: (item: T, index: number) => string, initialValue?: string): string;
export declare function arrayReduce<T>(array: ArrayLike<T>, callback: (item: T, index: number) => string, initialValue?: string): string;
//# sourceMappingURL=arrayReduce.d.ts.map

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

export default function attempt<T>(callback: () => T): T | null;
export declare function attempt<T>(callback: () => T): T | null;
//# sourceMappingURL=attempt.d.ts.map

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

export default function createState<T>(defaultValue?: T): {
export declare function createState<T>(defaultValue?: T): {
get(): T | undefined;

@@ -3,0 +3,0 @@ reset(): void;

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

export default function deepClone<T extends object>(object: T): T;
export declare function deepClone<T extends object>(object: T): T;
//# sourceMappingURL=deepClone.d.ts.map
export declare function merge(base: object, next: object): object;
export default function deepMerge<T = object>(...objects: unknown[]): T;
export declare function deepMerge<T = object>(...objects: unknown[]): T;
//# sourceMappingURL=deepMerge.d.ts.map

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

export default function generateHash(value: string): string;
export declare function generateHash(value: string): string;
//# sourceMappingURL=generateHash.d.ts.map

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

export default function hyphenate(value: string): string;
export declare function hyphenate(value: string): string;
//# sourceMappingURL=hyphenate.d.ts.map

@@ -5,20 +5,20 @@ /**

*/
import arrayLoop from './arrayLoop';
import arrayReduce from './arrayReduce';
import attempt from './attempt';
import createState from './createState';
import deepClone from './deepClone';
import deepMerge from './deepMerge';
import generateHash from './generateHash';
import hyphenate from './hyphenate';
import isDOM from './isDOM';
import isObject from './isObject';
import joinQueries from './joinQueries';
import nonce from './nonce';
import objectCreate from './objectCreate';
import objectLoop from './objectLoop';
import objectReduce from './objectReduce';
import toArray from './toArray';
import { arrayLoop } from './arrayLoop';
import { arrayReduce } from './arrayReduce';
import { attempt } from './attempt';
import { createState } from './createState';
import { deepClone } from './deepClone';
import { deepMerge } from './deepMerge';
import { generateHash } from './generateHash';
import { hyphenate } from './hyphenate';
import { isDOM } from './isDOM';
import { isObject } from './isObject';
import { joinQueries } from './joinQueries';
import { nonce } from './nonce';
import { objectCreate } from './objectCreate';
import { objectLoop } from './objectLoop';
import { objectReduce } from './objectReduce';
import { toArray } from './toArray';
export * from './types';
export { arrayLoop, arrayReduce, attempt, createState, deepClone, deepMerge, generateHash, hyphenate, isDOM, isObject, joinQueries, nonce, objectCreate, objectLoop, objectReduce, toArray, };
//# sourceMappingURL=index.d.ts.map

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

export default function isDOM(): boolean;
export declare function isDOM(): boolean;
//# sourceMappingURL=isDOM.d.ts.map

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

export default function isObject<T = object>(value: unknown): value is T;
export declare function isObject<T = object>(value: unknown): value is T;
//# sourceMappingURL=isObject.d.ts.map

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

export default function joinQueries(prev: string | undefined, next: string): string;
export declare function joinQueries(prev: string | undefined, next: string): string;
//# sourceMappingURL=joinQueries.d.ts.map

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

export default function nonce(): string | undefined;
export declare function nonce(): string | undefined;
//# sourceMappingURL=nonce.d.ts.map

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

export default function objectCreate<K extends number | string, V = unknown>(keys: K[], callback: (key: K) => V): Record<K, V>;
export declare function objectCreate<K extends number | string, V = unknown>(keys: K[], callback: (key: K) => V): Record<K, V>;
//# sourceMappingURL=objectCreate.d.ts.map
import { StringKey } from './types';
export default function objectLoop<T extends object, K extends keyof T>(object: T, callback: (value: T[K], key: StringKey<K>) => void): void;
export declare function objectLoop<T extends object, K extends keyof T>(object: T | undefined, callback: (value: T[K], key: StringKey<K>) => void): void;
//# sourceMappingURL=objectLoop.d.ts.map
import { StringKey } from './types';
export default function objectReduce<T extends object, K extends keyof T>(object: T, callback: (value: T[K], key: StringKey<K>) => string, initialValue?: string): string;
export declare function objectReduce<T extends object, K extends keyof T>(object: T, callback: (value: T[K], key: StringKey<K>) => string, initialValue?: string): string;
//# sourceMappingURL=objectReduce.d.ts.map

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

export default function toArray<T>(value: T | T[]): T[];
export declare function toArray<T>(value: T | T[]): T[];
//# sourceMappingURL=toArray.d.ts.map

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

// Generated with Packemon: https://packemon.dev
// Bundled with Packemon: https://packemon.dev
// Platform: browser, Support: stable, Format: esm

@@ -6,12 +6,12 @@ import hash from 'string-hash'; // https://jsperf.com/compare-while-loop-vs-for-loop/30

function arrayLoop(array, callback, reverse) {
if (reverse === void 0) {
reverse = false;
function arrayLoop(array, callback, reverse = false) {
if (array === undefined) {
return;
}
var length = array.length;
var i = 0;
const length = array.length;
let i = 0;
while (i < length) {
var x = reverse ? length - i - 1 : i;
const x = reverse ? length - i - 1 : i;
callback(array[x], x);

@@ -22,11 +22,7 @@ i += 1;

function arrayReduce(array, callback, initialValue) {
if (initialValue === void 0) {
initialValue = '';
}
function arrayReduce(array, callback, initialValue = '') {
const length = array.length;
let value = initialValue;
let i = 0;
var length = array.length;
var value = initialValue;
var i = 0;
while (i < length) {

@@ -43,3 +39,3 @@ value += callback(array[i], i);

return callback();
} catch (_unused) {
} catch {
return null;

@@ -50,13 +46,16 @@ }

function createState(defaultValue) {
var value = defaultValue;
let value = defaultValue;
return {
get: function get() {
get() {
return value;
},
reset: function reset() {
reset() {
value = undefined;
},
set: function set(nextValue) {
set(nextValue) {
value = nextValue;
}
};

@@ -70,8 +69,12 @@ }

function objectLoop(object, callback) {
var keys = Object.keys(object);
var l = keys.length;
var i = 0;
if (object === undefined) {
return;
}
const keys = Object.keys(object);
const l = keys.length;
let i = 0;
while (i < l) {
var key = keys[i];
const key = keys[i];
callback(object[key], key);

@@ -81,7 +84,7 @@ i += 1;

}
/* eslint-disable no-param-reassign, no-use-before-define, @typescript-eslint/no-use-before-define */
/* eslint-disable no-param-reassign, @typescript-eslint/no-use-before-define */
function merge(base, next) {
objectLoop(next, function (right, key) {
objectLoop(next, (right, key) => {
if (isObject(right)) {

@@ -96,7 +99,3 @@ base[key] = deepMerge(base[key], right);

function deepMerge() {
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
objects[_key] = arguments[_key];
}
function deepMerge(...objects) {
if (objects.length === 1) {

@@ -106,4 +105,4 @@ return objects[0];

var result = {};
arrayLoop(objects, function (object) {
const result = {};
arrayLoop(objects, object => {
if (isObject(object)) {

@@ -120,3 +119,3 @@ merge(result, object);

var cache$2 = {};
const cache$2 = {};

@@ -132,13 +131,11 @@ function generateHash(value) {

var CAMEL_CASE_PATTERN = /[A-Z]/g;
var cache$1 = {};
const CAMEL_CASE_PATTERN = /[A-Z]/gu;
const cache$1 = {};
function toLower(match) {
return "-" + match.toLowerCase();
return `-${match.toLowerCase()}`;
}
function isPrefixed(value) {
return (// eslint-disable-next-line no-magic-numbers
value.slice(0, 2) === 'ms' || value.slice(0, 3) === 'moz' || value.slice(0, 6) === 'webkit'
);
return value.startsWith('ms') || value.startsWith('moz') || value.startsWith('webkit');
}

@@ -148,6 +145,6 @@

if (!cache$1[value]) {
var result = value.replace(CAMEL_CASE_PATTERN, toLower);
let result = value.replace(CAMEL_CASE_PATTERN, toLower);
if (isPrefixed(result)) {
result = "-" + result;
result = `-${result}`;
}

@@ -161,3 +158,3 @@

var cache = null;
let cache = null;

@@ -182,3 +179,3 @@ function isDOM() {

return prev + " and " + next;
return `${prev} and ${next}`;
}

@@ -196,3 +193,3 @@

}
/* eslint-disable no-underscore-dangle */
/* eslint-disable camelcase, no-underscore-dangle */

@@ -205,4 +202,4 @@

function objectCreate(keys, callback) {
var object = {};
arrayLoop(keys, function (key) {
const object = {};
arrayLoop(keys, key => {
object[key] = callback(key);

@@ -213,14 +210,8 @@ });

function objectReduce(object, callback, initialValue) {
if (initialValue === void 0) {
initialValue = '';
}
return arrayReduce(Object.keys(object), function (key) {
return callback(object[key], key);
}, initialValue);
function objectReduce(object, callback, initialValue = '') {
return arrayReduce(Object.keys(object), key => callback(object[key], key), initialValue);
}
function toArray(value) {
if (!value) {
if (value === undefined) {
return [];

@@ -231,9 +222,4 @@ }

}
/**
* @copyright 2020, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
export { arrayLoop, arrayReduce, attempt, createState, deepClone, deepMerge, generateHash, hyphenate, isDOM, isObject, joinQueries, nonce, objectCreate, objectLoop, objectReduce, toArray };
//# sourceMappingURL=index.js.map
{
"name": "@aesthetic/utils",
"version": "0.7.0",
"version": "0.8.0",
"description": "Utility functions for Aesthetic.",

@@ -17,3 +17,4 @@ "keywords": [

"license": "MIT",
"main": "./lib/index.js",
"type": "module",
"main": "./esm/index.js",
"module": "./esm/index.js",

@@ -41,3 +42,3 @@ "types": "./dts/index.d.ts",

},
"gitHead": "dd20a1ddf36757a97401cff73f7f994b592bfa93"
"gitHead": "6fd0ed93f8f15446ba2f9f0be8054a091997cbec"
}
// https://jsperf.com/compare-while-loop-vs-for-loop/30
// https://jsperf.com/for-in-object-key/3
export default function arrayLoop<T>(
array: ArrayLike<T>,
callback: (item: T, index: number) => void,
reverse: boolean = false,
export function arrayLoop<T>(
array: ArrayLike<T> | undefined,
callback: (item: T, index: number) => void,
reverse: boolean = false,
) {
const { length } = array;
let i = 0;
if (array === undefined) {
return;
}
while (i < length) {
const x = reverse ? length - i - 1 : i;
const { length } = array;
let i = 0;
callback(array[x], x);
i += 1;
}
while (i < length) {
const x = reverse ? length - i - 1 : i;
callback(array[x], x);
i += 1;
}
}

@@ -1,16 +0,16 @@

export default function arrayReduce<T>(
array: ArrayLike<T>,
callback: (item: T, index: number) => string,
initialValue: string = '',
export function arrayReduce<T>(
array: ArrayLike<T>,
callback: (item: T, index: number) => string,
initialValue: string = '',
): string {
const { length } = array;
let value = initialValue;
let i = 0;
const { length } = array;
let value = initialValue;
let i = 0;
while (i < length) {
value += callback(array[i], i);
i += 1;
}
while (i < length) {
value += callback(array[i], i);
i += 1;
}
return value;
return value;
}

@@ -1,7 +0,7 @@

export default function attempt<T>(callback: () => T): T | null {
try {
return callback();
} catch {
return null;
}
export function attempt<T>(callback: () => T): T | null {
try {
return callback();
} catch {
return null;
}
}

@@ -1,15 +0,15 @@

export default function createState<T>(defaultValue?: T) {
let value: T | undefined = defaultValue;
export function createState<T>(defaultValue?: T) {
let value: T | undefined = defaultValue;
return {
get() {
return value;
},
reset() {
value = undefined;
},
set(nextValue: T) {
value = nextValue;
},
};
return {
get() {
return value;
},
reset() {
value = undefined;
},
set(nextValue: T) {
value = nextValue;
},
};
}
import { merge } from './deepMerge';
export default function deepClone<T extends object>(object: T): T {
return merge({}, object) as T;
export function deepClone<T extends object>(object: T): T {
return merge({}, object) as T;
}

@@ -1,33 +0,33 @@

/* eslint-disable no-param-reassign, no-use-before-define, @typescript-eslint/no-use-before-define */
/* eslint-disable no-param-reassign, @typescript-eslint/no-use-before-define */
import arrayLoop from './arrayLoop';
import isObject from './isObject';
import objectLoop from './objectLoop';
import { arrayLoop } from './arrayLoop';
import { isObject } from './isObject';
import { objectLoop } from './objectLoop';
export function merge(base: object, next: object): object {
objectLoop(next, (right, key) => {
if (isObject(right)) {
base[key] = deepMerge(base[key], right);
} else {
base[key] = right;
}
});
objectLoop(next, (right, key) => {
if (isObject(right)) {
base[key] = deepMerge(base[key], right);
} else {
base[key] = right;
}
});
return base;
return base;
}
export default function deepMerge<T = object>(...objects: unknown[]): T {
if (objects.length === 1) {
return objects[0] as T;
}
export function deepMerge<T = object>(...objects: unknown[]): T {
if (objects.length === 1) {
return objects[0] as T;
}
const result: object = {};
const result: object = {};
arrayLoop(objects, (object) => {
if (isObject(object)) {
merge(result, object);
}
});
arrayLoop(objects, (object) => {
if (isObject(object)) {
merge(result, object);
}
});
return (result as unknown) as T;
return result as unknown as T;
}

@@ -5,9 +5,9 @@ import hash from 'string-hash';

export default function generateHash(value: string): string {
if (!cache[value]) {
// eslint-disable-next-line no-magic-numbers
cache[value] = hash(value).toString(36);
}
export function generateHash(value: string): string {
if (!cache[value]) {
// eslint-disable-next-line no-magic-numbers
cache[value] = hash(value).toString(36);
}
return cache[value];
return cache[value];
}

@@ -5,24 +5,21 @@ const CAMEL_CASE_PATTERN = /[A-Z]/gu;

function toLower(match: string): string {
return `-${match.toLowerCase()}`;
return `-${match.toLowerCase()}`;
}
function isPrefixed(value: string): boolean {
return (
// eslint-disable-next-line no-magic-numbers
value.slice(0, 2) === 'ms' || value.slice(0, 3) === 'moz' || value.slice(0, 6) === 'webkit'
);
return value.startsWith('ms') || value.startsWith('moz') || value.startsWith('webkit');
}
export default function hyphenate(value: string): string {
if (!cache[value]) {
let result = value.replace(CAMEL_CASE_PATTERN, toLower);
export function hyphenate(value: string): string {
if (!cache[value]) {
let result = value.replace(CAMEL_CASE_PATTERN, toLower);
if (isPrefixed(result)) {
result = `-${result}`;
}
if (isPrefixed(result)) {
result = `-${result}`;
}
cache[value] = result;
}
cache[value] = result;
}
return cache[value];
return cache[value];
}

@@ -6,18 +6,18 @@ /**

import arrayLoop from './arrayLoop';
import arrayReduce from './arrayReduce';
import attempt from './attempt';
import createState from './createState';
import deepClone from './deepClone';
import deepMerge from './deepMerge';
import generateHash from './generateHash';
import hyphenate from './hyphenate';
import isDOM from './isDOM';
import isObject from './isObject';
import joinQueries from './joinQueries';
import nonce from './nonce';
import objectCreate from './objectCreate';
import objectLoop from './objectLoop';
import objectReduce from './objectReduce';
import toArray from './toArray';
import { arrayLoop } from './arrayLoop';
import { arrayReduce } from './arrayReduce';
import { attempt } from './attempt';
import { createState } from './createState';
import { deepClone } from './deepClone';
import { deepMerge } from './deepMerge';
import { generateHash } from './generateHash';
import { hyphenate } from './hyphenate';
import { isDOM } from './isDOM';
import { isObject } from './isObject';
import { joinQueries } from './joinQueries';
import { nonce } from './nonce';
import { objectCreate } from './objectCreate';
import { objectLoop } from './objectLoop';
import { objectReduce } from './objectReduce';
import { toArray } from './toArray';

@@ -27,18 +27,18 @@ export * from './types';

export {
arrayLoop,
arrayReduce,
attempt,
createState,
deepClone,
deepMerge,
generateHash,
hyphenate,
isDOM,
isObject,
joinQueries,
nonce,
objectCreate,
objectLoop,
objectReduce,
toArray,
arrayLoop,
arrayReduce,
attempt,
createState,
deepClone,
deepMerge,
generateHash,
hyphenate,
isDOM,
isObject,
joinQueries,
nonce,
objectCreate,
objectLoop,
objectReduce,
toArray,
};
let cache: boolean | null = null;
export default function isDOM(): boolean {
if (process.env.AESTHETIC_SSR) {
return false;
}
export function isDOM(): boolean {
if (process.env.AESTHETIC_SSR) {
return false;
}
if (cache === null) {
cache = typeof window !== 'undefined' && typeof document !== 'undefined';
}
if (cache === null) {
cache = typeof window !== 'undefined' && typeof document !== 'undefined';
}
return cache;
return cache;
}

@@ -1,3 +0,3 @@

export default function isObject<T = object>(value: unknown): value is T {
return value !== null && !Array.isArray(value) && typeof value === 'object';
export function isObject<T = object>(value: unknown): value is T {
return value !== null && !Array.isArray(value) && typeof value === 'object';
}

@@ -1,19 +0,19 @@

export default function joinQueries(prev: string | undefined, next: string): string {
if (prev && next) {
if (prev.includes(next)) {
return prev;
}
export function joinQueries(prev: string | undefined, next: string): string {
if (prev && next) {
if (prev.includes(next)) {
return prev;
}
return `${prev} and ${next}`;
}
return `${prev} and ${next}`;
}
if (next) {
return next;
}
if (next) {
return next;
}
if (prev) {
return prev;
}
if (prev) {
return prev;
}
return '';
return '';
}

@@ -1,7 +0,7 @@

/* eslint-disable no-underscore-dangle */
/* eslint-disable camelcase, no-underscore-dangle */
declare const __webpack_nonce__: string;
export default function nonce(): string | undefined {
return typeof __webpack_nonce__ === 'undefined' ? undefined : __webpack_nonce__;
export function nonce(): string | undefined {
return typeof __webpack_nonce__ === 'undefined' ? undefined : __webpack_nonce__;
}

@@ -1,14 +0,14 @@

import arrayLoop from './arrayLoop';
import { arrayLoop } from './arrayLoop';
export default function objectCreate<K extends number | string, V = unknown>(
keys: K[],
callback: (key: K) => V,
export function objectCreate<K extends number | string, V = unknown>(
keys: K[],
callback: (key: K) => V,
): Record<K, V> {
const object: Partial<Record<K, V>> = {};
const object: Partial<Record<K, V>> = {};
arrayLoop(keys, (key) => {
object[key] = callback(key);
});
arrayLoop(keys, (key) => {
object[key] = callback(key);
});
return object as Record<K, V>;
return object as Record<K, V>;
}
import { StringKey } from './types';
export default function objectLoop<T extends object, K extends keyof T>(
object: T,
callback: (value: T[K], key: StringKey<K>) => void,
export function objectLoop<T extends object, K extends keyof T>(
object: T | undefined,
callback: (value: T[K], key: StringKey<K>) => void,
) {
const keys = Object.keys(object);
const l = keys.length;
let i = 0;
if (object === undefined) {
return;
}
while (i < l) {
const key = keys[i] as K;
const keys = Object.keys(object);
const l = keys.length;
let i = 0;
callback(object[key], key as StringKey<K>);
i += 1;
}
while (i < l) {
const key = keys[i] as K;
callback(object[key], key as StringKey<K>);
i += 1;
}
}

@@ -1,14 +0,14 @@

import arrayReduce from './arrayReduce';
import { arrayReduce } from './arrayReduce';
import { StringKey } from './types';
export default function objectReduce<T extends object, K extends keyof T>(
object: T,
callback: (value: T[K], key: StringKey<K>) => string,
initialValue: string = '',
export function objectReduce<T extends object, K extends keyof T>(
object: T,
callback: (value: T[K], key: StringKey<K>) => string,
initialValue: string = '',
): string {
return arrayReduce(
Object.keys(object) as K[],
(key) => callback(object[key], key as StringKey<K>),
initialValue,
);
return arrayReduce(
Object.keys(object) as K[],
(key) => callback(object[key], key as StringKey<K>),
initialValue,
);
}

@@ -1,7 +0,7 @@

export default function toArray<T>(value: T | T[]): T[] {
if (!value) {
return [];
}
export function toArray<T>(value: T | T[]): T[] {
if (value === undefined) {
return [];
}
return Array.isArray(value) ? value : [value];
return Array.isArray(value) ? value : [value];
}

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