Skip to content

Instantly share code, notes, and snippets.

View artemsites's full-sized avatar

Artem Kuznecov artemsites

View GitHub Profile
export function objectMergeDeep(target, source) {
Object.keys(source).forEach(key => {
const targetValue = target[key];
const sourceValue = source[key];
if (typeof sourceValue === 'object' && sourceValue !== null) {
if (typeof targetValue === 'object' && targetValue !== null) {
objectMergeDeep(targetValue, sourceValue);
} else {
target[key] = (Array.isArray(sourceValue)) ? [] : {};
export function objectUpdateNested(obj, pathAndValue) {
let current = obj;
const value = pathAndValue.pop();
for (let i = 0; i < pathAndValue.length - 1; i++) {
if (typeof current[pathAndValue[i]] !== 'object' || current[pathAndValue[i]] === null) {
current[pathAndValue[i]] = {};
}
current = current[pathAndValue[i]];
export default class LocalStorageManager {
constructor() {
this.prefix = ""
}
setPrefix(newPrefix) {
this.prefix = newPrefix
}
removeLocalStorage(name) {
/**
* Проскроллить к элементу (верху или низу элемента)
*
* @author https://t.me/artemsites
*/
export default function scrollTo(params) {
let { selector, element, position } = params
let el = null
if (element) {
/**
* @author https://t.me/artemsites
*/
export default function isElementInViewportByAxisY(target) {
let el = (typeof target === 'string') ? document.querySelector(target) : target
const rect = el.getBoundingClientRect()
return (
rect.top <= 0
|| rect.bottom >= (window.innerHeight || document.documentElement.clientHeight)
);
export default function textareaAutoheight(selector) {
const textareaAll = document.querySelectorAll(selector)
textareaAll.forEach((textarea) => {
textarea.addEventListener("input", autoResize)
})
function autoResize() {
this.style.height = this.scrollHeight + "px"
}
/**
* @source https://gist.github.com/artemsites/8d260ef1682d10c70c2cf1cd256c629d
*/
export default function getParamFromUrlSearch(paramName) {
if (location.search) {
let params = location.search.split('?')[1].split("&")
let param = params.find(p=>p.includes(paramName))
if (param) return param.split('=')[1]
return false
}

Вывести "дословно" что-то в шаблон без парсинга твигом

{% verbatim %}
  {{ vueVariable }}
{% endverbatim %}
<div class="slider">
<div class="item n1">1</div>
<div class="item n2">2</div>
<div class="item n3">3</div>
</div>