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 4.0.0-beta.0 to 4.0.0-beta.1

268

dist/remirror-core-helpers.js

@@ -0,1 +1,13 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
// src/core-errors.ts

@@ -17,3 +29,3 @@ import { BaseError as BaseError2 } from "make-error";

function assertGet(value, key, message) {
const prop = value[key];
var prop = value[key];
assert(!isUndefined(prop), message);

@@ -27,4 +39,7 @@ return prop;

}
var AssertionError = class extends BaseError {
name = "AssertionError";
var AssertionError = class AssertionError extends BaseError {
constructor() {
super(...arguments);
_defineProperty(this, "name", "AssertionError");
}
};

@@ -50,3 +65,3 @@ function entries(value) {

function getObjectType(value) {
const objectName = toString(value).slice(8, -1);
var objectName = toString(value).slice(8, -1);
return objectName;

@@ -92,3 +107,3 @@ }

}
const prototype = Object.getPrototypeOf(value);
var prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.getPrototypeOf({});

@@ -144,14 +159,18 @@ }

}
function callIfDefined(fn, ...args) {
function callIfDefined(fn) {
if (isFunction(fn)) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
fn(...args);
}
}
function findMatches(text, regexp, runWhile = match => !!match) {
function findMatches(text, regexp) {
var runWhile = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : match => !!match;
regexp.lastIndex = 0;
const results = [];
const flags = regexp.flags;
let match;
var results = [];
var flags = regexp.flags;
var match;
if (!flags.includes("g")) {
regexp = new RegExp(regexp.source, `g${flags}`);
regexp = new RegExp(regexp.source, "g".concat(flags));
}

@@ -168,14 +187,16 @@ do {

function cleanupOS(os, pattern, label) {
var _os$replace$replace$r;
if (pattern && label) {
os = os.replace(new RegExp(pattern, "i"), label);
}
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$replace$r = 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]) !== null && _os$replace$replace$r !== void 0 ? _os$replace$replace$r : "");
}
function isAndroidOS() {
const ua = navigator.userAgent;
const match = new RegExp("\\bAndroid(?:/[\\d.]+|[ \\w.]*)", "i").exec(ua);
var _match$;
var ua = navigator.userAgent;
var match = new RegExp("\\bAndroid(?:/[\\d.]+|[ \\w.]*)", "i").exec(ua);
if (!match) {
return false;
}
return cleanupOS(match[0] ?? "", "Android", "Android").includes("Android");
return cleanupOS((_match$ = match[0]) !== null && _match$ !== void 0 ? _match$ : "", "Android", "Android").includes("Android");
}

