Emits an E_WARNING level error if the directory already exists.
Emits an E_WARNING level error if the relevant permissions prevent creating the directory.
/**
* Create a directory
*
* @param string $path Directory path
* @param int $mode Permissions
* @return bool TRUE if directory created or exists, FALSE on failure
*/
function makedir($path, $mode)
{
if (is_dir($path)) {
return true;
}
if (is_writable($path)) {
return mkdir($path, $mode, true);
}
return false;
}
const initalState = {
foo: 'bar',
baz: 'pew',
structure: [
['', ''],
['', ''],
],
};
const reducer = (state, action) => {
switch (action.type) {
case 'ADD_INPUT':
return {
...state,
structure: state.structure.map((v1, k1) => {
if (k1 === action.first) {
return v1.map((v2, k2) => {
if (k2 === action.second) {
return action.value;
} else {
return v2;
}
});
} else {
return v1;
}
}),
};
break;
default:
return state;
}
};
const newState = reducer(initalState, {
type: 'ADD_INPUT',
first: 0,
last: 0,
value: 'foo',
});
console.log(initalState);
console.log(newState);