@alitajs/autils
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -25,2 +25,3 @@ export { default as arrayToObject } from './arrayToObject'; | ||
export { default as Policy } from './Policy'; | ||
export { default as NumberPrecision } from './NumberPrecision'; | ||
export { default as ArabicChinese } from './ArabicChinese'; | ||
@@ -38,2 +39,4 @@ export { default as round } from './round'; | ||
export { default as indent } from './indent'; | ||
export * from './delay'; | ||
export * from './immediate'; | ||
export * from './enhanceType'; |
@@ -30,2 +30,3 @@ // @index(['./*', '!./_*', '!./typings.d.ts', '!./*.test.ts'], pp => `export * from '${pp.path}'`) | ||
export { default as Policy } from './Policy'; | ||
export { default as NumberPrecision } from './NumberPrecision'; | ||
export { default as ArabicChinese } from './ArabicChinese'; // Math | ||
@@ -45,3 +46,6 @@ | ||
export * from './dedent'; | ||
export { default as indent } from './indent'; | ||
export { default as indent } from './indent'; // Promise utils | ||
export * from './delay'; | ||
export * from './immediate'; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,2 @@ /** | ||
* @example | ||
* | ||
* ```js | ||
@@ -23,3 +22,2 @@ * const actions = { | ||
* @example | ||
* | ||
* ``` | ||
@@ -52,3 +50,3 @@ * { module: 'module1', action: 'action1' } | ||
/** 该权限策略版本 */ | ||
version: string | number; | ||
version: number; | ||
/** 授权语句集合 */ | ||
@@ -96,3 +94,3 @@ statement: IStatement[]; | ||
* @param actions 操作集合 | ||
* @param separator 分隔符 | ||
* @param separator 分隔符 默认: '/' | ||
* */ | ||
@@ -102,10 +100,38 @@ constructor(actions: IAction[], separator?: string); | ||
* 按照模块组织操作 | ||
* @param actions 权限集合 | ||
* */ | ||
private getModuleMap; | ||
/** | ||
* 验证组合条件的权限 | ||
* @param actionStr 需要验证的权限 | ||
* @example | ||
* ```js | ||
* policy.combinationVerify('((goods/create && !goods/list) && goods/info)') | ||
* ``` | ||
* */ | ||
combinationVerify: (actionStr: string) => boolean; | ||
/** | ||
* 验证单个或多个权限 | ||
* @param actions | ||
*/ | ||
multipleVerify: (actions: string | string[]) => boolean; | ||
/** | ||
* 验证单个权限 | ||
* @param action | ||
*/ | ||
singleVerify: (action: string) => boolean; | ||
/** | ||
* 添加权限策略 | ||
* @param policy | ||
*/ | ||
addPolicy: (policy: IPolicyData) => void; | ||
/** | ||
* 解析权限 | ||
* @param action | ||
*/ | ||
private parseAction; | ||
/** | ||
* 获取所有的Action | ||
*/ | ||
private getAllAction; | ||
} |
@@ -50,3 +50,3 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
* @param actions 操作集合 | ||
* @param separator 分隔符 | ||
* @param separator 分隔符 默认: '/' | ||
* */ | ||
@@ -58,5 +58,7 @@ function Policy(actions, separator) { | ||
// 以module为key存储权限 | ||
this.moduleMap = {}; | ||
/** | ||
* 按照模块组织操作 | ||
* @param actions 权限集合 | ||
* */ | ||
@@ -77,15 +79,26 @@ | ||
return moduleMap; | ||
}; // 需要验证组合条件时 | ||
// eg: '((goods/create && !goods/list) && goods/info) || * || goods/info' | ||
}; | ||
/** | ||
* 验证组合条件的权限 | ||
* @param actionStr 需要验证的权限 | ||
* @example | ||
* ```js | ||
* policy.combinationVerify('((goods/create && !goods/list) && goods/info)') | ||
* ``` | ||
* */ | ||
this.combinationVerify = function (actionStr) { | ||
var reg = /([\w|\d|\*]+\/[\w|*]+)|\*/g; | ||
var matchList = actionStr.match(reg); | ||
matchList.map(function (item) { | ||
var regStr = '([\\w|\\d|\\*]+\\/[\\w|*]+)|\\*'; | ||
var reg = new RegExp(regStr, 'g'); | ||
(actionStr.match(reg) || []).map(function (item) { | ||
var result = _this.singleVerify(item) ? 'true' : 'false'; | ||
actionStr = actionStr.replace(/([\w|\d|\*]+\/[\w|*]+)|\*/, result); | ||
actionStr = actionStr.replace(new RegExp(regStr), result); | ||
}); | ||
return !!eval(actionStr); | ||
}; // 验证Action | ||
}; | ||
/** | ||
* 验证单个或多个权限 | ||
* @param actions | ||
*/ | ||
@@ -106,9 +119,12 @@ | ||
} | ||
return true; | ||
} | ||
}; // 验证单个action | ||
// * | 'module1/action1' | ||
return true; | ||
}; | ||
/** | ||
* 验证单个权限 | ||
* @param action | ||
*/ | ||
this.singleVerify = function (action) { | ||
@@ -132,6 +148,11 @@ // 表示任何用户皆可以访问 | ||
}; | ||
/** | ||
* 添加权限策略 | ||
* @param policy | ||
*/ | ||
this.addPolicy = function (policy) { | ||
if (!policy) return; | ||
var statement = policy.statement; | ||
var statement = policy.statement; // 解析授权语句 | ||
@@ -152,4 +173,5 @@ if (statement && statement.length) { | ||
}); | ||
} | ||
} // 允许 | ||
if (effect === 'allow') { | ||
@@ -160,4 +182,5 @@ var actionList = _this.allowActions.concat(actions); | ||
return; | ||
} | ||
} // 禁止 | ||
if (effect === 'deny') { | ||
@@ -171,3 +194,7 @@ var _actionList = _this.denyActions.concat(actions); | ||
} | ||
}; // 解析Action | ||
}; | ||
/** | ||
* 解析权限 | ||
* @param action | ||
*/ | ||
@@ -198,3 +225,6 @@ | ||
return result; | ||
}; // 获取所有的Action | ||
}; | ||
/** | ||
* 获取所有的Action | ||
*/ | ||
@@ -201,0 +231,0 @@ |
@@ -25,2 +25,3 @@ export { default as arrayToObject } from './arrayToObject'; | ||
export { default as Policy } from './Policy'; | ||
export { default as NumberPrecision } from './NumberPrecision'; | ||
export { default as ArabicChinese } from './ArabicChinese'; | ||
@@ -38,2 +39,4 @@ export { default as round } from './round'; | ||
export { default as indent } from './indent'; | ||
export * from './delay'; | ||
export * from './immediate'; | ||
export * from './enhanceType'; |
@@ -31,2 +31,3 @@ "use strict"; | ||
Policy: true, | ||
NumberPrecision: true, | ||
ArabicChinese: true, | ||
@@ -188,2 +189,8 @@ round: true, | ||
}); | ||
Object.defineProperty(exports, "NumberPrecision", { | ||
enumerable: true, | ||
get: function get() { | ||
return _NumberPrecision["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ArabicChinese", { | ||
@@ -304,2 +311,4 @@ enumerable: true, | ||
var _NumberPrecision = _interopRequireDefault(require("./NumberPrecision")); | ||
var _ArabicChinese = _interopRequireDefault(require("./ArabicChinese")); | ||
@@ -340,3 +349,29 @@ | ||
var _delay = require("./delay"); | ||
Object.keys(_delay).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _delay[key]; | ||
} | ||
}); | ||
}); | ||
var _immediate = require("./immediate"); | ||
Object.keys(_immediate).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _immediate[key]; | ||
} | ||
}); | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,2 @@ /** | ||
* @example | ||
* | ||
* ```js | ||
@@ -23,3 +22,2 @@ * const actions = { | ||
* @example | ||
* | ||
* ``` | ||
@@ -52,3 +50,3 @@ * { module: 'module1', action: 'action1' } | ||
/** 该权限策略版本 */ | ||
version: string | number; | ||
version: number; | ||
/** 授权语句集合 */ | ||
@@ -96,3 +94,3 @@ statement: IStatement[]; | ||
* @param actions 操作集合 | ||
* @param separator 分隔符 | ||
* @param separator 分隔符 默认: '/' | ||
* */ | ||
@@ -102,10 +100,38 @@ constructor(actions: IAction[], separator?: string); | ||
* 按照模块组织操作 | ||
* @param actions 权限集合 | ||
* */ | ||
private getModuleMap; | ||
/** | ||
* 验证组合条件的权限 | ||
* @param actionStr 需要验证的权限 | ||
* @example | ||
* ```js | ||
* policy.combinationVerify('((goods/create && !goods/list) && goods/info)') | ||
* ``` | ||
* */ | ||
combinationVerify: (actionStr: string) => boolean; | ||
/** | ||
* 验证单个或多个权限 | ||
* @param actions | ||
*/ | ||
multipleVerify: (actions: string | string[]) => boolean; | ||
/** | ||
* 验证单个权限 | ||
* @param action | ||
*/ | ||
singleVerify: (action: string) => boolean; | ||
/** | ||
* 添加权限策略 | ||
* @param policy | ||
*/ | ||
addPolicy: (policy: IPolicyData) => void; | ||
/** | ||
* 解析权限 | ||
* @param action | ||
*/ | ||
private parseAction; | ||
/** | ||
* 获取所有的Action | ||
*/ | ||
private getAllAction; | ||
} |
@@ -61,3 +61,3 @@ "use strict"; | ||
* @param actions 操作集合 | ||
* @param separator 分隔符 | ||
* @param separator 分隔符 默认: '/' | ||
* */ | ||
@@ -69,5 +69,7 @@ function Policy(actions, separator) { | ||
// 以module为key存储权限 | ||
this.moduleMap = {}; | ||
/** | ||
* 按照模块组织操作 | ||
* @param actions 权限集合 | ||
* */ | ||
@@ -88,15 +90,26 @@ | ||
return moduleMap; | ||
}; // 需要验证组合条件时 | ||
// eg: '((goods/create && !goods/list) && goods/info) || * || goods/info' | ||
}; | ||
/** | ||
* 验证组合条件的权限 | ||
* @param actionStr 需要验证的权限 | ||
* @example | ||
* ```js | ||
* policy.combinationVerify('((goods/create && !goods/list) && goods/info)') | ||
* ``` | ||
* */ | ||
this.combinationVerify = function (actionStr) { | ||
var reg = /([\w|\d|\*]+\/[\w|*]+)|\*/g; | ||
var matchList = actionStr.match(reg); | ||
matchList.map(function (item) { | ||
var regStr = '([\\w|\\d|\\*]+\\/[\\w|*]+)|\\*'; | ||
var reg = new RegExp(regStr, 'g'); | ||
(actionStr.match(reg) || []).map(function (item) { | ||
var result = _this.singleVerify(item) ? 'true' : 'false'; | ||
actionStr = actionStr.replace(/([\w|\d|\*]+\/[\w|*]+)|\*/, result); | ||
actionStr = actionStr.replace(new RegExp(regStr), result); | ||
}); | ||
return !!eval(actionStr); | ||
}; // 验证Action | ||
}; | ||
/** | ||
* 验证单个或多个权限 | ||
* @param actions | ||
*/ | ||
@@ -117,9 +130,12 @@ | ||
} | ||
return true; | ||
} | ||
}; // 验证单个action | ||
// * | 'module1/action1' | ||
return true; | ||
}; | ||
/** | ||
* 验证单个权限 | ||
* @param action | ||
*/ | ||
this.singleVerify = function (action) { | ||
@@ -143,6 +159,11 @@ // 表示任何用户皆可以访问 | ||
}; | ||
/** | ||
* 添加权限策略 | ||
* @param policy | ||
*/ | ||
this.addPolicy = function (policy) { | ||
if (!policy) return; | ||
var statement = policy.statement; | ||
var statement = policy.statement; // 解析授权语句 | ||
@@ -163,4 +184,5 @@ if (statement && statement.length) { | ||
}); | ||
} | ||
} // 允许 | ||
if (effect === 'allow') { | ||
@@ -171,4 +193,5 @@ var actionList = _this.allowActions.concat(actions); | ||
return; | ||
} | ||
} // 禁止 | ||
if (effect === 'deny') { | ||
@@ -182,3 +205,7 @@ var _actionList = _this.denyActions.concat(actions); | ||
} | ||
}; // 解析Action | ||
}; | ||
/** | ||
* 解析权限 | ||
* @param action | ||
*/ | ||
@@ -209,3 +236,6 @@ | ||
return result; | ||
}; // 获取所有的Action | ||
}; | ||
/** | ||
* 获取所有的Action | ||
*/ | ||
@@ -212,0 +242,0 @@ |
{ | ||
"name": "@alitajs/autils", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "Awesome Utils(前端常用工具方法)", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:alitajs/autils.git", |
@@ -36,2 +36,3 @@ <h1 align="center">autils</h1> | ||
* [ArabicChinese](https://alitajs.github.io/autils/classes/arabicchinese.html) 阿拉伯数字和中文数字互转 | ||
* [NumberPrecision](https://alitajs.github.io/autils/classes/numberprecision.html) 解决浮动运算问题,避免小数点后产生多数值和计算精度损失 | ||
* [Policy](https://alitajs.github.io/autils/classes/policy.html) 解析权限策略,并提供验证功能 | ||
@@ -46,5 +47,7 @@ <!-- 工具类i目录 --> | ||
* [deepClone](https://alitajs.github.io/autils/globals.html#deepclone) 深拷贝 | ||
* [delay](https://alitajs.github.io/autils/globals.html#delay) 休眠函数 | ||
* [forOwn](https://alitajs.github.io/autils/globals.html#forown) 遍历对象的可枚举属性。若遍历函数返回 `false`,遍历会提前退出。 | ||
* [getType](https://alitajs.github.io/autils/globals.html#gettype) 检测 `value` 的类型 | ||
* [groupBy](https://alitajs.github.io/autils/globals.html#groupby) 根据迭代函数返回的值对 `data` 进行分组。 | ||
* [immediate](https://alitajs.github.io/autils/globals.html#immediate) 推迟执行 | ||
* [indent](https://alitajs.github.io/autils/globals.html#indent) 每一行紧跟前导空白的插入值为多行时,保持缩进。 | ||
@@ -51,0 +54,0 @@ * [isArray](https://alitajs.github.io/autils/globals.html#isarray) 检查 `value` 是否是一个数组 |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
439937
344
6608
83