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

@garfish/utils

Package Overview
Dependencies
Maintainers
8
Versions
367
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@garfish/utils - npm Package Compare versions

Comparing version 0.0.36 to 0.0.37

104

dist/utils.cjs.js

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

const processError = (error, fn) => {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
try {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
fn(error, false);
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
}
fn(error, false);
}
}
catch (e) {
fn(error, typeof error === 'string');
}
};

@@ -64,2 +69,3 @@ function warn(msg) {

const warnMsg = isString ? e : e.message;
if (false) ;
console.warn(warnMsg);

@@ -688,2 +694,4 @@ });

const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__');
const __MockBody__ = '__garfishmockbody__';
const __MockHead__ = '__garfishmockhead__';

@@ -823,4 +831,83 @@ function parseContentType(input) {

var ElementType;
(function (ElementType) {
ElementType[ElementType["TEXT"] = 3] = "TEXT";
ElementType[ElementType["COMMENT"] = 8] = "COMMENT";
ElementType[ElementType["ELEMENT"] = 1] = "ELEMENT";
})(ElementType || (ElementType = {}));
function Attributes({ name, value }) {
this.key = name;
this.value = value;
}
const generateAttributes = (el) => {
const list = [];
const attrs = el.attributes;
const len = attrs.length;
if (len > 0) {
// Optimize for the most common cases
if (len === 1) {
list[0] = new Attributes(attrs[0]);
}
else if (len === 2) {
list[0] = new Attributes(attrs[0]);
list[1] = new Attributes(attrs[1]);
}
else {
for (let i = 0; i < len; i++) {
list[i] = new Attributes(attrs[i]);
}
}
}
return list;
};
const createElement = (el, filter) => {
switch (el.nodeType) {
case ElementType.TEXT:
return {
type: 'text',
content: el.textContent,
};
case ElementType.COMMENT:
return {
type: 'comment',
content: el.textContent,
};
case ElementType.ELEMENT:
return filter({
type: 'element',
tagName: el.tagName.toLowerCase(),
attributes: generateAttributes(el),
children: Array.from(el.childNodes).map((node) => {
return createElement(node, filter);
}),
});
default:
warn(`Invalid node type "${el.nodeType}"`);
}
};
// 1M text takes about time 60ms
function templateParse(code, tags) {
let astTree = [];
const htmlNode = document.createElement('html');
const collectionEls = {};
const filter = (el) => {
if (tags.includes(el.tagName)) {
collectionEls[el.tagName].push(el);
}
return el;
};
htmlNode.innerHTML = code;
for (const tag of tags) {
collectionEls[tag] = [];
}
astTree = Array.from(htmlNode.childNodes).map((node) => {
return createElement(node, filter);
});
return [astTree, collectionEls];
}
exports.DOMApis = DOMApis;
exports.__GARFISH_FLAG__ = __GARFISH_FLAG__;
exports.__MockBody__ = __MockBody__;
exports.__MockHead__ = __MockHead__;
exports.__extends = __extends;

@@ -860,2 +947,3 @@ exports.assert = assert;

exports.sourceNode = sourceNode;
exports.templateParse = templateParse;
exports.toBoolean = toBoolean;

@@ -862,0 +950,0 @@ exports.transformUrl = transformUrl;

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

const processError = (error, fn) => {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
try {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
fn(error, false);
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
}
fn(error, false);
}
}
catch (e) {
fn(error, typeof error === 'string');
}
};

@@ -59,2 +64,3 @@ function warn(msg) {

const warnMsg = isString ? e : e.message;
if (false) ;
console.warn(warnMsg);

@@ -680,2 +686,4 @@ });

const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__');
const __MockBody__ = '__garfishmockbody__';
const __MockHead__ = '__garfishmockhead__';

