This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec, spawn } = require('child_process'); | |
exec('cp ./component/data.txt ./page/info.txt'); // When copying files, you need to make sure the target directory exists | |
exec('cp -r ./component ./page/landing/home'); // Copy the folder, the target directory can be created automatically | |
spawn('cp', ['-r', './component', './page/landing/home']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copy the src folder to the dest folder | |
* @param {string} src | |
* @param {string} dest | |
* @param {function} callback | |
*/ | |
const copyDir = (src, dest, callback) => { | |
const copy = (copySrc, copyDest) => { | |
fs.readdir(copySrc, (err, list) => { | |
if (err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copy directory | |
fs.cp('./component', './page', { recursive: true }, (err) => { | |
if (err) { | |
console.error(err); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copy file | |
fs.cp('./data.txt', './dest/info.txt', (err) => { | |
if (err) { | |
console.error(err); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFile('./data.txt', { encoding: 'utf8' }, (err, data) => { | |
if (err) { | |
console.error(err); | |
return; | |
} | |
data = data.replace(/hi/gi, 'world'); | |
fs.writeFile('./info.txt', data, (err) => { | |
if (err) { | |
console.error(err); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((win) => { | |
const nativeLocalStorage = win.localStorage; | |
win.nativeLocalStorage = nativeLocalStorage; // keep the original usage | |
class MyLocalStorage { | |
setItem(key, value) { | |
console.log('MyLocalStorage.setItem', key, value); | |
nativeLocalStorage.setItem(key, value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyLocalStorage { | |
setItem(key, value) { | |
console.log('MyLocalStorage.setItem', key, value); | |
localStorage.setItem(key, value); | |
} | |
} | |
const myLocalStorage = new MyLocalStorage(); | |
myLocalStorage.setItem('aa', '123'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { setItem } = localStorage.__proto__; | |
localStorage.setItem = function (key, value) { | |
console.log('localStorage.__proto__.setItem', key, value); | |
setItem.call(this, key, value); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { setItem } = localStorage; | |
localStorage.setItem = function (key, value) { | |
console.log('localStorage.setItem', key, value); | |
setItem.call(this, key, value); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id="root">...</div> | |
<script> | |
window.__APOLLO_STATE__ = {//json data that's inserted in HTML, inside #root, using javascript on browser side} | |
</script> | |
</body> |
NewerOlder