const parseDate = (str, format) => {
if (!format) return new Date(str);
const mask = {};
for (const { 0: key, index } of format.matchAll(/(SSS|ss|mm|HH|DD|MM|YYYY|YY)/g)) {
mask[key] = parseInt(str.substr(index, key.length)) || 0;
}
const year = mask.YYYY || (mask.YY && `20${mask.YY}`) || 0;
const month = (mask.MM || 1) - 1;
const day = mask.DD || 0;
const hour = mask.HH || 0;
const minute = mask.mm || 0;
const second = mask.ss || 0;
const millisecond = mask.SSS || 0;
return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
};
const maxChar = str => {
const charObj = {};
let max = {char:'', count:''};
let maxChar = '';
for (let char of str) {
if (charObj[char]) {
charObj[char]++;
} else {
charObj[char] = 1;
}
if ( charObj[char] >= max.count ) {
max.char = char
max.count = charObj[char]
}
}
return max.char;
};
console.log( maxChar('abccccsddasdadwqwf'))
fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin"
})
[
'gd00.55...dgfdg',
'gd0055dgfdg',
'a252.25a',
'a25225a',
'a252,25a',
'252,25a',
'a252,250',
'-d--252,2534567',
'',
'aaa',
'0',
].forEach( input => {
// Добавлены слеши для экранирования, выражение - RegExp('...').toString()
const scale = 1;
const regExp = `(-?\\d+)([.,]${ scale ? '\\d{1,' + scale + '}' : '' })?`;
const result = +( new RegExp(regExp).exec(input) || ['0'] )[0].replace(',', '.');
console.log( '"%s" → [ %s ]', input, result );
});
"gd00.55...dgfdg" → [ 0.5 ]
"gd0055dgfdg" → [ 55 ]
"a252.25a" → [ 252.2 ]
"a25225a" → [ 25225 ]
"a252,25a" → [ 252.2 ]
"252,25a" → [ 252.2 ]
"a252,250" → [ 252.2 ]
"-d--252,2534567" → [ -252.2 ]
"" → [ 0 ]
"aaa" → [ 0 ]
"0" → [ 0 ]
doctype html
html
head
title Slim Examples
meta name="keywords" content="template language"
link rel="stylesheet" href="table_image.css"
body
#block1.block
a *{href: '#block1'} Hide
#block2.block
a *{href: '#'} Show Block 1
body {
display: flex;
height: 100vh;
}
#block1 {
flex: 0 0 30%;
background-color: #ccc;
}
#block2 {
flex-basis: 100%;
background-color: #eee;
}
#block1:target {
display: none;
}
doctype html
html
head
title Slim Examples
meta name="keywords" content="template language"
link rel="stylesheet" href="table_image.css"
body
table
tr
td
.img *{ style: "background-image: url('http://lorempixel.com/100/200/');" }
td
.img *{ style: "background-image: url('http://lorempixel.com/100/300/');" }
.img {
height: 100px;
width: 100px;
background-repeat:no-repeat;
background-size: 100% 100% / contain;
}
moment = require( 'moment' );
moment.locale('ru');
console.log(moment('25.05.2017', 'DD.MM.YYYY').format( 'dddd' ));
// четверг
isObject = (item) ->
item and typeof item is 'object' and not Array.isArray item
mergeDeep = (target, source) ->
if isObject(target) and isObject(source)
Object.keys(source).forEach (key) ->
if isObject source[ key ]
if not target[key] then Object.assign target, { "#{key}": {} }
mergeDeep target[ key ], source[ key ]
else
Object.assign target, { "#{key}": source[key] }
target
obj1 = {a:1, b: {b1: 1, b2: 4}}
obj2 = {b: {b1: 2, b3: {b11:4, b21:3}}, c:{c1: {c12: 5} } }
console.log(mergeDeep(obj1, obj2));
###
{ a: 1,
b: { b1: 2, b2: 4, b3: { b11: 4, b21: 3 } },
c: { c1: { c12: 5 } } }
###
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-ui/i18n/datepicker-uk
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Конечная дата фильтрации
$( '#date_start' )
.val GetSession $sessionKey, 'date_start'
.data 'old-value', GetSession $sessionKey, 'date_start'
.datepicker onSelect: ->
$this = $( @ )
$thisVal = $this.val( )
if $thisVal isnt $this.data 'old-value'
SetSession $sessionKey, 'date_start', $thisVal
$this.data 'old-value', $thisVal
$dateEnd = $( '#date_end' )
$dateEndVal = $dateEnd.val( )
if not $dateEndVal || moment( $thisVal, $formatDate ).isAfter( moment( $dateEndVal, $formatDate ) )
SetSession $sessionKey, 'date_end', $thisVal
$dateEnd.val( $thisVal ).data 'old-value', $thisVal
filterTable( ) # Фильтрация таблицы документов
function assignLocation(siteUrl, urlParams) {
let serializeParams = ''
for (let item of Object.entries(urlParams)) {
serializeParams += `&${ item[0] }=${ item[1] }`
}
let url = `${siteUrl}?${serializeParams.slice(1)}`;
//window.location.assign(url);
console.log(url);
}
assignLocation('https://www.site.com/test', { id: 324, name: 'Jack', age: 25 } ); // https://www.site.com/test?id=324&name=Jack&age=25
$("document").ready(function() {
$('.input-radio-gift').click(function() {
$(this).next('a').css('color', '#337ab7').siblings('a').css('color', '#fac902');
});
});