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

ant-util

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ant-util - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

130

lib/array.js

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,10 +6,36 @@ Object.defineProperty(exports, "__esModule", {

});
/*
* 数组操作
* */
var removeItem = function removeItem(arr, item) {
return arr.includes(item) && arr.splice(arr.indexOf(item), 1);
exports.defaults = exports.findEqual = exports.findWhere = exports.asname = exports.findColumn = exports.object = exports.pluck = exports.countBy = exports.groupBy = exports.sortBy = exports.chainArray = exports.diffArray = exports.removeItem = undefined;
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends5 = require('babel-runtime/helpers/extends');
var _extends6 = _interopRequireDefault(_extends5);
var _object = require('./object');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var chainArray = function chainArray(actions) {
return function (datas) {
return (0, _object.reduce)(actions, function (last, handle, action) {
return last[action](handle);
}, datas);
};
}; /*
* 数组操作
* */
var removeItem = function removeItem(datas, item) {
return datas.includes(item) && datas.splice(datas.indexOf(item), 1);
};
var diff = function diff(arr1, arr2) {
var diffArray = function diffArray(arr1, arr2) {
return arr1.length === arr2.length && arr1.every(function (value) {

@@ -20,3 +46,91 @@ return arr2.includes(value);

var sortBy = function sortBy(datas, fn) {
return datas.sort(function (d1, d2) {
return fn(d1) - fn(d2);
});
};
var groupBy = function groupBy(datas, fn) {
return datas.reduce(function (last, data) {
return (0, _extends6.default)({}, last, (0, _defineProperty3.default)({}, '' + fn(data), (last[fn(data)] || []).concat(data)));
}, {});
};
var countBy = function countBy(datas, fn) {
return datas.reduce(function (last, data) {
return (0, _extends6.default)({}, last, (0, _defineProperty3.default)({}, '' + fn(data), last[fn(data)] ? ++last[fn(data)] : 1));
}, {});
};
var pluck = function pluck(datas, propertyName) {
return datas.map(function (data) {
return data[propertyName];
});
};
var object = function object(datas) {
return datas.reduce(function (last, _ref) {
var _ref2 = (0, _slicedToArray3.default)(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return (0, _extends6.default)({}, last, (0, _defineProperty3.default)({}, key, value));
}, {});
};
var findColumn = function findColumn(datas, columns) {
return datas.map(function (data) {
return (0, _object.pick)(data, columns);
});
};
var asname = function asname(table, newNames) {
return table.map(function (data) {
return (0, _object.rename)(data, newNames);
});
};
var findWhere = function findWhere(datas, handle) {
return datas.filter(function (data) {
return handle(data);
});
};
var findEqual = function findEqual(datas, where) {
var wheres = (0, _object.pairs)(where);
return datas.filter(function (data) {
return wheres.every(function (_ref3) {
var _ref4 = (0, _slicedToArray3.default)(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return data[key] === value;
});
});
};
var defaults = function defaults(datas, misses) {
return datas.map(function (data) {
var finalData = (0, _extends6.default)({}, data);
(0, _object.map)(misses, function (value, key) {
if (finalData[key] === undefined) {
finalData[key] = value;
}
});
return finalData;
});
};
exports.removeItem = removeItem;
exports.diff = diff;
exports.diffArray = diffArray;
exports.chainArray = chainArray;
exports.sortBy = sortBy;
exports.groupBy = groupBy;
exports.countBy = countBy;
exports.pluck = pluck;
exports.object = object;
exports.findColumn = findColumn;
exports.asname = asname;
exports.findWhere = findWhere;
exports.findEqual = findEqual;
exports.defaults = defaults;

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,17 +6,19 @@ Object.defineProperty(exports, "__esModule", {

});
exports.some = exports.switcher = exports.concat = exports.compose = exports.translate = undefined;
exports.propExecer = exports.any = exports.all = exports.divider = exports.execer = exports.some = exports.switcher = exports.concat = exports.compose = exports.translate = undefined;
var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _object = require('./object');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* 函数操作
* */
var translate = function translate(string) {
return new Function("return " + string)();
};
return new Function('return ' + string)();
}; /*
* 函数操作
* */
var compose = function compose(first) {

@@ -76,2 +78,60 @@ for (var _len = arguments.length, last = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {

var execer = function execer(condition, action) {
return function () {
return (0, _object.existy)(condition) ? action.apply(undefined, arguments) : undefined;
};
};
var divider = function divider(actions) {
return function () {
for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
return actions.map(function (_ref) {
var condition = _ref.condition,
action = _ref.action,
name = _ref.name;
return { name: name, value: execer(condition, action).apply(undefined, args) };
});
};
};
var all = function all() {
for (var _len8 = arguments.length, funs = Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
funs[_key8] = arguments[_key8];
}
return function (condition) {
return funs.reduce(function (truth, fun) {
return truth && fun() === condition;
}, true);
};
};
var any = function any() {
for (var _len9 = arguments.length, funs = Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
funs[_key9] = arguments[_key9];
}
return function (condition) {
return funs.reduce(function (truth, fun) {
return truth || fun() === condition;
}, false);
};
};
var propExecer = function propExecer(target, name) {
return function () {
for (var _len10 = arguments.length, args = Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
args[_key10] = arguments[_key10];
}
var action = target[name];
return execer(action, function () {
return typeof action === 'function' ? action.apply(target, args) : action;
})();
};
};
exports.translate = translate;

@@ -81,2 +141,7 @@ exports.compose = compose;

exports.switcher = switcher;
exports.some = some;
exports.some = some;
exports.execer = execer;
exports.divider = divider;
exports.all = all;
exports.any = any;
exports.propExecer = propExecer;

12

lib/index.js

@@ -7,2 +7,6 @@ 'use strict';

var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _object = require('./object');

@@ -14,4 +18,6 @@

exports.default = {
object: object
};
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var final = (0, _extends3.default)({}, object);
exports.default = final;

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -6,13 +6,17 @@ Object.defineProperty(exports, "__esModule", {

});
exports.removeItem = exports.zip = exports.walk = exports.pick = exports.omit = exports.map2Array = exports.map = exports.filter = exports.reduce = exports.each = exports.isEmptyObject = undefined;
exports.rename = exports.remove = exports.zip = exports.truthy = exports.existy = exports.walk = exports.pick = exports.omit = exports.invert = exports.pairs = exports.values = exports.map2Array = exports.map = exports.filter = exports.reduce = exports.each = undefined;
var _defineProperty2 = require("babel-runtime/helpers/defineProperty");
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends4 = require("babel-runtime/helpers/extends");
var _extends6 = require('babel-runtime/helpers/extends');
var _extends5 = _interopRequireDefault(_extends4);
var _extends7 = _interopRequireDefault(_extends6);
var _keys = require("babel-runtime/core-js/object/keys");
var _keys = require('babel-runtime/core-js/object/keys');

@@ -27,13 +31,6 @@ var _keys2 = _interopRequireDefault(_keys);

var keys = _keys2.default;
var isEmptyObject = function isEmptyObject(obj) {
return !obj || !(0, _keys2.default)(obj).length;
var identity = function identity(value) {
return value;
};
var each = function each(obj, fn) {
return keys(obj).forEach(function (k) {
return fn && fn(obj[k], k);
});
};
var reduce = function reduce(obj, handler) {

@@ -48,3 +45,3 @@ var initial = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

return reduce(obj, function (last, value, key) {
return handler(value, key) ? (0, _extends5.default)({}, last, (0, _defineProperty3.default)({}, key, value)) : last;
return handler(value, key) ? (0, _extends7.default)({}, last, (0, _defineProperty3.default)({}, key, value)) : last;
});

@@ -55,3 +52,3 @@ };

return reduce(obj, function (last, value, key) {
return (0, _extends5.default)({}, last, (0, _defineProperty3.default)({}, key, handler(value, key)));
return (0, _extends7.default)({}, last, (0, _defineProperty3.default)({}, key, handler(value, key)));
});

@@ -66,2 +63,18 @@ };

var values = function values(obj) {
return map2Array(obj, identity);
};
var pairs = function pairs(obj) {
return map2Array(obj, function (value, key) {
return [key, value];
});
};
var invert = function invert(obj) {
return reduce(obj, function (last, value, key) {
return (0, _extends7.default)({}, last, (0, _defineProperty3.default)({}, value, key));
});
};
var omit = function omit(obj, names) {

@@ -79,2 +92,28 @@ return filter(obj, function (value, key) {

var remove = function remove(obj, item) {
return (0, _keys2.default)(obj).forEach(function (k) {
return obj[k] === item && delete obj[k];
});
};
var each = function each(obj, fn) {
return keys(obj).forEach(function (k) {
return fn && fn(obj[k], k);
});
};
var existy = function existy(obj) {
return !!obj;
};
var truthy = function truthy(obj) {
return existy(obj) && ((typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object' ? !!(0, _keys2.default)(obj).length : true);
};
var zip = function zip(zipKeys, zipValues) {
return zipKeys.reduce(function (last, key, index) {
return (0, _extends7.default)({}, last, (0, _defineProperty3.default)({}, key, zipValues[index]));
}, {});
};
var walk = function walk(obj, childrenName, handler) {

@@ -92,16 +131,13 @@ var i = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;

var zip = function zip(zipKeys, zipValues) {
return zipKeys.reduce(function (last, key, index) {
last[key] = zipValues[index];
/* 返回对象新列名 */
var rename = function rename(data, newNames) {
return reduce(newNames, function (last, newName, oldName) {
if (data[oldName] !== undefined) {
last[newName] = data[oldName];
delete last[oldName];
}
return last;
}, {});
}, (0, _extends7.default)({}, data));
};
var removeItem = function removeItem(obj, item) {
return (0, _keys2.default)(obj).forEach(function (k) {
return obj[k] === item && delete obj[k];
});
};
exports.isEmptyObject = isEmptyObject;
exports.each = each;

@@ -112,6 +148,12 @@ exports.reduce = reduce;

exports.map2Array = map2Array;
exports.values = values;
exports.pairs = pairs;
exports.invert = invert;
exports.omit = omit;
exports.pick = pick;
exports.walk = walk;
exports.existy = existy;
exports.truthy = truthy;
exports.zip = zip;
exports.removeItem = removeItem;
exports.remove = remove;
exports.rename = rename;
{
"name": "ant-util",
"version": "1.0.1",
"version": "1.0.2",
"description": "ant工具组件",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -1,5 +0,2 @@

var webpack = require('webpack');
var glob = require('glob');
var fs = require('fs');
var path = require('path');
const glob = require('glob')

@@ -9,12 +6,12 @@ module.exports = {

output: {
filename: "index.js"
filename: 'index.js',
},
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/}
]
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
],
},
resolve:{
extensions:['','.js','.json']
}
};
resolve: {
extensions: ['', '.js', '.json'],
},
}
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