@@ -815,4 +823,81 @@ function parseContentType(input) {

var ElementType;
(function (ElementType) {
ElementType[ElementType["TEXT"] = 3] = "TEXT";
ElementType[ElementType["COMMENT"] = 8] = "COMMENT";
ElementType[ElementType["ELEMENT"] = 1] = "ELEMENT";
})(ElementType || (ElementType = {}));
function Attributes({ name, value }) {
this.key = name;
this.value = value;
}
const generateAttributes = (el) => {
const list = [];
const attrs = el.attributes;
const len = attrs.length;
if (len > 0) {
// Optimize for the most common cases
if (len === 1) {
list[0] = new Attributes(attrs[0]);
}
else if (len === 2) {
list[0] = new Attributes(attrs[0]);
list[1] = new Attributes(attrs[1]);
}
else {
for (let i = 0; i < len; i++) {
list[i] = new Attributes(attrs[i]);
}
}
}
return list;
};
const createElement = (el, filter) => {
switch (el.nodeType) {
case ElementType.TEXT:
return {
type: 'text',
content: el.textContent,
};
case ElementType.COMMENT:
return {
type: 'comment',
content: el.textContent,
};
case ElementType.ELEMENT:
return filter({
type: 'element',
tagName: el.tagName.toLowerCase(),
attributes: generateAttributes(el),
children: Array.from(el.childNodes).map((node) => {
return createElement(node, filter);
}),
});
}
};
// 1M text takes about time 60ms
function templateParse(code, tags) {
let astTree = [];
const htmlNode = document.createElement('html');
const collectionEls = {};
const filter = (el) => {
if (tags.includes(el.tagName)) {
collectionEls[el.tagName].push(el);
}
return el;
};
htmlNode.innerHTML = code;
for (const tag of tags) {
collectionEls[tag] = [];
}
astTree = Array.from(htmlNode.childNodes).map((node) => {
return createElement(node, filter);
});
return [astTree, collectionEls];
}
exports.DOMApis = DOMApis;
exports.__GARFISH_FLAG__ = __GARFISH_FLAG__;
exports.__MockBody__ = __MockBody__;
exports.__MockHead__ = __MockHead__;
exports.__extends = __extends;

@@ -852,2 +937,3 @@ exports.assert = assert;

exports.sourceNode = sourceNode;
exports.templateParse = templateParse;
exports.toBoolean = toBoolean;

@@ -854,0 +940,0 @@ exports.transformUrl = transformUrl;

@@ -45,12 +45,17 @@ const objectToString = Object.prototype.toString;

const processError = (error, fn) => {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
try {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
fn(error, false);
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
}
fn(error, false);
}
}
catch (e) {
fn(error, typeof error === 'string');
}
};

@@ -60,2 +65,3 @@ function warn(msg) {

const warnMsg = isString ? e : e.message;
if (false) ;
console.warn(warnMsg);

@@ -684,2 +690,4 @@ });

const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__');
const __MockBody__ = '__garfishmockbody__';
const __MockHead__ = '__garfishmockhead__';

