New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@alitajs/autils

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alitajs/autils - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

10

es/groupBy.d.ts

@@ -12,2 +12,5 @@ export interface GroupByIterator<T, K> {

}
export interface GroupByFormatter<T> {
(item: T, index: number, data: T[]): any;
}
/**

@@ -18,6 +21,7 @@ * 根据迭代函数返回的值对 `data` 进行分组。

* @param iterator 迭代函数
* @param formatter 格式化函数
* @returns 返回分组结果
* @example
* ```ts
* * groupBy(
* groupBy(
* [

@@ -28,3 +32,3 @@ * { module: 'module1', action: 'action1' },

* ],
* item => item.type,
* item => item.module,
* )

@@ -42,2 +46,2 @@ * // => {

*/
export default function groupBy<T, K extends keyof any>(data: T[], iterator: GroupByIterator<T, K>): Record<K, T[]>;
export default function groupBy<T, K extends keyof any>(data: T[], iterator: GroupByIterator<T, K>, formatter?: GroupByFormatter<T>): Record<K, T[]>;

@@ -6,6 +6,7 @@ /**

* @param iterator 迭代函数
* @param formatter 格式化函数
* @returns 返回分组结果
* @example
* ```ts
* * groupBy(
* groupBy(
* [

@@ -16,3 +17,3 @@ * { module: 'module1', action: 'action1' },

* ],
* item => item.type,
* item => item.module,
* )

@@ -30,3 +31,3 @@ * // => {

*/
export default function groupBy(data, iterator) {
export default function groupBy(data, iterator, formatter) {
return data.reduce(function (res, item, index) {

@@ -39,3 +40,3 @@ var key = iterator(item, index, data);

res[key].push(item);
res[key].push(formatter ? formatter(item, index, data) : item);
return res;

@@ -42,0 +43,0 @@ }, {});

@@ -91,3 +91,10 @@ /**

denyActions: string[];
/**
* @param actions 操作集合
* @param separator 分隔符
* */
constructor(actions: IAction[], separator?: string);
/**
* 按照模块组织操作
* */
private getModuleMap;

@@ -94,0 +101,0 @@ combinationVerify: (actionStr: string) => boolean;

@@ -13,2 +13,3 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

import isArray from '../isArray';
import groupBy from '../groupBy';
/**

@@ -47,3 +48,8 @@ * 解析权限策略,并提供验证功能

var Policy = function Policy(actions, separator) {
var Policy =
/**
* @param actions 操作集合
* @param separator 分隔符
* */
function Policy(actions, separator) {
var _this = this;

@@ -54,2 +60,5 @@

this.moduleMap = {};
/**
* 按照模块组织操作
* */

@@ -60,12 +69,7 @@ this.getModuleMap = function () {

if (actions && actions.length) {
actions.forEach(function (item) {
var moduleName = item.module;
var policyAction = "".concat(item.module, "/").concat(item.action);
if (!moduleMap[moduleName]) {
moduleMap[moduleName] = [policyAction];
} else {
moduleMap[moduleName].push(policyAction);
}
if (actions) {
moduleMap = groupBy(actions, function (item) {
return item.module;
}, function (item) {
return "".concat(item.module).concat(_this.separator).concat(item.action);
});

@@ -200,5 +204,7 @@ }

return actions;
}; // 模块的操作集合
}; // 分隔符自定义
this.separator = separator || '/'; // 模块的操作集合
this.moduleMap = this.getModuleMap(actions); // 允许的操作

@@ -208,5 +214,3 @@

this.denyActions = []; // 分隔符自定义
this.separator = separator || '/';
this.denyActions = [];
};

@@ -213,0 +217,0 @@

@@ -12,2 +12,5 @@ export interface GroupByIterator<T, K> {

}
export interface GroupByFormatter<T> {
(item: T, index: number, data: T[]): any;
}
/**

@@ -18,6 +21,7 @@ * 根据迭代函数返回的值对 `data` 进行分组。

* @param iterator 迭代函数
* @param formatter 格式化函数
* @returns 返回分组结果
* @example
* ```ts
* * groupBy(
* groupBy(
* [

@@ -28,3 +32,3 @@ * { module: 'module1', action: 'action1' },

* ],
* item => item.type,
* item => item.module,
* )

@@ -42,2 +46,2 @@ * // => {

*/
export default function groupBy<T, K extends keyof any>(data: T[], iterator: GroupByIterator<T, K>): Record<K, T[]>;
export default function groupBy<T, K extends keyof any>(data: T[], iterator: GroupByIterator<T, K>, formatter?: GroupByFormatter<T>): Record<K, T[]>;

@@ -13,6 +13,7 @@ "use strict";

* @param iterator 迭代函数
* @param formatter 格式化函数
* @returns 返回分组结果
* @example
* ```ts
* * groupBy(
* groupBy(
* [

@@ -23,3 +24,3 @@ * { module: 'module1', action: 'action1' },

* ],
* item => item.type,
* item => item.module,
* )

@@ -37,3 +38,3 @@ * // => {

*/
function groupBy(data, iterator) {
function groupBy(data, iterator, formatter) {
return data.reduce(function (res, item, index) {

@@ -46,3 +47,3 @@ var key = iterator(item, index, data);

res[key].push(item);
res[key].push(formatter ? formatter(item, index, data) : item);
return res;

@@ -49,0 +50,0 @@ }, {});

@@ -91,3 +91,10 @@ /**

denyActions: string[];
/**
* @param actions 操作集合
* @param separator 分隔符
* */
constructor(actions: IAction[], separator?: string);
/**
* 按照模块组织操作
* */
private getModuleMap;

@@ -94,0 +101,0 @@ combinationVerify: (actionStr: string) => boolean;

@@ -12,2 +12,4 @@ "use strict";

var _groupBy = _interopRequireDefault(require("../groupBy"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -57,3 +59,8 @@

* */
var Policy = function Policy(actions, separator) {
var Policy =
/**
* @param actions 操作集合
* @param separator 分隔符
* */
function Policy(actions, separator) {
var _this = this;

@@ -64,2 +71,5 @@

this.moduleMap = {};
/**
* 按照模块组织操作
* */

@@ -70,12 +80,7 @@ this.getModuleMap = function () {

if (actions && actions.length) {
actions.forEach(function (item) {
var moduleName = item.module;
var policyAction = "".concat(item.module, "/").concat(item.action);
if (!moduleMap[moduleName]) {
moduleMap[moduleName] = [policyAction];
} else {
moduleMap[moduleName].push(policyAction);
}
if (actions) {
moduleMap = (0, _groupBy["default"])(actions, function (item) {
return item.module;
}, function (item) {
return "".concat(item.module).concat(_this.separator).concat(item.action);
});

@@ -210,5 +215,7 @@ }

return actions;
}; // 模块的操作集合
}; // 分隔符自定义
this.separator = separator || '/'; // 模块的操作集合
this.moduleMap = this.getModuleMap(actions); // 允许的操作

@@ -218,5 +225,3 @@

this.denyActions = []; // 分隔符自定义
this.separator = separator || '/';
this.denyActions = [];
};

@@ -223,0 +228,0 @@

{
"name": "@alitajs/autils",
"version": "0.5.1",
"version": "0.5.2",
"description": "Awesome Utils(前端常用工具方法)",

@@ -21,4 +21,2 @@ "repository": "git@github.com:alitajs/autils.git",

"build": "lotus-tools build",
"prepublish": "yarn build",
"publish": "npm publish",
"docs": "ts-node scripts/buildDocs.ts",

@@ -25,0 +23,0 @@ "predeploy": "yarn docs",

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

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