本文整理汇总了TypeScript中lodash.mixin函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mixin函数的具体用法?TypeScript mixin怎么用?TypeScript mixin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mixin函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
import _ from 'lodash';
_.mixin({
move: function (array, fromIndex, toIndex) {
array.splice(toIndex, 0, array.splice(fromIndex, 1)[0] );
return array;
}
});
示例2: function
.run(() => {
_.mixin({
arraySwap: function(array, a, b) {
if (_.isArray(array) && _.size(array) > a && _.size(array) > b) {
const temp = array[a];
array[a] = array[b];
array[b] = temp;
}
return array;
}
});
_.mixin({
zipBy: function(array, kfield, vfield) {
if (_.isArray(array) && kfield) {
if (vfield) {
return _.zipObject(_.map(array, kfield), _.map(array, vfield));
} else {
return _.zipObject(_.map(array, kfield), array);
}
} else {
return {};
}
}
});
_.mixin({
set: function(obj, field) {
return function(value) {
obj[field] = value;
};
}
});
_.mixin({
setWithCallback: function(obj, field, cb) {
return function(value) {
cb = cb || angular.noop;
obj[field] = value;
cb(value);
};
}
});
_.mixin({
flattenTree: function flattenTree(obj, extractChildren) {
if (!_.isArray(obj) && obj) {
obj = [obj];
}
if (_.isEmpty(obj)) {
return [];
}
return _.union(
obj,
_(obj)
.map(function(o) {
return flattenTree(extractChildren(o), extractChildren);
})
.flatten()
.value()
);
}
});
_.mixin({
reducedIndexOf: function(obj, extractor, combinator) {
if (!_.isArray(obj) && obj) {
obj = [obj];
}
let results = {};
_.each(obj, function(o) {
const index = extractor(o);
if (results[index]) {
results[index] = combinator(results[index], o);
} else {
results[index] = o;
}
});
return results;
}
});
})
示例3: require
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//--------------------------------------------
// Extend lodash
var _ = require('lodash');
_.mixin(require('lodash-deep'));
//--------------------------------------------
const url = require('url');
const Promise = require('bluebird');
const path = require('path');
const paths = require('../paths');
const config = require('../config');
const getPort = require('get-port');
//---------------------------------------------------
// Look for server certificates
interface ProtocolOptions {
key?: string;
cert?: string;
示例4:
import _ from 'lodash';
/*
Mixins :)
*/
_.mixin({
move: (array, fromIndex, toIndex) => {
array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]);
return array;
},
});