本文整理汇总了TypeScript中lodash.mapKeys函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapKeys函数的具体用法?TypeScript mapKeys怎么用?TypeScript mapKeys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapKeys函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dumpToCSV
public dumpToCSV(resultFile: string) {
const newResult = _.mapKeys(this.result as _.Dictionary<any>, (v, k) => {
if (k !== 'repoName') {
return `${requestTypeMapping.get(this.requestType)}_${k}`;
} else {
return 'repoName';
}
});
if (!fs.existsSync(resultFile)) {
console.log(papa.unparse([newResult]));
fs.writeFileSync(resultFile, papa.unparse([newResult]));
} else {
const file = fs.createReadStream(resultFile);
papa.parse(file, {
header: true,
complete: parsedResult => {
const originResults = parsedResult.data;
const index = originResults.findIndex(originResult => {
return originResult.repoName === newResult.repoName;
});
if (index === -1) {
originResults.push(newResult);
} else {
originResults[index] = { ...originResults[index], ...newResult };
}
fs.writeFileSync(resultFile, papa.unparse(originResults));
},
});
}
}
示例2: buildSorter
export function buildSorter(options: any, index?: number, bindVarsMap?: any): any {
if (_.isNil(options.sort) || _.isEmpty(options.sort)) {
return '';
}
if (!index) {
index = 0;
}
if (!bindVarsMap) {
bindVarsMap = {};
}
const sort = _.mapKeys(options.sort, (value, key) => {
return autoCastKey(key);
});
let sortKeysOrder = '';
let i = 1;
let objLength = Object.keys(sort).length;
for (let key in sort) {
if (objLength == i) {
// Do not append ',' for the last element
sortKeysOrder = `${sortKeysOrder} ${key} ${sort[key]} `;
} else {
sortKeysOrder = `${sortKeysOrder} ${key} ${sort[key]},`;
}
i += 1;
}
return 'SORT ' + sortKeysOrder;
}
示例3: payments
export function payments(state: PaymentsState = initialState, {type, payload}: Action): PaymentsState {
switch (type) {
case PatientActions.REMOVE_SUCCESS: {
const data = _.omitBy(state.data, p => p.patient_id == payload) as PaymentData;
const ids = _.values(data).map(data => data['id']);
return { ...state, ids, data };
}
case PaymentsActions.EDIT_SUCCESS: {
return { ...state, data: { ...state.data, [payload.id]: payload } };
}
case PaymentsActions.CREATE_SUCCESS: {
const data = { ...state.data, [payload.id]: payload };
const ids = [payload.id, ...state.ids];
return { selected: payload.id, status: true, ids , data };
}
case PaymentsActions.REMOVE_SUCCESS: {
const ids = state.ids.filter(ids => ids !== payload.id);
const data = _.omit(state.data, payload.id) as PaymentData;
return { ...state, ids, data };
}
case PaymentsActions.INIT_SUCCESS: {
const ids = payload.map(data => data.id);
const data = _.mapKeys(payload, 'id') as PaymentData;
return { ...state, status: false, ids, data };
}
default: return state;
}
};
示例4: diary
export function diary(state: DiaryState = initialState, {type, payload}: Action): DiaryState {
switch (type) {
case DiaryActions.SELECT: {
const date = payload.date as Date;
const y = date.getFullYear();
const m = date.getMonth()+1;
const d = date.getDate();
return { ...state, date, selected: 'diary_'+d+'_'+m+'_'+y };
}
case DiaryActions.CREATE_SUCCESS: {
const data = { ...state.data, [payload.id]: payload };
const ids = [payload.id, ...state.ids];
return { ...state, date: payload.date, selected: payload.id, status: true, ids , data };
}
case DiaryActions.INIT_SUCCESS: {
const ids = payload.map(data => data.id);
const data = _.mapKeys(payload, 'id') as DiaryData;
return { ...state, status: false, ids, data };
}
default: return state;
}
};
示例5: store
export function store(state: StoreState = initialState, {type, payload}: Action): StoreState {
switch (type) {
case StoreActions.SELECT: {
return { ...state, selected: payload.id };
}
case StoreActions.REMOVE_SUCCESS: {
const ids = state.ids.filter(ids => ids !== payload.id);
const data = _.omit(state.data, payload.id);
return Object.assign({}, state, { ids, data });
}
case StoreActions.CREATE_SUCCESS: {
const data = { ...state.data, [payload.id]: payload };
const ids = [payload.id, ...state.ids];
return { ...state, selected: payload.id, ids , data };
}
case StoreActions.INIT_SUCCESS: {
const ids = payload.map(data => data.id);
const data = _.mapKeys(payload, 'id') as StoreData;
return { ...state, ids, data };
}
default: return state;
}
};
示例6: patients
export function patients(state: PatientsState = initialState, {type, payload}: Action): PatientsState {
switch (type) {
case PatientActions.FETCH: {
return Object.assign({}, state, { selected: payload });
}
case PatientActions.CREATE_SUCCESS: {
const data = update_data(state.data, payload.id, { type, payload });
const ids = [payload.id, ...state.ids];
return Object.assign({}, { selected: payload.id, status: true, ids , data });
}
case PatientActions.EDIT_SUCCESS: {
const data = update_data(state.data, payload.id, { type, payload });
return Object.assign({}, state, { data });
}
case PatientActions.REMOVE_SUCCESS: {
const ids = state.ids.filter(ids => ids !== payload);
const data = _.omit(state.data, payload);
return Object.assign({}, state, { ids, data });
}
case PatientsActions.INIT_SUCCESS: {
const ids = payload.map(data => data.id);
const data = _.mapKeys(payload, 'id') as PatientData;
return Object.assign({}, state, { status: false, ids, data });
}
default: return state;
}
};
示例7: convertProps
function convertProps(attributes: xmlParser.Attributes): string {
let props;
props = _.mapKeys(attributes, (value: string, key: string) => _.camelCase(key));
if (_.isEmpty(props)) {
return "undefined";
}
return stringify(props);
}
示例8:
return JSON.parse(JSON.stringify(model), (key, value) => {
return _.isObject(value) && !_.isArray(value)
? _.mapKeys(value, (v, k: string) => {
return k.replace(/{{[^{}]+}}/g, (token: string) => {
return model[token.replace(/[{}]+/g, '')];
});
})
: value;
});
示例9: function
return _.transform(obj, function (result, value, key) {
if (_.isObject(value) && !_.isArray(value)) {
const flatMap = _.mapKeys(flattenObject(value), (_mvalue, mkey) => {
return `${key}.${mkey}`;
});
_.assign(result, flatMap);
} else {
result[key] = value;
}
return result;
}, {});
示例10:
$("*").each((idx, element) => {
const attrs = element.attribs;
const patchedAttrs = _.mapKeys<any>(
attrs,
(value, key) => (attrsNeedToConvert[key] ? attrsNeedToConvert[key] : key),
);
_.assign(element, {
attribs: patchedAttrs,
});
});