@@ -193,12 +214,13 @@ function randomFloat(min, max) {

function startCase(string) {
return string.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, (_, $1, $2) => `${$1} ${$2}`).replace(/(\s|^)(\w)/g, (_, $1, $2) => `${$1}${$2.toUpperCase()}`);
return string.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, (_, $1, $2) => "".concat($1, " ").concat($2)).replace(/(\s|^)(\w)/g, (_, $1, $2) => "".concat($1).concat($2.toUpperCase()));
}
function n() {
const time = Date.now();
const last2 = n.last || time;
var time = Date.now();
var last2 = n.last || time;
return n.last = time > last2 ? time : last2 + 1;
}
n.last = 0;
function uniqueId(prefix = "") {
return `${prefix}${n().toString(36)}`;
function uniqueId() {
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
return "".concat(prefix).concat(n().toString(36));
}

@@ -216,9 +238,7 @@ function take(array, number) {

}
return {
...value
};
return _objectSpread({}, value);
}
function shallowClone(value) {
const clone2 = Object.create(Object.getPrototypeOf(value));
const descriptors = Object.getOwnPropertyDescriptors(value);
var clone2 = Object.create(Object.getPrototypeOf(value));
var descriptors = Object.getOwnPropertyDescriptors(value);
Object.defineProperties(clone2, descriptors);

@@ -228,12 +248,22 @@ return clone2;

var isEqual = fastDeepEqual;
function uniqueArray(array, fromStart = false) {
const array_ = fromStart ? [...array].reverse() : array;
const set2 = new Set(array_);
function uniqueArray(array) {
var fromStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var array_ = fromStart ? [...array].reverse() : array;
var set2 = new Set(array_);
return fromStart ? [...set2].reverse() : [...set2];
}
function flattenArray(array) {
const flattened = [];
for (const item of array) {
const itemsToInsert = isArray(item) ? flattenArray(item) : [item];
flattened.push(...itemsToInsert);
var flattened = [];
var _iterator = _createForOfIteratorHelper(array),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var item = _step.value;
var itemsToInsert = isArray(item) ? flattenArray(item) : [item];
flattened.push(...itemsToInsert);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}

@@ -245,3 +275,6 @@ return flattened;

}
function deepMerge(...objects) {
function deepMerge() {
for (var _len2 = arguments.length, objects = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
objects[_key2] = arguments[_key2];
}
return deepmerge.all(objects, {

@@ -251,7 +284,6 @@ isMergeableObject: isPlainObject

}
function clamp({
min,
max,
value
}) {
function clamp(_ref) {
var min = _ref.min,
max = _ref.max,
value = _ref.value;
if (value < min) {

@@ -269,5 +301,6 @@ return min;

index
})).sort((a, z) => compareFn(a.value, z.value) || a.index - z.index).map(({
value
}) => value);
})).sort((a, z) => compareFn(a.value, z.value) || a.index - z.index).map(_ref2 => {
var value = _ref2.value;
return value;
});
}

@@ -280,5 +313,5 @@ function get(root, path, defaultValue) {

if (isArray(path)) {
path = `['${path.join("']['")}']`;
path = "['".concat(path.join("']['"), "']");
}
let obj = root;
var obj = root;
path.replace(/\[\s*(["'])(.*?)\1\s*]|^\s*(\w+)\s*(?=\.|\[|$)|\.\s*(\w*)\s*(?=\.|\[|$)|\[\s*(-?\d+)\s*]/g, (_, __, quotedProp, firstLevel, namedProp, index) => {

@@ -289,3 +322,3 @@ obj = obj[quotedProp || firstLevel || namedProp || index];

return obj === void 0 ? defaultValue : obj;
} catch {
} catch (_unused) {
return defaultValue;

@@ -299,3 +332,3 @@ }

obj = obj || {};
const key = path[index];
var key = path[index];
assert(key);

@@ -305,3 +338,3 @@ return setClone(obj, key, setPropInternal(path, obj[key], value, ++index));

function setClone(obj, key, value) {
const newObj = clone(obj);
var newObj = clone(obj);
newObj[key] = value;

@@ -320,26 +353,35 @@ return newObj;

function unset(path, target) {
const clonedObject = clone(target);
let value = clonedObject;
for (const [index, key] of path.entries()) {
const shouldDelete = index >= path.length - 1;
let item = value[key];
if (shouldDelete) {
if (isArray(value)) {
const indexKey = Number.parseInt(key.toString(), 10);
if (isNumber(indexKey)) {
value.splice(indexKey, 1);
var clonedObject = clone(target);
var value = clonedObject;
var _iterator2 = _createForOfIteratorHelper(path.entries()),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _step2$value = _slicedToArray(_step2.value, 2),
index = _step2$value[0],
key = _step2$value[1];
var shouldDelete = index >= path.length - 1;
var item = value[key];
if (shouldDelete) {
if (isArray(value)) {
var indexKey = Number.parseInt(key.toString(), 10);
if (isNumber(indexKey)) {
value.splice(indexKey, 1);
}
} else {
Reflect.deleteProperty(value, key);
}
} else {
Reflect.deleteProperty(value, key);
return clonedObject;
}
return clonedObject;
if (isPrimitive(item)) {
return clonedObject;
}
item = isArray(item) ? [...item] : _objectSpread({}, item);
value[key] = item;
value = item;
}
if (isPrimitive(item)) {
return clonedObject;
}
item = isArray(item) ? [...item] : {
...item
};
value[key] = item;
value = item;
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}

@@ -351,13 +393,23 @@ return clonedObject;

}
function uniqueBy(array, getValue, fromStart = false) {
const unique = [];
const found = /* @__PURE__ */new Set();
const getter = isFunction(getValue) ? getValue : makeFunctionForUniqueBy(getValue);
const list = fromStart ? [...array].reverse() : array;
for (const item of list) {
const value = getter(item);
if (!found.has(value)) {
found.add(value);
unique.push(item);
function uniqueBy(array, getValue) {
var fromStart = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var unique = [];
var found = /* @__PURE__ */new Set();
var getter = isFunction(getValue) ? getValue : makeFunctionForUniqueBy(getValue);
var list = fromStart ? [...array].reverse() : array;
var _iterator3 = _createForOfIteratorHelper(list),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var item = _step3.value;
var value = getter(item);
if (!found.has(value)) {
found.add(value);
unique.push(item);
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}

@@ -367,3 +419,3 @@ return fromStart ? unique.reverse() : unique;

function range(start, end) {
const startValue = isArray(start) ? start[0] : start;
var startValue = isArray(start) ? start[0] : start;
if (!isNumber(end)) {

@@ -383,4 +435,7 @@ return Array.from({

}
function within(value, ...rest) {
const numbers = rest.filter(isNumber);
function within(value) {
for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
rest[_key3 - 1] = arguments[_key3];
}
var numbers = rest.filter(isNumber);
return value >= Math.min(...numbers) && value <= Math.max(...numbers);

@@ -401,3 +456,3 @@ }

var errorMessageMap = {
[ErrorConstant.UNKNOWN]: "An error occurred but we're not quite sure why. \u{1F9D0}",
[ErrorConstant.UNKNOWN]: "An error occurred but we're not quite sure why. \uD83E\uDDD0",
[ErrorConstant.INVALID_COMMAND_ARGUMENTS]: "The arguments passed to the command method were invalid.",

@@ -439,10 +494,6 @@ [ErrorConstant.CUSTOM]: "This is a custom error, possibly thrown by an external library.",

function createErrorMessage(code, extraMessage) {
const message = errorMessageMap[code];
const prefix = message ? `${message}
` : "";
const customMessage = extraMessage ? `${extraMessage}
` : "";
return `${prefix}${customMessage}For more information visit ${ERROR_INFORMATION_URL}#${code.toLowerCase()}`;
var message = errorMessageMap[code];
var prefix = message ? "".concat(message, "\n\n") : "";
var customMessage = extraMessage ? "".concat(extraMessage, "\n\n") : "";
return "".concat(prefix).concat(customMessage, "For more information visit ").concat(ERROR_INFORMATION_URL, "#").concat(code.toLowerCase());
}

@@ -453,3 +504,4 @@ var RemirrorError = class _RemirrorError extends BaseError2 {

*/
static create(options = {}) {
static create() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new _RemirrorError(options);

@@ -460,19 +512,21 @@ }

*/
errorCode;
/**
* The link to read more about the error online.
*/
url;
/**
* The constructor is intentionally kept private to prevent being extended from.
*/
constructor({
code,
message,
disableLogging = false
} = {}) {
const errorCode = isErrorConstant(code) ? code : ErrorConstant.CUSTOM;
constructor() {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
code = _ref3.code,
message = _ref3.message,
_ref3$disableLogging = _ref3.disableLogging,
disableLogging = _ref3$disableLogging === void 0 ? false : _ref3$disableLogging;
var errorCode = isErrorConstant(code) ? code : ErrorConstant.CUSTOM;
super(createErrorMessage(errorCode, message));
_defineProperty(this, "errorCode", void 0);
/**
* The link to read more about the error online.
*/
_defineProperty(this, "url", void 0);
this.errorCode = errorCode;
this.url = `${ERROR_INFORMATION_URL}#${errorCode.toLowerCase()}`;
this.url = "".concat(ERROR_INFORMATION_URL, "#").concat(errorCode.toLowerCase());
if (!disableLogging) {

@@ -492,6 +546,7 @@ console.error(this.message);

function defaultImport(mod) {
var _mod$default;
if (typeof mod !== "object" || mod === null) {
return mod;
}
const defaultVal = Symbol.toStringTag in mod && mod[Symbol.toStringTag] === "Module" ? mod.default ?? mod : mod;
var defaultVal = Symbol.toStringTag in mod && mod[Symbol.toStringTag] === "Module" ? (_mod$default = mod.default) !== null && _mod$default !== void 0 ? _mod$default : mod : mod;
if (defaultVal && typeof mod === "object" && "__esModule" in defaultVal && defaultVal.__esModule && defaultVal.default !== void 0) {

@@ -505,3 +560,4 @@ return defaultVal.default;

import { ErrorConstant as ErrorConstant2 } from "@remirror/core-constants";
function freeze(target, options = {}) {
function freeze(target) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (process.env.NODE_ENV === "production") {

@@ -517,3 +573,3 @@ return target;

invariant(prop in target2 || !options.requireKeys, {
message: `The prop: '${prop.toString()}' you are trying to access does not yet exist on the target.`
message: "The prop: '".concat(prop.toString(), "' you are trying to access does not yet exist on the target.")
});

@@ -524,3 +580,3 @@ return Reflect.get(target2, prop, receiver);

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 (".concat(String(prop), ") on a frozen object. For your protection this object does not allow direct mutation."),
code: ErrorConstant2.MUTATION

@@ -527,0 +583,0 @@ });

{
"name": "@remirror/core-helpers",
"version": "4.0.0-beta.0",
"version": "4.0.0-beta.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": "3.0.0-beta.0",
"@remirror/types": "2.0.0-beta.0",
"@remirror/core-constants": "3.0.0-beta.1",
"@remirror/types": "2.0.0-beta.1",
"@types/object.omit": "^3.0.0",

@@ -37,0 +37,0 @@ "@types/object.pick": "^1.3.2",

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