var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
var sourceString = '(( @';
[...sourceString]
.map(char =>
(
sourceString.match(
RegExp(char.replace(reRegExpChar, '\\$&'), 'gi'),
) || []
).length <= 1
? '('
: ')',
)
.join('');
console.log(users.map(user => user.toJSON()))
const controllerCheckInput = value =>
users.find({ login: value }).then(res => !!res);
// вариант async/await
(async () => {
const exists = await controllerCheckInput('login');
console.log(exists);
})();
// then/catch
(() => {
controllerCheckInput('login').then(exists => {
console.log(exists);
});
})();
// примерно так это выглядит в express
app.post('/register', async (req, res) => {
const exists = await controllerCheckInput('login');
console.log(exists);
});
const io = socket();
io.use(async (socket, next) => {
try {
const { token } = socket.handshake.query;
const data = await verify(token);
socket.request.user = data;
return next();
} catch (err) {
// ignore
return next();
}
})
function parser() {
// request get
return Promise.delay(500).then(() => ({ results: [] }));
}
function* sequence() {
while (true) {
yield parser();
// other throwns
}
}
(async () => {
for (let parserPromise of sequence()) {
const parserResults = await parserPromise;
await Promise.delay(30 * 60 * 1000);
}
})();
npm install animate.css --save
import 'animate/animate.css';
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
}
]
},
@import '~bootstrap/scss/bootstrap.scss'
<?php
namespace App;
class Config {
private $values = [];
public function __construct()
{
$this->readfile();
}
public function readfile()
{
// read config.json
//
// save to ->values
};
// get
// set
// or magic methods
public function getValue()
{
return ...;
};
}
class App {
private $_config;
private $_instance = NULL;
static public function get_instance()
{
if (!$this->_instance)
{
$this->_instance = new App;
}
return $this->_instance;
};
public function __construct()
{
$this->_config = new Config;
}
public function __get($variable)
{
if ($variable === "config")
{
return $this->_config;
}
};
}
use \App\App;
App::get_instance()
->config->getValue("my.super.value")