import chain from '@bingo347/fn/mappers/chain';
import extractField from '@bingo347/fn/mappers/extractField';
// создаем функцию для безопасного извлечения
const getBCDE = chain(
extractField('B'),
extractField('C'),
extractField('D'),
extractField('E')
);
// извлекаем
const ABCDE = getBCDE(A);
const TestClass = (function() {
class TestClass {
constructor() {
this.calls = '';
}
toString() {
return this.calls;
}
}
Object.setPrototypeOf(TestClass.prototype, Function.prototype);
function callTestClassInstance(el) {
this.calls += String(el);
}
return new Proxy(TestClass, {
construct(TestClass, args) {
const instance = new TestClass(...args);
const target = args => callTestClassInstance.apply(instance, args);
Object.setPrototypeOf(target, TestClass.prototype);
return new Proxy(target, {
apply(target, _, args) {
return target(args);
},
get(_, name) {
return instance[name];
},
set(_, name, value) {
instance[name] = value;
return true;
},
has(_, name) {
return name in instance;
},
deleteProperty(_, name) {
return delete instance[name];
},
defineProperty(_, name, descriptor) {
return Object.defineProperty(instance, name, descriptor);
},
getOwnPropertyDescriptor(_, name) {
return Object.getOwnPropertyDescriptor(instance, name);
},
ownKeys() {
return Object.getOwnPropertyNames(instance).concat(Object.getOwnPropertySymbols(instance));
}
});
}
});
})();
const appleDevice = /iP(hone|od|ad)/;
const applePhone = /iPhone/i;
const appleIPod = /iPod/i;
const appleTablet = /iPad/i;
const androidPhone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i;
const androidTablet = /Android/i;
const windowsPhone = /Windows Phone/i;
const windowsTablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i;
const otherBlackberry = /BlackBerry/i;
const otherOpera = /Opera Mini/i;
const otherFirefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i;
const sevenInch = /(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)/i;
function match(regex, target = navigator.userAgent) {
return regex.test(target);
}
export const isAppleDevice = match(applePhone) || match(appleIPod) || match(appleTablet) || match(appleDevice, navigator.platform);
export const isAndroidDevice = match(androidPhone) || match(androidTablet);
export const isWindowsDevice = match(windowsPhone) || match(windowsTablet);
export const isOtherDevice = match(otherBlackberry) || match(otherOpera) || match(otherFirefox);
export const isSevenInch = match(sevenInch);
export const isMobileDevice = isAppleDevice || isAndroidDevice || isWindowsDevice || isOtherDevice || isSevenInch;
export const isEmulator = isMobileDevice && !isWindowsDevice && (match(/Mac/, navigator.platform) || match(/Win32/, navigator.platform));
// мне кажется, что ждать полной загрузки страницы тут незачем
document.addEventListener('DOMContentLoaded', () => {
new Slider({
images: ".slider__galary img",
btnPrev: ".btnPrev",
btnNext: ".btnNext",
rate: false
});
});
// хелпер для прослушивания событий
class EventListener {
constructor(ctx, handlers, target) {
this.ctx = ctx;
this.handlers = handlers;
Object.keys(handlers).forEach(event => target.addEventListener(event, this));
}
handleEvent(event) {
const {handlers, ctx} = this;
const {type} = event;
if(typeof handlers[type] !== 'function') return;
handlers[type].call(ctx, event);
}
}
class Slider {
construnctor({images, btnPrev, btnNext, rate, time = 1000}) {
this.images = document.querySelectorAll(images);
this.i = 0;
new EventListener(this, {
click: this.prev
}, document.querySelector(btnPrev));
new EventListener(this, {
click: this.next
}, document.querySelector(btnNext));
if(rate) {
setInterval(() => this.next(), time);
}
}
prev() {
this.images[i].classList.remove("showed");
this.i--;
if(this.i < 0){
this.i = this.images.length - 1;
}
this.images[i].classList.add("showed");
}
next() {
this.images[i].classList.remove("showed");
this.i++;
if(this.i >= this.images.length){
this.i = 0;
}
this.images[i].classList.add("showed");
}
}
const {PassThrough} = require('stream');
const youtubeStream = new PassThrough();
youtubeApi.downloadVideo(
'v=4P1-JwZF0Vo&t=4519s',
chunk => youtubeStream.write(chunk),
() => youtubeStream.end()
);
youtubeStream.pipe(res); // где res - выходной поток к клиенту