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

@remirror/core-helpers

Package Overview
Dependencies
Maintainers
2
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remirror/core-helpers - npm Package Compare versions

Comparing version 0.0.0-pr2169.2 to 0.0.0-pr2223.1

dist/remirror-core-helpers.d.mts

677

dist/remirror-core-helpers.d.ts

@@ -1,86 +0,591 @@

export { invariant } from './_tsup-dts-rollup';
export { RemirrorError } from './_tsup-dts-rollup';
export { RemirrorErrorOptions } from './_tsup-dts-rollup';
export { Cast } from './_tsup-dts-rollup';
export { assertGet } from './_tsup-dts-rollup';
export { assert } from './_tsup-dts-rollup';
export { entries } from './_tsup-dts-rollup';
export { keys } from './_tsup-dts-rollup';
export { values } from './_tsup-dts-rollup';
export { includes } from './_tsup-dts-rollup';
export { object } from './_tsup-dts-rollup';
export { toString } from './_tsup-dts-rollup';
export { isDirectInstanceOf } from './_tsup-dts-rollup';
export { isNull } from './_tsup-dts-rollup';
export { isClass } from './_tsup-dts-rollup';
export { isBoolean } from './_tsup-dts-rollup';
export { isInteger } from './_tsup-dts-rollup';
export { isSafeInteger } from './_tsup-dts-rollup';
export { isPlainObject } from './_tsup-dts-rollup';
export { isPrimitive } from './_tsup-dts-rollup';
export { isJSONPrimitive } from './_tsup-dts-rollup';
export { isNullOrUndefined } from './_tsup-dts-rollup';
export { isObject } from './_tsup-dts-rollup';
export { isInstanceOf } from './_tsup-dts-rollup';
export { isNativePromise } from './_tsup-dts-rollup';
export { isPromise } from './_tsup-dts-rollup';
export { isMap } from './_tsup-dts-rollup';
export { isSet } from './_tsup-dts-rollup';
export { isEmptyObject } from './_tsup-dts-rollup';
export { isEmptyArray } from './_tsup-dts-rollup';
export { isNonEmptyArray } from './_tsup-dts-rollup';
export { capitalize } from './_tsup-dts-rollup';
export { format } from './_tsup-dts-rollup';
export { callIfDefined } from './_tsup-dts-rollup';
export { findMatches } from './_tsup-dts-rollup';
export { cleanupOS } from './_tsup-dts-rollup';
export { isAndroidOS } from './_tsup-dts-rollup';
export { randomFloat } from './_tsup-dts-rollup';
export { randomInt } from './_tsup-dts-rollup';
export { startCase } from './_tsup-dts-rollup';
export { uniqueId } from './_tsup-dts-rollup';
export { take } from './_tsup-dts-rollup';
export { omitUndefined } from './_tsup-dts-rollup';
export { clone } from './_tsup-dts-rollup';
export { shallowClone } from './_tsup-dts-rollup';
export { uniqueArray } from './_tsup-dts-rollup';
export { flattenArray } from './_tsup-dts-rollup';
export { noop } from './_tsup-dts-rollup';
export { deepMerge } from './_tsup-dts-rollup';
export { clamp } from './_tsup-dts-rollup';
export { last } from './_tsup-dts-rollup';
export { sort } from './_tsup-dts-rollup';
export { get } from './_tsup-dts-rollup';
export { set } from './_tsup-dts-rollup';
export { unset } from './_tsup-dts-rollup';
export { uniqueBy } from './_tsup-dts-rollup';
export { range } from './_tsup-dts-rollup';
export { within } from './_tsup-dts-rollup';
export { hasOwnProperty } from './_tsup-dts-rollup';
export { getLazyArray } from './_tsup-dts-rollup';
export { isUndefined } from './_tsup-dts-rollup';
export { isString } from './_tsup-dts-rollup';
export { isNumber } from './_tsup-dts-rollup';
export { isFunction } from './_tsup-dts-rollup';
export { isSymbol } from './_tsup-dts-rollup';
export { isRegExp } from './_tsup-dts-rollup';
export { isDate } from './_tsup-dts-rollup';
export { isError } from './_tsup-dts-rollup';
export { isArray } from './_tsup-dts-rollup';
export { isEqual } from './_tsup-dts-rollup';
export { camelCase } from './_tsup-dts-rollup';
export { capitalCase } from './_tsup-dts-rollup';
export { constantCase } from './_tsup-dts-rollup';
export { kebabCase } from './_tsup-dts-rollup';
export { pascalCase } from './_tsup-dts-rollup';
export { pathCase } from './_tsup-dts-rollup';
export { snakeCase } from './_tsup-dts-rollup';
export { spaceCase } from './_tsup-dts-rollup';
export { DebouncedFunction } from './_tsup-dts-rollup';
export { ThrottledFunction } from './_tsup-dts-rollup';
export { debounce } from './_tsup-dts-rollup';
export { throttle } from './_tsup-dts-rollup';
export { omit } from './_tsup-dts-rollup';
export { pick } from './_tsup-dts-rollup';
export { defaultImport } from './_tsup-dts-rollup';
export { freeze } from './_tsup-dts-rollup';
import { BaseError } from 'make-error';
import { ErrorConstant } from '@remirror/core-constants';
import { AnyConstructor, AnyFunction, UnknownShape, Primitive, JsonPrimitive, Shape, Nullable, ConditionalExcept } from '@remirror/types';
export { camelCase, capitalCase, constantCase, kebabCase, pascalCase, pathCase, snakeCase, spaceCase } from 'case-anything';
export { debounce as DebouncedFunction, throttle as ThrottledFunction, debounce, throttle } from 'throttle-debounce';
export { default as omit } from 'object.omit';
export { default as pick } from 'object.pick';
/**
* This marks the error as a remirror specific error, with enhanced stack
* tracing capabilities.
*
* @remarks
*
* Use this when creating your own extensions and notifying the user that
* something has gone wrong.
*/
declare class RemirrorError extends BaseError {
/**
* A shorthand way of creating an error message.
*/
static create(options?: RemirrorErrorOptions): RemirrorError;
/**
* The error code used to create this error message.
*/
errorCode: ErrorConstant;
/**
* The link to read more about the error online.
*/
url: string;
/**
* The constructor is intentionally kept private to prevent being extended from.
*/
private constructor();
}
/**
* Throw an error if the condition fails. Strip out error messages for
* production. Adapted from `tiny-invariant`.
*/
declare function invariant(condition: unknown, options: RemirrorErrorOptions): asserts condition;
/**
* The invariant options which only show up during development.
*/
interface RemirrorErrorOptions {
/**
* The code for the built in error.
*/
code?: ErrorConstant;
/**
* The message to add to the error.
*/
message?: string;
/**
* When true logging to the console is disabled.
*
* @defaultValue false
*/
disableLogging?: boolean;
}
type TupleRange<Size extends number> = Size extends Size ? number extends Size ? number[] : _NumberRangeTuple<[], Size> : never;
type _NumberRangeTuple<Tuple extends readonly unknown[], Length extends number> = Tuple['length'] extends Length ? Tuple : _NumberRangeTuple<[...Tuple, Tuple['length']], Length>;
/**
* Type cast an argument. If no type is provided it will default to any.
*
* @param arg - the arg to typecast
*/
declare function Cast<Type = any>(value: unknown): Type;
/**
* Get the key from a given value. Throw an error if the referenced property is
* `undefined`.
*/
declare function assertGet<Value extends object, Key extends keyof Value>(value: Value, key: Key, message?: string): Value[Key];
/**
* Assert the value is `truthy`. Good for defensive programming, especially
* after enabling `noUncheckedIndexedAccess` in the tsconfig `compilerOptions`.
*/
declare function assert(testValue: unknown, message?: string): asserts testValue;
/**
* A typesafe implementation of `Object.entries()`
*
* Taken from
* https://github.com/biggyspender/ts-entries/blob/master/src/ts-entries.ts
*/
declare function entries<Type extends object, Key extends Extract<keyof Type, string>, Value extends Type[Key], Entry extends [Key, Value]>(value: Type): Entry[];
/**
* A typesafe implementation of `Object.keys()`
*/
declare function keys<Type extends object, Key extends Extract<keyof Type, string>>(value: Type): Key[];
/**
* A typesafe implementation of `Object.values()`
*/
declare function values<Type extends object, Key extends Extract<keyof Type, string>, Value extends Type[Key]>(value: Type): Value[];
/**
* A more lenient typed version of `Array.prototype.includes` which allow less
* specific types to be checked.
*/
declare function includes<Type>(array: Type[] | readonly Type[], item: unknown, fromIndex?: number): item is Type;
/**
* Creates an object with the null prototype.
*
* @param value - the object to create
*/
declare function object<Type extends object>(value?: Type): Type;
/**
* Alias of toString for non-dom environments.
*
* This is a safe way of calling `toString` on objects created with
* `Object.create(null)`.
*/
declare function toString(value: unknown): string;
/**
* Check if an instance is the direct instance of the provided class.
*/
declare function isDirectInstanceOf<Type>(instance: unknown, Constructor: AnyConstructor<Type>): instance is Type;
/**
* Predicate check that value is undefined
*
* @param value - the value to check
*
*/
declare const isUndefined: (value: unknown) => value is undefined;
/**
* Predicate check that value is a string
*
* @param value - the value to check
*
*/
declare const isString: (value: unknown) => value is string;
/**
* Predicate check that value is a number.
*
* Also by default doesn't include NaN as a valid number.
*
* @param value - the value to check
*
*/
declare const isNumber: (value: unknown) => value is number;
/**
* Predicate check that value is a function
*
* @param value - the value to check
*
*/
declare const isFunction: (value: unknown) => value is AnyFunction;
/**
* Predicate check that value is null
*
* @param value - the value to check
*
*/
declare function isNull(value: unknown): value is null;
/**
* Predicate check that value is a class
*
* @deprecated Due to the current build process stripping out classes
*
* @param value - the value to check
*
*/
declare function isClass(value: unknown): value is AnyConstructor;
/**
* Predicate check that value is boolean
*
* @param value - the value to check
*
*/
declare function isBoolean(value: unknown): value is boolean;
/**
* Predicate check that value is a symbol
*
* @param value - the value to check
*
*/
declare const isSymbol: (value: unknown) => value is symbol;
/**
* Helper function for Number.isInteger check allowing non numbers to be tested
*
* @param value - the value to check
*
*/
declare function isInteger(value: unknown): value is number;
/**
* Helper function for Number.isSafeInteger allowing for unknown values to be
* tested
*
* @param value - the value to check
*
*/
declare function isSafeInteger(value: unknown): value is number;
/**
* Predicate check for whether passed in value is a plain object
*
* @param value - the value to check
*
*/
declare function isPlainObject<Type = unknown>(value: unknown): value is UnknownShape<Type>;
/**
* Predicate check for whether passed in value is a primitive value
*/
declare function isPrimitive(value: unknown): value is Primitive;
/**
* Predicate check for whether passed in value is a JSON primitive value
*/
declare function isJSONPrimitive(value: unknown): value is JsonPrimitive;
/**
* Utility predicate check that value is either null or undefined
*
* @param value - the value to check
*
*/
declare function isNullOrUndefined(value: unknown): value is null | undefined;
/**
* Predicate check that value is an object.
*
* @param value - the value to check
*
*/
declare function isObject<Type extends Shape>(value: unknown): value is Type;
/**
* A shorthand method for creating instance of checks.
*/
declare function isInstanceOf<Constructor extends AnyConstructor>(Constructor: Constructor): (value: unknown) => value is InstanceType<Constructor>;
/**
* Predicate check that value is a native promise
*
* @param value - the value to check
*
*/
declare function isNativePromise(value: unknown): value is Promise<unknown>;
/**
* Predicate check that value has the promise api implemented
*
* @param value - the value to check
*
*/
declare function isPromise(value: unknown): value is Promise<unknown>;
/**
* Predicate check that value is a RegExp
*
* @param value - the value to check
*
*/
declare const isRegExp: (value: unknown) => value is RegExp;
/**
* Predicate check that value is a date
*
* @param value - the value to check
*
*/
declare const isDate: (value: unknown) => value is Date;
/**
* Predicate check that value is an error
*
* @param value - the value to check
*
*/
declare const isError: (value: unknown) => value is Error;
/**
* Predicate check that value is a `Map`
*
* @param value - the value to check
*
*/
declare function isMap(value: unknown): value is Map<unknown, unknown>;
/**
* Predicate check that value is a `Set`
*
* @param value - the value to check
*
*/
declare function isSet(value: unknown): value is Set<unknown>;
/**
* Predicate check that value is an empty object
*
* @param value - the value to check
*
*/
declare function isEmptyObject(value: unknown): boolean;
/**
* Alias the isArray method.
*/
declare const isArray: (arg: any) => arg is any[];
/**
* Predicate check that value is an empty array
*
* @param value - the value to check
*
*/
declare function isEmptyArray(value: unknown): value is never[];
/**
* Predicate check that value is a non-empty.
*
* @param value - the value to check
*
*/
declare function isNonEmptyArray<Item>(value: Item[]): value is [Item, ...Item[]];
/**
* Capitalizes a string value.
*
* @param str - the string to capitalize.
*/
declare function capitalize(string: string): string;
/**
* Trim and conditionally capitalize string values.
*
* @param str - the string to format.
*
*/
declare function format(value: string): string;
/**
* Calls a function if defined and provides compile time type checking for the
* passed in parameters.
*
* @param fn - the function to call if it exists
* @param args - the rest of the parameters with types
*/
declare function callIfDefined<Method extends AnyFunction>(fn: Nullable<Method>, ...args: Parameters<Method>): void;
/**
* Finds all the regex matches for a string
*
* @param text - the text to check against
* @param regexp - the regex (which should include a 'g' flag)
*
*/
declare function findMatches(text: string, regexp: RegExp, runWhile?: (match: RegExpExecArray | null) => boolean): RegExpExecArray[];
/**
* A utility function to clean up the Operating System name.
*
* @param os - the OS name to clean up.
* @param pattern - a `RegExp` pattern matching the OS name.
* @param label - a label for the OS.
* @returns a cleaned up Operating System name
*/
declare function cleanupOS(os: string, pattern?: string, label?: string): string;
/**
* A utility function to check whether the current browser is running on the
* android platform.
*/
declare function isAndroidOS(): boolean;
/**
* Generate a random float between min and max. If only one parameter is
* provided minimum is set to 0.
*
* @param min - the minimum value
* @param max - the maximum value
*
*/
declare function randomFloat(min: number, max?: number): number;
/**
* Generate a random integer between min and max. If only one parameter is
* provided minimum is set to 0.
*
* @param min - the minimum value
* @param max - the maximum value
*
*/
declare function randomInt(min: number, max?: number): number;
/**
* Converts a string, including strings in camelCase or snake_case, into Start
* Case (a variant of Title case where all words start with a capital letter),
* it keeps original single quote and hyphen in the word.
*
* 'management_companies' to 'Management Companies' 'managementCompanies' to
* 'Management Companies' `hell's kitchen` to `Hell's Kitchen` `co-op` to
* `Co-op`
*
* @param str - the string to examine
*/
declare function startCase(string: string): string;
/**
* Generate a unique id
*
* @param prefix - a prefix for the generated id.
* @returns a unique string of specified length
*
*/
declare function uniqueId(prefix?: string): string;
/**
* Takes a number of elements from the provided array starting from the
* zero-index
*
* @param arr - the array to take from
* @param num - the number of items to take
*
*/
declare function take<Type>(array: Type[], number: number): Type[];
/**
* Remove the undefined values from an object.
*/
declare function omitUndefined<Type extends object>(object: Type): ConditionalExcept<Type, undefined>;
/**
* Clones a plain object using object spread notation
*
* @param value - the value to check
*
*/
declare function clone<Type extends object>(value: Type): Type;
/**
* Shallow clone an object while preserving it's getters and setters. This is a
* an alternative to the spread clone.
*/
declare function shallowClone<Type extends object>(value: Type): Type;
/**
* Alias for fast deep equal
*/
declare const isEqual: (a: any, b: any) => boolean;
/**
* Create a unique array in a non-mutating manner
*
* @param array - the array which will be reduced to its unique elements
* @param fromStart - when set to true the duplicates will be removed from the
* beginning of the array. This defaults to false.
*
* @returns a new array containing only unique elements (by reference)
*
*/
declare function uniqueArray<Type>(array: Type[], fromStart?: boolean): Type[];
/**
* Flattens an array.
*
* @param array
*
*/
declare function flattenArray<Type>(array: any[]): Type[];
/**
* noop is a shorthand way of saying `No Operation` and is a function that does
* nothing.
*
* And Sometimes doing nothing is the best policy.
*/
declare function noop(): undefined;
/**
* A deep merge which only merges plain objects and Arrays. It clones the object
* before the merge so will not mutate any of the passed in values.
*
* To completely remove a key you can use the `Merge` helper class which
* replaces it's key with a completely new object
*/
declare function deepMerge<Type = any>(...objects: Array<object | unknown[]>): Type;
interface ClampProps {
min: number;
max: number;
value: number;
}
/**
* Clamps the value to the provided range.
*/
declare function clamp({ min, max, value }: ClampProps): number;
/**
* Get the last element of the array.
*/
declare function last<Type>(array: Type[]): Type;
/**
* Sorts an array while retaining the original order when the compare method
* identifies the items as equal.
*
* `Array.prototype.sort()` is unstable and so values that are the same will
* jump around in a non deterministic manner. Here I'm using the index as a
* fallback. If two elements have the same priority the element with the lower
* index is placed first hence retaining the original order.
*
* @param array - the array to sort
* @param compareFn - compare the two value arguments `a` and `z` - return 0 for
* equal - return number > 0 for a > z - return number < 0 for
* z > a
*/
declare function sort<Type>(array: Type[], compareFn: (a: Type, z: Type) => number): Type[];
/**
* Get a property from an object or array by a string path or an array path.
*
* @param obj - object to retrieve property from
* @param path - path to property
*/
declare function get<Return>(root: Shape, path: string | string[], defaultValue?: unknown): Return;
/**
* Set the value of a given path for the provided object. Does not mutate the
* original object.
*/
declare function set(path: number | string | Array<string | number>, obj: Shape, value: unknown): Shape;
/**
* Unset the value of a given path within an object.
*/
declare function unset(path: Array<string | number>, target: Shape): Shape;
/**
* Create a unique array of objects from a getter function or a property list.
*
* @param array - the array to extract unique values from
* @param getValue - a getter function or a string with the path to the item
* that is being used as a a test for uniqueness.
* @param fromStart - when true will remove duplicates from the start rather
* than from the end
*
* ```ts
* import { uniqueBy } from '@remirror/core-helpers';
*
* const values = uniqueBy([{ id: 'a', value: 'Awesome' }, { id: 'a', value: 'ignored' }], item => item.id);
* log(values) // => [{id: 'a', value: 'Awesome'}]
*
* const byKey = uniqueBy([{ id: 'a', value: 'Awesome' }, { id: 'a', value: 'ignored' }], 'id')
* // Same as above
* ```
*/
declare function uniqueBy<Item = any>(array: Item[], getValue: ((item: Item) => unknown) | string | string[], fromStart?: boolean): Item[];
/**
* Create a range from start to end.
*
* If only start is provided it creates an array of the size provided. if start
* and end are provided it creates an array who's first position is start and
* final position is end. i.e. `length = (end - start) + 1`.
*
* If you'd like to create a typed tuple of up to `40` items then pass in a
* `[number]` tuple as the first argument.
*/
declare function range<Size extends number>(size: [Size]): TupleRange<Size>;
declare function range(size: number): number[];
declare function range(start: number, end: number): number[];
/**
* Check that a number is within the minimum and maximum bounds of a set of
* numbers.
*
* @param value - the number to test
*/
declare function within(value: number, ...rest: Array<number | undefined | null>): boolean;
/**
* Safe implementation of hasOwnProperty with typechecking.
*
* @remarks
*
* See {@link https://eslint.org/docs/rules/no-prototype-builtins}
*
* @param obj - the object to check
* @param key - the property to check
*
* @typeParam Obj - the object type
* @typeParam Property - the property which can be a string | number | symbol
*/
declare function hasOwnProperty<Obj extends object, Property extends string | number | symbol>(object_: Obj, key: Property): object_ is Property extends keyof Obj ? Obj : Obj & {
Key: unknown;
};
/**
* Helper for getting an array from a function or array.
*/
declare function getLazyArray<Type>(value: Type[] | (() => Type[])): Type[];
/**
* Fixes the default import for a CommonJS module.
*
* @internal
*
* @remark
*
* With ESM it is possible to export both a default value and multiple named exports.
* With CJS it is possible to "mock" ESM functionality with a `__esModule=true` flag
* but still only export a single "default" export, or multiple named exports.
*
* This helper method detects when a library tries to do a "default" export with other named values
* and returns the "intended" default value.
*
* It also handles CJS exports that export an entire object via `module.exports = {}` rather than export syntax,
* as well as extracting the `default` (if exists) from a dynamic import.
*
* Note there is not "namedExport" equivalent because it is assumed module loaders successfully parse that
* out for both CJS and ESM.
*
* @param {*} mod - "default" export that might be wrapped in another layer
* @returns {*} unwrapped module
*/
declare function defaultImport<T>(mod: T): T;
/**
* A freeze method for objects that only runs in development. Helps prevent code
* that shouldn't be mutated from being mutated during development.
*
* @remarks
*
* This function passes the value back unchanged when in a production
* environment. It's purpose is to help prevent bad practice while developing
* by avoiding mutation of values that shouldn't be mutated.
*/
declare function freeze<Target extends object>(target: Target, options?: FreezeOptions): Readonly<Target>;
interface FreezeOptions {
/**
* Whether the key that is being accessed should exist on the target object.
*
* @defaultValue undefined
*/
requireKeys?: boolean;
}
export { Cast, RemirrorError, type RemirrorErrorOptions, assert, assertGet, callIfDefined, capitalize, clamp, cleanupOS, clone, deepMerge, defaultImport, entries, findMatches, flattenArray, format, freeze, get, getLazyArray, hasOwnProperty, includes, invariant, isAndroidOS, isArray, isBoolean, isClass, isDate, isDirectInstanceOf, isEmptyArray, isEmptyObject, isEqual, isError, isFunction, isInstanceOf, isInteger, isJSONPrimitive, isMap, isNativePromise, isNonEmptyArray, isNull, isNullOrUndefined, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSafeInteger, isSet, isString, isSymbol, isUndefined, keys, last, noop, object, omitUndefined, randomFloat, randomInt, range, set, shallowClone, sort, startCase, take, toString, uniqueArray, uniqueBy, uniqueId, unset, values, within };

