const {get} = require('http');
const {Iconv} = require('iconv');
const {parseString} = require('xml2js');
const {inspect} = require('util');
get('http://www.cbr.ru/scripts/XML_daily.asp', res => {
const data = [];
res
.pipe(new Iconv('cp1251', 'utf8'))
.on('data', chunk => data.push(chunk))
.on('end', () =>
parseString(
Buffer.concat(data),
(err, res) => console.log(inspect(res, {depth: null}))
)
);
});
loader: 'babel-loader',
include: [
path.resolve(__dirname, './src'),
]
const data = [
[42, 'red'],
[44, 'red'],
[42, 'green'],
[44, 'green'],
[46, 'green'],
[42, 'blue'],
[46, 'blue']
];
data.reduce((s, [size, color]) => {
if (size == selectedSize) s.add(color);
return s;
}, new Set());
$ browserify --node server.js -t [ babelify --presets [ babili ] ] $(node -p 'Object.keys(require(`./package.json`).dependencies).map(e => `--exclude ${e}`).join(` `)') -o server.min.js
var d = new Date(2016, 10, 20);
var end = new Date(2017, 0, 20);
var dates = [];
while (d <= end) {
dates.push(d.toLocaleDateString());
d.setDate(d.getDate() + 1);
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('node.js это круто? ', (answer) => {
switch (answer.toLowerCase()) {
case 'да':
case 'yes':
console.log(answer, '- это правильный ответ');
break;
default:
console.log(answer, '- ошибочное мнение');
}
rl.close();
});
rl.write('Да');
"webpack-dev-server/client?http://localhost:8080/"
Effectively, the 'readable' event indicates that the stream has new information: either new data is available or the end of the stream has been reached. In the former case, stream.read() will return the available data. In the latter case, stream.read() will return null.
var instance = ReactDOM.render(<MyComponent />. document.body);
instance.setState({myState: 1});
import io from 'socket.io-client';
export default ({dispatch, getState}) => {
const socket = io();
socket.on('dispatch', action => { dispatch(action) });
return next => action => {
const {type, payload, meta} = action;
if (meta && meta.socket) {
socket.emit(type, payload);
} else {
next(action);
}
};
};
export const handleSubmit = data => ({
type: 'SUBMIT_TO_SERVER',
payload: data,
meta: {socket: true}
});
export const handleChange = event => ({
type: 'CHANGE_VALUE',
payload: event.target.value
});
export default (state = '', {type, payload}) => {
if (type == 'CHANGE_VALUE') return payload;
else return state;
};
import {connect} from 'react-redux';
import {handleChange, handleSubmit} from 'actions';
const Form = ({state, handleChange, handleSubmit}) => <form onChange={handleChange} onSubmit={handleSubmit}>
<input type='text' value={state} />
<button>Submit</button>
</form>;
export default connect(state => state, {handleChange, handleSubmit})(Form);
socket.on('SUBMIT_TO_SERVER', data => {
socket.emit('dispatch', {
type: 'CHANGE_VALUE',
payload: data ? data.toUpperCase() : ''
});
});
(async function run() {
var results = [];
for (const url of urls) {
results.push(await getData(url));
}
console.log(results);
})();
{
"dependencies": {
"babel-core": "latest",
"babel-preset-es2015-node6": "latest",
"babel-preset-stage-3": "latest",
"babel-register": "latest"
},
"babel": {
"presets": [
"es2015-node6",
"stage-3"
]
},
"scripts": {
"start": "node -r babel-register server.js"
}
}
class Test extends React.Component {
state = {
text: '',
select: 0
};
handleChange = ({target: {id, value}}) => {
const data = {[id]: value};
if (id == 'text') data.select = value.length % 3;
this.setState(data);
};
render() {
return <div>
<input type='text' id='text' value={this.state.text} onChange={this.handleChange} />
<select id='select' value={this.state.select} onChange={this.handleChange}>
<option value='0'>option1</option>
<option value='1'>option2</option>
<option value='2'>option3</option>
</select>
</div>;
}
}