🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@ismartify/common

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ismartify/common - npm Package Compare versions

Comparing version
1.0.9
to
1.0.10
+1
dist/index.js
var o=class{#t=new Map;constructor(){this.set("__namespace","ismartify"),this.set("__name","ismartify.store"),this.set("__description","ismartify\u57FA\u7840\u8FD0\u884C\u65F6\u5B58\u50A8\u7C7B")}raw=()=>this.#t;get=(t,e)=>e===void 0?this.#t.get(t):this.#t.get(t)||e;set=(t,e)=>(this.#t.set(t,e),this);pick(...t){return t.map(e=>this.#t.get(e))}delete=t=>(this.#t.delete(t),this);clear=()=>(this.#t.clear(),this);has=t=>this.#t.has(t);mixin=(t,e)=>{let s=function(...i){return e(this,...i)};return this.set(`_mixin.${t}`,s),this};call=(t,...e)=>{let s=this.get(`_mixin.${t}`);if(!s)throw new Error(`Function ${t} not found in mixin`);return s.call(this,...e)};exec=(t,...e)=>t(this,...e);tap=t=>{let e=typeof t=="string"?new RegExp(t):t instanceof RegExp?t:null,n=Array.from(this.raw().entries()).filter(([r])=>!e||e.test(r)).map(([r,h])=>({key:r,value:h}));return console.table(n),this}};var a=class extends Error{_IsmartifyError=!0;statusCode=500;code="UNKNOWN_ERROR";module="noname";#t=/^(([0-9]*)\.)?([^$@#]+)?(?:#([^@$]+))?(?:@([^$]+))?$/gi;constructor(t="\u672A\u77E5\u9519\u8BEF"){super(t);let e=this.#t.exec(t||"");if(e){let[,,s="500",i="",n="UNKNOWN_ERROR",r]=e;s&&(this.statusCode=parseInt(s,10)||500),n&&(this.code=n),i&&(this.message=i),r&&(this.module=r)}}throw(){throw this}json(t=!1){let e={code:this.code,message:this.message,module:this.module};return t&&(e.stack=this.stack||""),{success:!1,error:e,status:this.statusCode}}};export{a as ISmartifyError,o as ISmartifyStore};
+1
-104

@@ -1,104 +0,1 @@

'use strict';
class ISmartifyStore {
#store = /* @__PURE__ */ new Map();
constructor() {
this.set("__namespace", "ismartify");
this.set("__name", "ismartify.store");
this.set("__description", "ismartify\u57FA\u7840\u8FD0\u884C\u65F6\u5B58\u50A8\u7C7B");
}
// 基础方法
raw = () => this.#store;
get = (k, def) => def === void 0 ? this.#store.get(k) : this.#store.get(k) || def;
set = (key, value) => {
this.#store.set(key, value);
return this;
};
//prettier-ignore
pick(...keys) {
return keys.map((k) => this.#store.get(k));
}
//简单扩展
delete = (key) => {
this.#store.delete(key);
return this;
};
clear = () => {
this.#store.clear();
return this;
};
has = (key) => this.#store.has(key);
//函数方法
mixin = (name, fn) => {
const newFn = function(...args) {
return fn(this, ...args);
};
this.set(`_mixin.${name}`, newFn);
return this;
};
// 新增 call 方法
call = (name, ...args) => {
const fn = this.get(`_mixin.${name}`);
if (!fn) throw new Error(`Function ${name} not found in mixin`);
return fn.call(this, ...args);
};
// 新增 exec 方法 - 传递 _self 参数,支持箭头函数
exec = (callback, ...args) => {
return callback(this, ...args);
};
// 新增 tap 方法 - 支持正则表达式和字符串规则
tap = (rule) => {
let regex = typeof rule === "string" ? new RegExp(rule) : rule instanceof RegExp ? rule : null;
const entries = Array.from(this.raw().entries());
const filteredEntries = entries.filter(([key]) => !regex || regex.test(key));
const resultArray = filteredEntries.map(([key, value]) => ({ key, value }));
console.table(resultArray);
return this;
};
}
class ISmartifyError extends Error {
_IsmartifyError = true;
// 标记为 ISmartifyError 实例
statusCode = 500;
// HTTP 状态码
code = "UNKNOWN_ERROR";
// 错误代码
module = "noname";
// 模块或作者
#reg = /^(([0-9]*)\.)?([^$@#]+)?(?:#([^@$]+))?(?:@([^$]+))?$/gi;
// 解析消息格式: [statusCode.]message[#err.code][@module]
//构建
constructor(message = "\u672A\u77E5\u9519\u8BEF") {
super(message);
const match = this.#reg.exec(message || "");
if (match) {
const [, , statusCodeStr = "500", message2 = "", errorCode = "UNKNOWN_ERROR", module] = match;
if (statusCodeStr) this.statusCode = parseInt(statusCodeStr, 10) || 500;
if (errorCode) this.code = errorCode;
if (message2) this.message = message2;
if (module) this.module = module;
}
}
// 获取错误响应项
throw() {
throw this;
}
// 获取错误JSON
json(stack = false) {
const errorItem = {
code: this.code,
message: this.message,
module: this.module
};
if (stack) errorItem.stack = this.stack || "";
return {
success: false,
error: errorItem,
status: this.statusCode
};
}
}
exports.ISmartifyError = ISmartifyError;
exports.ISmartifyStore = ISmartifyStore;
"use strict";var h=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var f=(i,t)=>{for(var e in t)h(i,e,{get:t[e],enumerable:!0})},d=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!l.call(i,r)&&r!==e&&h(i,r,{get:()=>t[r],enumerable:!(s=g(t,r))||s.enumerable});return i};var p=i=>d(h({},"__esModule",{value:!0}),i);var y={};f(y,{ISmartifyError:()=>c,ISmartifyStore:()=>a});module.exports=p(y);var a=class{#t=new Map;constructor(){this.set("__namespace","ismartify"),this.set("__name","ismartify.store"),this.set("__description","ismartify\u57FA\u7840\u8FD0\u884C\u65F6\u5B58\u50A8\u7C7B")}raw=()=>this.#t;get=(t,e)=>e===void 0?this.#t.get(t):this.#t.get(t)||e;set=(t,e)=>(this.#t.set(t,e),this);pick(...t){return t.map(e=>this.#t.get(e))}delete=t=>(this.#t.delete(t),this);clear=()=>(this.#t.clear(),this);has=t=>this.#t.has(t);mixin=(t,e)=>{let s=function(...r){return e(this,...r)};return this.set(`_mixin.${t}`,s),this};call=(t,...e)=>{let s=this.get(`_mixin.${t}`);if(!s)throw new Error(`Function ${t} not found in mixin`);return s.call(this,...e)};exec=(t,...e)=>t(this,...e);tap=t=>{let e=typeof t=="string"?new RegExp(t):t instanceof RegExp?t:null,o=Array.from(this.raw().entries()).filter(([n])=>!e||e.test(n)).map(([n,u])=>({key:n,value:u}));return console.table(o),this}};var c=class extends Error{_IsmartifyError=!0;statusCode=500;code="UNKNOWN_ERROR";module="noname";#t=/^(([0-9]*)\.)?([^$@#]+)?(?:#([^@$]+))?(?:@([^$]+))?$/gi;constructor(t="\u672A\u77E5\u9519\u8BEF"){super(t);let e=this.#t.exec(t||"");if(e){let[,,s="500",r="",o="UNKNOWN_ERROR",n]=e;s&&(this.statusCode=parseInt(s,10)||500),o&&(this.code=o),r&&(this.message=r),n&&(this.module=n)}}throw(){throw this}json(t=!1){let e={code:this.code,message:this.message,module:this.module};return t&&(e.stack=this.stack||""),{success:!1,error:e,status:this.statusCode}}};0&&(module.exports={ISmartifyError,ISmartifyStore});
{
"name": "@ismartify/common",
"version": "1.0.9",
"version": "1.0.10",
"description": "",

@@ -13,5 +13,5 @@ "type": "module",

"test": "vitest",
"build": "npx -y unbuild",
"build": "tsup",
"ver+": "npm version patch",
"npm:publish": "npm publish --registry https://registry.npmjs.org/ --access public --no-git-checks"
"npm:publish": "npm run ver+ && npm run build && npm publish --registry https://registry.npmjs.org/ --access public --no-git-checks"
},

@@ -22,4 +22,4 @@ "keywords": [],

"devDependencies": {
"unbuild": "^3.5.0"
"tsup": "^8.5.0"
}
}
declare class ISmartifyStore {
#private;
constructor();
raw: () => Map<string, any>;
get: (k: string, def?: any) => any;
set: (key: string, value: any) => this;
pick(...keys: string[]): any[];
delete: (key: string) => this;
clear: () => this;
has: (key: string) => boolean;
mixin: (name: string, fn: Function) => this;
call: <T extends (...args: any[]) => any>(name: string, ...args: Parameters<T>) => ReturnType<T>;
exec: <T extends (self: this, ...args: any[]) => any>(callback: T, ...args: any[]) => ReturnType<T>;
tap: (rule?: string | RegExp) => this;
}
interface IErrorItem {
code: string | number;
message: string;
module?: string;
stack?: string;
innerErrors?: IErrorItem[];
}
declare class ISmartifyError extends Error {
#private;
_IsmartifyError: boolean;
statusCode: number;
code: string;
module?: string;
constructor(message?: string);
throw(): void;
json(stack?: boolean): {
success: boolean;
error: IErrorItem;
status: number;
};
}
export { ISmartifyError, ISmartifyStore };
class ISmartifyStore {
#store = /* @__PURE__ */ new Map();
constructor() {
this.set("__namespace", "ismartify");
this.set("__name", "ismartify.store");
this.set("__description", "ismartify\u57FA\u7840\u8FD0\u884C\u65F6\u5B58\u50A8\u7C7B");
}
// 基础方法
raw = () => this.#store;
get = (k, def) => def === void 0 ? this.#store.get(k) : this.#store.get(k) || def;
set = (key, value) => {
this.#store.set(key, value);
return this;
};
//prettier-ignore
pick(...keys) {
return keys.map((k) => this.#store.get(k));
}
//简单扩展
delete = (key) => {
this.#store.delete(key);
return this;
};
clear = () => {
this.#store.clear();
return this;
};
has = (key) => this.#store.has(key);
//函数方法
mixin = (name, fn) => {
const newFn = function(...args) {
return fn(this, ...args);
};
this.set(`_mixin.${name}`, newFn);
return this;
};
// 新增 call 方法
call = (name, ...args) => {
const fn = this.get(`_mixin.${name}`);
if (!fn) throw new Error(`Function ${name} not found in mixin`);
return fn.call(this, ...args);
};
// 新增 exec 方法 - 传递 _self 参数,支持箭头函数
exec = (callback, ...args) => {
return callback(this, ...args);
};
// 新增 tap 方法 - 支持正则表达式和字符串规则
tap = (rule) => {
let regex = typeof rule === "string" ? new RegExp(rule) : rule instanceof RegExp ? rule : null;
const entries = Array.from(this.raw().entries());
const filteredEntries = entries.filter(([key]) => !regex || regex.test(key));
const resultArray = filteredEntries.map(([key, value]) => ({ key, value }));
console.table(resultArray);
return this;
};
}
class ISmartifyError extends Error {
_IsmartifyError = true;
// 标记为 ISmartifyError 实例
statusCode = 500;
// HTTP 状态码
code = "UNKNOWN_ERROR";
// 错误代码
module = "noname";
// 模块或作者
#reg = /^(([0-9]*)\.)?([^$@#]+)?(?:#([^@$]+))?(?:@([^$]+))?$/gi;
// 解析消息格式: [statusCode.]message[#err.code][@module]
//构建
constructor(message = "\u672A\u77E5\u9519\u8BEF") {
super(message);
const match = this.#reg.exec(message || "");
if (match) {
const [, , statusCodeStr = "500", message2 = "", errorCode = "UNKNOWN_ERROR", module] = match;
if (statusCodeStr) this.statusCode = parseInt(statusCodeStr, 10) || 500;
if (errorCode) this.code = errorCode;
if (message2) this.message = message2;
if (module) this.module = module;
}
}
// 获取错误响应项
throw() {
throw this;
}
// 获取错误JSON
json(stack = false) {
const errorItem = {
code: this.code,
message: this.message,
module: this.module
};
if (stack) errorItem.stack = this.stack || "";
return {
success: false,
error: errorItem,
status: this.statusCode
};
}
}
export { ISmartifyError, ISmartifyStore };