@@ -819,2 +827,79 @@ function parseContentType(input) {

export { DOMApis, __GARFISH_FLAG__, __extends, assert, callTestCallback, computeErrorUrl, computeStackTraceFromStackProp, createAppContainer, createKey, deepMerge, def, error, evalWithEnv, filterAndWrapEventListener, findTarget, getRenderNode, hasOwn, inBrowser, internFunc, isAbsolute, isCss, isHtml, isJs, isObject, isPlainObject, isPrimitive, isPromise, makeMap, nextTick, noop, objectToString, parseContentType, remove, setDocCurrentScript, sourceListTags, sourceNode, toBoolean, transformUrl, unique, validURL, warn };
var ElementType;
(function (ElementType) {
ElementType[ElementType["TEXT"] = 3] = "TEXT";
ElementType[ElementType["COMMENT"] = 8] = "COMMENT";
ElementType[ElementType["ELEMENT"] = 1] = "ELEMENT";
})(ElementType || (ElementType = {}));
function Attributes({ name, value }) {
this.key = name;
this.value = value;
}
const generateAttributes = (el) => {
const list = [];
const attrs = el.attributes;
const len = attrs.length;
if (len > 0) {
// Optimize for the most common cases
if (len === 1) {
list[0] = new Attributes(attrs[0]);
}
else if (len === 2) {
list[0] = new Attributes(attrs[0]);
list[1] = new Attributes(attrs[1]);
}
else {
for (let i = 0; i < len; i++) {
list[i] = new Attributes(attrs[i]);
}
}
}
return list;
};
const createElement = (el, filter) => {
switch (el.nodeType) {
case ElementType.TEXT:
return {
type: 'text',
content: el.textContent,
};
case ElementType.COMMENT:
return {
type: 'comment',
content: el.textContent,
};
case ElementType.ELEMENT:
return filter({
type: 'element',
tagName: el.tagName.toLowerCase(),
attributes: generateAttributes(el),
children: Array.from(el.childNodes).map((node) => {
return createElement(node, filter);
}),
});
default:
warn(`Invalid node type "${el.nodeType}"`);
}
};
// 1M text takes about time 60ms
function templateParse(code, tags) {
let astTree = [];
const htmlNode = document.createElement('html');
const collectionEls = {};
const filter = (el) => {
if (tags.includes(el.tagName)) {
collectionEls[el.tagName].push(el);
}
return el;
};
htmlNode.innerHTML = code;
for (const tag of tags) {
collectionEls[tag] = [];
}
astTree = Array.from(htmlNode.childNodes).map((node) => {
return createElement(node, filter);
});
return [astTree, collectionEls];
}
export { DOMApis, __GARFISH_FLAG__, __MockBody__, __MockHead__, __extends, assert, callTestCallback, computeErrorUrl, computeStackTraceFromStackProp, createAppContainer, createKey, deepMerge, def, error, evalWithEnv, filterAndWrapEventListener, findTarget, getRenderNode, hasOwn, inBrowser, internFunc, isAbsolute, isCss, isHtml, isJs, isObject, isPlainObject, isPrimitive, isPromise, makeMap, nextTick, noop, objectToString, parseContentType, remove, setDocCurrentScript, sourceListTags, sourceNode, templateParse, toBoolean, transformUrl, unique, validURL, warn };

@@ -51,12 +51,17 @@ (function (global, factory) {

const processError = (error, fn) => {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
try {
if (typeof error === 'string') {
error = `${warnPrefix}: ${error}\n\n`;
fn(error, true);
}
fn(error, false);
else if (error instanceof Error) {
if (!error.message.startsWith(warnPrefix)) {
error.message = `${warnPrefix}: ${error.message}`;
}
fn(error, false);
}
}
catch (e) {
fn(error, typeof error === 'string');
}
};

@@ -66,2 +71,3 @@ function warn(msg) {

const warnMsg = isString ? e : e.message;
if (false) ;
console.warn(warnMsg);

@@ -690,2 +696,4 @@ });

const __GARFISH_FLAG__ = Symbol.for('__GARFISH_FLAG__');
const __MockBody__ = '__garfishmockbody__';
const __MockHead__ = '__garfishmockhead__';

@@ -825,4 +833,83 @@ function parseContentType(input) {

var ElementType;
(function (ElementType) {
ElementType[ElementType["TEXT"] = 3] = "TEXT";
ElementType[ElementType["COMMENT"] = 8] = "COMMENT";
ElementType[ElementType["ELEMENT"] = 1] = "ELEMENT";
})(ElementType || (ElementType = {}));
function Attributes({ name, value }) {
this.key = name;
this.value = value;
}
const generateAttributes = (el) => {
const list = [];
const attrs = el.attributes;
const len = attrs.length;
if (len > 0) {
// Optimize for the most common cases
if (len === 1) {
list[0] = new Attributes(attrs[0]);
}
else if (len === 2) {
list[0] = new Attributes(attrs[0]);
list[1] = new Attributes(attrs[1]);
}
else {
for (let i = 0; i < len; i++) {
list[i] = new Attributes(attrs[i]);
}
}
}
return list;
};
const createElement = (el, filter) => {
switch (el.nodeType) {
case ElementType.TEXT:
return {
type: 'text',
content: el.textContent,
};
case ElementType.COMMENT:
return {
type: 'comment',
content: el.textContent,
};
case ElementType.ELEMENT:
return filter({
type: 'element',
tagName: el.tagName.toLowerCase(),
attributes: generateAttributes(el),
children: Array.from(el.childNodes).map((node) => {
return createElement(node, filter);
}),
});
default:
warn(`Invalid node type "${el.nodeType}"`);
}
};
// 1M text takes about time 60ms
function templateParse(code, tags) {
let astTree = [];
const htmlNode = document.createElement('html');
const collectionEls = {};
const filter = (el) => {
if (tags.includes(el.tagName)) {
collectionEls[el.tagName].push(el);
}
return el;
};
htmlNode.innerHTML = code;
for (const tag of tags) {
collectionEls[tag] = [];
}
astTree = Array.from(htmlNode.childNodes).map((node) => {
return createElement(node, filter);
});
return [astTree, collectionEls];
}
exports.DOMApis = DOMApis;
exports.__GARFISH_FLAG__ = __GARFISH_FLAG__;
exports.__MockBody__ = __MockBody__;
exports.__MockHead__ = __MockHead__;
exports.__extends = __extends;

@@ -862,2 +949,3 @@ exports.assert = assert;

exports.sourceNode = sourceNode;
exports.templateParse = templateParse;
exports.toBoolean = toBoolean;

@@ -864,0 +952,0 @@ exports.transformUrl = transformUrl;

4

package.json
{
"name": "@garfish/utils",
"version": "0.0.36",
"version": "0.0.37",
"description": "utils module.",

@@ -40,3 +40,3 @@ "keywords": [

},
"gitHead": "23da44e1e3483b3a375add7296ff214d4884f32f"
"gitHead": "141f84c25bf5c27b828154b58fc5de271c4369c8"
}
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