192

dist/remirror-core-helpers.js

@@ -1,6 +0,6 @@

// src/core-errors.ts
// packages/remirror__core-helpers/src/core-errors.ts
import { BaseError as BaseError2 } from "make-error";
import { ErrorConstant } from "@remirror/core-constants";
// src/core-helpers.ts
// packages/remirror__core-helpers/src/core-helpers.ts
import deepmerge from "deepmerge";

@@ -11,3 +11,12 @@ import fastDeepEqual from "fast-deep-equal";

import pick from "object.pick";
import { camelCase, capitalCase, constantCase, kebabCase, pascalCase, pathCase, snakeCase, spaceCase } from "case-anything";
import {
camelCase,
capitalCase,
constantCase,
kebabCase,
pascalCase,
pathCase,
snakeCase,
spaceCase
} from "case-anything";
import { debounce, throttle } from "throttle-debounce";

@@ -43,3 +52,3 @@ function Cast(value) {

function object(value) {
return Object.assign( /* @__PURE__ */Object.create(null), value);
return Object.assign(/* @__PURE__ */ Object.create(null), value);
}

@@ -54,3 +63,3 @@ function toString(value) {

function isOfType(type, predicate) {
return value => {
return (value) => {
if (typeof value !== type) {

@@ -63,3 +72,3 @@ return false;

function isObjectOfType(type) {
return value => getObjectType(value) === type;
return (value) => getObjectType(value) === type;
}

@@ -71,3 +80,3 @@ function isDirectInstanceOf(instance, Constructor) {

var isString = isOfType("string");
var isNumber = isOfType("number", value => !Number.isNaN(value));
var isNumber = isOfType("number", (value) => !Number.isNaN(value));
var isFunction = isOfType("function");

@@ -110,3 +119,3 @@ function isNull(value) {

function isInstanceOf(Constructor) {
return value => isObject(value) && value instanceof Constructor;
return (value) => isObject(value) && value instanceof Constructor;
}

@@ -116,3 +125,3 @@ function isNativePromise(value) {

}
var hasPromiseAPI = value => !!(!isNull(value) && isObject(value) && isFunction(value.then) && isFunction(value.catch));
var hasPromiseAPI = (value) => !!(!isNull(value) && isObject(value) && isFunction(value.then) && isFunction(value.catch));
function isPromise(value) {

@@ -152,3 +161,3 @@ return isNativePromise(value) || hasPromiseAPI(value);

}
function findMatches(text, regexp, runWhile = match => !!match) {
function findMatches(text, regexp, runWhile = (match) => !!match) {
regexp.lastIndex = 0;

@@ -174,3 +183,5 @@ const results = [];

}
return format(os.replace(/ ce$/i, " CE").replace(/\bhpw/i, "web").replace(/\bMacintosh\b/, "Mac OS").replace(/_powerpc\b/i, " OS").replace(/\b(os x) [^\d ]+/i, "$1").replace(/\bMac (OS X)\b/, "$1").replace(/\/(\d)/, " $1").replace(/_/g, ".").replace(/(?: bepc|[ .]*fc[\d .]+)$/i, "").replace(/\bx86\.64\b/gi, "x86_64").replace(/\b(Windows Phone) OS\b/, "$1").replace(/\b(Chrome OS \w+) [\d.]+\b/, "$1").split(" on ")[0] ?? "");
return format(
os.replace(/ ce$/i, " CE").replace(/\bhpw/i, "web").replace(/\bMacintosh\b/, "Mac OS").replace(/_powerpc\b/i, " OS").replace(/\b(os x) [^\d ]+/i, "$1").replace(/\bMac (OS X)\b/, "$1").replace(/\/(\d)/, " $1").replace(/_/g, ".").replace(/(?: bepc|[ .]*fc[\d .]+)$/i, "").replace(/\bx86\.64\b/gi, "x86_64").replace(/\b(Windows Phone) OS\b/, "$1").replace(/\b(Chrome OS \w+) [\d.]+\b/, "$1").split(" on ")[0] ?? ""
);
}

@@ -212,3 +223,3 @@ function isAndroidOS() {

function omitUndefined(object2) {
return omit(object2, value => !isUndefined(value));
return omit(object2, (value) => !isUndefined(value));
}

@@ -219,5 +230,3 @@ function clone(value) {

}
return {
...value
};
return { ...value };
}

@@ -248,11 +257,5 @@ function shallowClone(value) {

function deepMerge(...objects) {
return deepmerge.all(objects, {
isMergeableObject: isPlainObject
});
return deepmerge.all(objects, { isMergeableObject: isPlainObject });
}
function clamp({
min,
max,
value
}) {
function clamp({ min, max, value }) {
if (value < min) {

@@ -267,8 +270,3 @@ return min;

function sort(array, compareFn) {
return [...array].map((value, index) => ({
value,
index
})).sort((a, z) => compareFn(a.value, z.value) || a.index - z.index).map(({
value
}) => value);
return [...array].map((value, index) => ({ value, index })).sort((a, z) => compareFn(a.value, z.value) || a.index - z.index).map(({ value }) => value);
}

@@ -284,6 +282,9 @@ function get(root, path, defaultValue) {

let obj = root;
path.replace(/\[\s*(["'])(.*?)\1\s*]|^\s*(\w+)\s*(?=\.|\[|$)|\.\s*(\w*)\s*(?=\.|\[|$)|\[\s*(-?\d+)\s*]/g, (_, __, quotedProp, firstLevel, namedProp, index) => {
obj = obj[quotedProp || firstLevel || namedProp || index];
return "";
});
path.replace(
/\[\s*(["'])(.*?)\1\s*]|^\s*(\w+)\s*(?=\.|\[|$)|\.\s*(\w*)\s*(?=\.|\[|$)|\[\s*(-?\d+)\s*]/g,
(_, __, quotedProp, firstLevel, namedProp, index) => {
obj = obj[quotedProp || firstLevel || namedProp || index];
return "";
}
);
return obj === void 0 ? defaultValue : obj;

@@ -337,5 +338,3 @@ } catch {

}
item = isArray(item) ? [...item] : {
...item
};
item = isArray(item) ? [...item] : { ...item };
value[key] = item;

@@ -347,7 +346,7 @@ value = item;

function makeFunctionForUniqueBy(value) {
return item => get(item, value);
return (item) => get(item, value);
}
function uniqueBy(array, getValue, fromStart = false) {
const unique = [];
const found = /* @__PURE__ */new Set();
const found = /* @__PURE__ */ new Set();
const getter = isFunction(getValue) ? getValue : makeFunctionForUniqueBy(getValue);

@@ -367,14 +366,11 @@ const list = fromStart ? [...array].reverse() : array;

if (!isNumber(end)) {
return Array.from({
length: Math.abs(startValue)
}, (_, index) => (startValue < 0 ? -1 : 1) * index);
return Array.from(
{ length: Math.abs(startValue) },
(_, index) => (startValue < 0 ? -1 : 1) * index
);
}
if (startValue <= end) {
return Array.from({
length: end + 1 - startValue
}, (_, index) => index + startValue);
return Array.from({ length: end + 1 - startValue }, (_, index) => index + startValue);
}
return Array.from({
length: startValue + 1 - end
}, (_, index) => -1 * index + startValue);
return Array.from({ length: startValue + 1 - end }, (_, index) => -1 * index + startValue);
}

@@ -395,3 +391,3 @@ function within(value, ...rest) {

// src/core-errors.ts
// packages/remirror__core-helpers/src/core-errors.ts
var ERROR_INFORMATION_URL = "https://remirror.io/docs/errors";

@@ -463,7 +459,3 @@ var errorMessageMap = {

*/
constructor({
code,
message,
disableLogging = false
} = {}) {
constructor({ code, message, disableLogging = false } = {}) {
const errorCode = isErrorConstant(code) ? code : ErrorConstant.CUSTOM;

@@ -485,3 +477,3 @@ super(createErrorMessage(errorCode, message));

// src/default-import.ts
// packages/remirror__core-helpers/src/default-import.ts
function defaultImport(mod) {

@@ -498,3 +490,3 @@ if (typeof mod !== "object" || mod === null) {

// src/freeze.ts
// packages/remirror__core-helpers/src/freeze.ts
import { ErrorConstant as ErrorConstant2 } from "@remirror/core-constants";

@@ -518,3 +510,5 @@ function freeze(target, options = {}) {

invariant(false, {
message: `It seems you're trying to set the value of the property (${String(prop)}) on a frozen object. For your protection this object does not allow direct mutation.`,
message: `It seems you're trying to set the value of the property (${String(
prop
)}) on a frozen object. For your protection this object does not allow direct mutation.`,
code: ErrorConstant2.MUTATION

@@ -525,2 +519,86 @@ });

}
export { Cast, RemirrorError, assert, assertGet, callIfDefined, camelCase, capitalCase, capitalize, clamp, cleanupOS, clone, constantCase, debounce, deepMerge, defaultImport, entries, findMatches, flattenArray, format, freeze, get, getLazyArray, hasOwnProperty, includes, invariant, isAndroidOS, isArray, isBoolean, isClass, isDate, isDirectInstanceOf, isEmptyArray, isEmptyObject, isEqual, isError, isFunction, isInstanceOf, isInteger, isJSONPrimitive, isMap, isNativePromise, isNonEmptyArray, isNull, isNullOrUndefined, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSafeInteger, isSet, isString, isSymbol, isUndefined, kebabCase, keys, last, noop, object, omit, omitUndefined, pascalCase, pathCase, pick, randomFloat, randomInt, range, set, shallowClone, snakeCase, sort, spaceCase, startCase, take, throttle, toString, uniqueArray, uniqueBy, uniqueId, unset, values, within };
export {
Cast,
RemirrorError,
assert,
assertGet,
callIfDefined,
camelCase,
capitalCase,
capitalize,
clamp,
cleanupOS,
clone,
constantCase,
debounce,
deepMerge,
defaultImport,
entries,
findMatches,
flattenArray,
format,
freeze,
get,
getLazyArray,
hasOwnProperty,
includes,
invariant,
isAndroidOS,
isArray,
isBoolean,
isClass,
isDate,
isDirectInstanceOf,
isEmptyArray,
isEmptyObject,
isEqual,
isError,
isFunction,
isInstanceOf,
isInteger,
isJSONPrimitive,
isMap,
isNativePromise,
isNonEmptyArray,
isNull,
isNullOrUndefined,
isNumber,
isObject,
isPlainObject,
isPrimitive,
isPromise,
isRegExp,
isSafeInteger,
isSet,
isString,
isSymbol,
isUndefined,
kebabCase,
keys,
last,
noop,
object,
omit,
omitUndefined,
pascalCase,
pathCase,
pick,
randomFloat,
randomInt,
range,
set,
shallowClone,
snakeCase,
sort,
spaceCase,
startCase,
take,
throttle,
toString,
uniqueArray,
uniqueBy,
uniqueId,
unset,
values,
within
};
{
"name": "@remirror/core-helpers",
"version": "0.0.0-pr2169.2",
"version": "0.0.0-pr2223.1",
"description": "Provide helper functions for the remirror codebase, kinda like a tiny lodash",

@@ -33,4 +33,4 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/remirror__core-helpers",

"dependencies": {
"@remirror/core-constants": "0.0.0-pr2169.2",
"@remirror/types": "0.0.0-pr2169.2",
"@remirror/core-constants": "0.0.0-pr2223.1",
"@remirror/types": "0.0.0-pr2223.1",
"@types/object.omit": "^3.0.0",

@@ -48,5 +48,2 @@ "@types/object.pick": "^1.3.2",

},
"devDependencies": {
"@remirror/cli": "0.0.0-pr2169.2"
},
"publishConfig": {

@@ -65,6 +62,3 @@ "access": "public"

}
},
"scripts": {
"build": "remirror-cli build"
}
}

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