Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import mapObj from 'map-obj';
const newObject: Object = mapObj({ foo: 'bar' }, function(key: string, value: any, object: Object) {
// first element is the new key and second is the new value
// here we reverse the order
return [value, key];
});
// $ExpectError
mapObj({a: 1}, (key, value, obj) => { obj.b; });
// $ExpectError
mapObj({a: 1}, (key, value, obj) => { obj.a = 'asdf'; });
// $ExpectError
(mapObj({a: 1}, (key, value, obj) => { return {b: 'asdf'}; }): {[key: string]: number});
const omitPath = (path) => {
return deepMap(path, (key, value) => {
if (key === 'path') {
return [
key,
null
];
}
return [
key,
value
];
}, {
deep: true
});
};
const overrideLastAttemptedAt = (path) => {
return deepMap(path, (key, value) => {
if (key === 'lastAttemptedAt' && typeof value === 'number') {
return [
key,
'[OVERRIDDEN]'
];
}
return [
key,
value
];
}, {
deep: true
});
};
export const translateEditorConfigToJsbeautifyConfig = editorConfig => ({
custom: mapObj(pickBy(editorConfig, (v, k) => isGlob(k) && isObject(v)), (globString, globConfig) => [
globString, mapObj(globConfig, (prefName, prefValue) => {
switch (prefName) {
case 'indent_style':
return [
'indent_char', sanitizeCharishValues(prefValue),
];
case 'insert_final_newline':
return [
'end_with_newline', prefValue,
];
default:
return [
prefName, prefValue,
];
}
}),
function camelCaseRecursive(obj) {
const transform = obj == null ? obj : mapObj(obj, (key, val) => {
const newArray = [];
if (Array.isArray(val)) {
val.forEach((value) => {
if (isObject(value) && !Array.isArray(value)) {
newArray.push(camelCaseRecursive(value));
} else {
newArray.push(value);
}
});
return [camelCase(key), newArray];
} else if (!val) {
return [camelCase(key), val];
} else if (val instanceof Date) {
return [camelCase(key), val];
custom: mapObj(pickBy(editorConfig, (v, k) => isGlob(k) && isObject(v)), (globString, globConfig) => [
globString, mapObj(globConfig, (prefName, prefValue) => {
switch (prefName) {
case 'indent_style':
return [
'indent_char', sanitizeCharishValues(prefValue),
];
case 'insert_final_newline':
return [
'end_with_newline', prefValue,
];
default:
return [
prefName, prefValue,
];
}
}),
]),
function mapPatterns (original, rules) {
return map(rules, (name, { pattern, moduleName }) => {
switch (pattern) {
case PATTERN.SYNC:
case PATTERN.EVENT:
return [name, original[name]]
case PATTERN.ASYNC:
return [name, promisify(original[name])]
case PATTERN.MODULE:
return [name, function () {
const instance = original[name].apply(this, arguments)
return mapPatterns(instance, APIS[moduleName])
}]
default:
throw new Error('Invalid pattern.')
export default (schemaSdl: string): string => {
return print(mapObject(parse(schemaSdl), (key, value) => {
if ((key === 'fields' || key === 'definitions') && Array.isArray(value)) {
return [
key,
value.slice().sort((a, b) => {
return a.name.value.localeCompare(b.name.value);
}),
];
}
return [
key,
value,
];
}, {
deep: true,
}));