code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function xorBlock(words, offset, blockSize) {
var block;
// Shortcut
var iv = this._iv;
// Choose mixing block
if (iv) {
block = iv;
// Remove IV for subsequent blocks
this._iv = undefined;
... | Processes the data block at offset.
@param {Array} words The data words to operate on.
@param {number} offset The offset where the block starts.
@example
mode.processBlock(data.words, offset); | xorBlock | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/cipher-core.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/cipher-core.js | MIT |
function swapEndian(word) {
return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
} | Converts a UTF-16 LE string to a word array.
@param {string} utf16Str The UTF-16 LE string.
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); | swapEndian | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function parseLoop(base64Str, base64StrLength, reverseMap) {
var words = [];
var nBytes = 0;
for (var i = 0; i < base64StrLength; i++) {
if (i % 4) {
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
var bits2 = reverseMap[base64Str.charC... | Converts a Base64 string to a word array.
@param {string} base64Str The Base64 string.
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Base64.parse(base64String); | parseLoop | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function parseLoop(base64Str, base64StrLength, reverseMap) {
var words = [];
var nBytes = 0;
for (var i = 0; i < base64StrLength; i++) {
if (i % 4) {
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
var bits2 = reverseMap[bas... | Converts a Base64url string to a word array.
@param {string} base64Str The Base64url string.
@param {boolean} urlSafe Whether to use url safe
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Base64url.parse(base64String); | parseLoop | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function isPrime(n) {
var sqrtN = Math.sqrt(n);
for (var factor = 2; factor <= sqrtN; factor++) {
if (!(n % factor)) {
return false;
}
}
return true;
} | Shortcut function to the HMAC's object interface.
@param {WordArray|string} message The message to hash.
@param {WordArray|string} key The secret key.
@return {WordArray} The HMAC.
@static
@example
var hmac = CryptoJS.HmacSHA1(message, key); | isPrime | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function getFractionalBits(n) {
return ((n - (n | 0)) * 0x100000000) | 0;
} | Shortcut function to the HMAC's object interface.
@param {WordArray|string} message The message to hash.
@param {WordArray|string} key The secret key.
@return {WordArray} The HMAC.
@static
@example
var hmac = CryptoJS.HmacSHA1(message, key); | getFractionalBits | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function X64Word_create() {
return X64Word.create.apply(X64Word, arguments);
} | Shortcut function to the HMAC's object interface.
@param {WordArray|string} message The message to hash.
@param {WordArray|string} key The secret key.
@return {WordArray} The HMAC.
@static
@example
var hmac = CryptoJS.HmacSHA224(message, key); | X64Word_create | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function selectCipherStrategy(key) {
if (typeof key == 'string') {
return PasswordBasedCipher;
} else {
return SerializableCipher;
}
} | Creates shortcut functions to a cipher's object interface.
@param {Cipher} cipher The cipher to create a helper for.
@return {Object} An object with encrypt and decrypt shortcut functions.
@static
@example
var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); | selectCipherStrategy | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function xorBlock(words, offset, blockSize) {
var block;
// Shortcut
var iv = this._iv;
// Choose mixing block
if (iv) {
block = iv;
// Remove IV for subsequent blocks
this._iv = undefined;
... | Processes the data block at offset.
@param {Array} words The data words to operate on.
@param {number} offset The offset where the block starts.
@example
mode.processBlock(data.words, offset); | xorBlock | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function incWord(word)
{
if (((word >> 24) & 0xff) === 0xff) { //overflow
var b1 = (word >> 16)&0xff;
var b2 = (word >> 8)&0xff;
var b3 = word & 0xff;
if (b1 === 0xff) // overflow b1
{
b1 = 0;
if (b2 === 0xff)
{
b2 = 0;
if (b3 === 0xff)
{
b3 = 0;
}
else
{
... | @preserve
Counter block mode compatible with Dr Brian Gladman fileenc.c
derived from CryptoJS.mode.CTR
Jan Hruby jhruby.web@gmail.com | incWord | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function incCounter(counter)
{
if ((counter[0] = incWord(counter[0])) === 0)
{
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
counter[1] = incWord(counter[1]);
}
return counter;
} | @preserve
Counter block mode compatible with Dr Brian Gladman fileenc.c
derived from CryptoJS.mode.CTR
Jan Hruby jhruby.web@gmail.com | incCounter | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function nextState() {
// Shortcuts
var X = this._X;
var C = this._C;
// Save old counter values
for (var i = 0; i < 8; i++) {
C_[i] = C[i];
}
// Calculate new counter values
C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
C[1] = ... | Rabbit stream cipher algorithm.
This is a legacy version that neglected to convert the key to little-endian.
This error doesn't affect the cipher's security,
but it does affect its compatibility with other implementations. | nextState | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/crypto-js.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/crypto-js.js | MIT |
function parseLoop(base64Str, base64StrLength, reverseMap) {
var words = [];
var nBytes = 0;
for (var i = 0; i < base64StrLength; i++) {
if (i % 4) {
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
var bits2 = reverseMap[base64Str.charC... | Converts a Base64 string to a word array.
@param {string} base64Str The Base64 string.
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Base64.parse(base64String); | parseLoop | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/enc-base64.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/enc-base64.js | MIT |
function parseLoop(base64Str, base64StrLength, reverseMap) {
var words = [];
var nBytes = 0;
for (var i = 0; i < base64StrLength; i++) {
if (i % 4) {
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
var bits2 = reverseMap[bas... | Converts a Base64url string to a word array.
@param {string} base64Str The Base64url string.
@param {boolean} urlSafe Whether to use url safe
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Base64url.parse(base64String); | parseLoop | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/enc-base64url.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/enc-base64url.js | MIT |
function swapEndian(word) {
return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
} | Converts a UTF-16 LE string to a word array.
@param {string} utf16Str The UTF-16 LE string.
@return {WordArray} The word array.
@static
@example
var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); | swapEndian | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/enc-utf16.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/enc-utf16.js | MIT |
function incWord(word)
{
if (((word >> 24) & 0xff) === 0xff) { //overflow
var b1 = (word >> 16)&0xff;
var b2 = (word >> 8)&0xff;
var b3 = word & 0xff;
if (b1 === 0xff) // overflow b1
{
b1 = 0;
if (b2 === 0xff)
{
b2 = 0;
if (b3 === 0xff)
{
b3 = 0;
}
else
{
... | @preserve
Counter block mode compatible with Dr Brian Gladman fileenc.c
derived from CryptoJS.mode.CTR
Jan Hruby jhruby.web@gmail.com | incWord | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/mode-ctr-gladman.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/mode-ctr-gladman.js | MIT |
function incCounter(counter)
{
if ((counter[0] = incWord(counter[0])) === 0)
{
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
counter[1] = incWord(counter[1]);
}
return counter;
} | @preserve
Counter block mode compatible with Dr Brian Gladman fileenc.c
derived from CryptoJS.mode.CTR
Jan Hruby jhruby.web@gmail.com | incCounter | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/mode-ctr-gladman.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/mode-ctr-gladman.js | MIT |
function nextState() {
// Shortcuts
var X = this._X;
var C = this._C;
// Save old counter values
for (var i = 0; i < 8; i++) {
C_[i] = C[i];
}
// Calculate new counter values
C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
C[1] = ... | Rabbit stream cipher algorithm.
This is a legacy version that neglected to convert the key to little-endian.
This error doesn't affect the cipher's security,
but it does affect its compatibility with other implementations. | nextState | javascript | tangyoha/telegram_media_downloader | module/static/aes/crypto-js-master/rabbit-legacy.js | https://github.com/tangyoha/telegram_media_downloader/blob/master/module/static/aes/crypto-js-master/rabbit-legacy.js | MIT |
function getFileName(lang, i, isBeta, chapter) {
if (i === 0 && lang === "en") {
return "index.html";
}
let fileName = `${pad(i)}_${lang}.html`;
if (chapter !== undefined && chapter !== null) {
fileName = `chapter_${chapter}_${lang}.html`;
}
return fileName;
} | @param {string} lang
@param {number} i
@param {boolean} isBeta currently unused
@param {string} chapter
@returns {string} | getFileName | javascript | richardanaya/tour_of_rust | generate.js | https://github.com/richardanaya/tour_of_rust/blob/master/generate.js | MIT |
function getWord(words, lang, w) {
if (words[lang][w]) {
return words[lang][w];
}
return words.en[w];
} | @param {string[]} words
@param {string} lang
@param {string} w
@returns {string} | getWord | javascript | richardanaya/tour_of_rust | generate.js | https://github.com/richardanaya/tour_of_rust/blob/master/generate.js | MIT |
getHead = (words, lang) => {
let rtl_langs = ["ar"];
let lang_dir = rtl_langs.includes(lang) ? "rtl" : "ltr";
return `<!DOCTYPE html>
<html lang="${lang}" dir="${lang_dir}">
<head>
<title>${getWord(
words,
lang,
"tor"
)} - Let's go on an adventure!</title>
... | @param {string[]} words
@param {string} lang
@returns {string} | getHead | javascript | richardanaya/tour_of_rust | generate.js | https://github.com/richardanaya/tour_of_rust/blob/master/generate.js | MIT |
getHead = (words, lang) => {
let rtl_langs = ["ar"];
let lang_dir = rtl_langs.includes(lang) ? "rtl" : "ltr";
return `<!DOCTYPE html>
<html lang="${lang}" dir="${lang_dir}">
<head>
<title>${getWord(
words,
lang,
"tor"
)} - Let's go on an adventure!</title>
... | @param {string[]} words
@param {string} lang
@returns {string} | getHead | javascript | richardanaya/tour_of_rust | generate.js | https://github.com/richardanaya/tour_of_rust/blob/master/generate.js | MIT |
lazyLoad(args) {
lazyLoadImage(args.target, null, () => {
//callback
})
} | Lazy load the related image.
@see ../utils/image.js
It is recommended to wrap your `<img>` into an element with the
CSS class name `.c-lazy`. The CSS class name modifier `.-lazy-loaded`
will be applied on both the image and the parent wrapper.
```html
<div class="c-lazy o-ratio u-4:3">
<img data-scroll data-scro... | lazyLoad | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/modules/Scroll.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/modules/Scroll.js | MIT |
scrollTo(params) {
let { target, ...options } = params
options = Object.assign({
// Defaults
duration: 1,
}, options)
this.scroll?.scrollTo(target, options)
} | Lazy load the related image.
@see ../utils/image.js
It is recommended to wrap your `<img>` into an element with the
CSS class name `.c-lazy`. The CSS class name modifier `.-lazy-loaded`
will be applied on both the image and the parent wrapper.
```html
<div class="c-lazy o-ratio u-4:3">
<img data-scroll data-scro... | scrollTo | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/modules/Scroll.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/modules/Scroll.js | MIT |
function conformsToReference(font, criterion)
{
for (const [ key, value ] of Object.entries(criterion)) {
switch (key) {
case 'family': {
if (trim(font[key]) !== value) {
return false;
}
break;
}
case 'w... | Determines if the given font matches the given `FontFaceReference`.
@param {FontFace} font - The font to inspect.
@param {FontFaceReference} criterion - The object of property values to match.
@returns {boolean} | conformsToReference | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function conformsToShorthand(font, criterion)
{
const family = trim(font.family);
if (trim(family) === criterion) {
return true;
}
if (
criterion.endsWith(trim(family)) && (
criterion.match(font.weight) ||
criterion.match(font.style)
)
) {
re... | Determines if the given font matches the given font shorthand.
@param {FontFace} font - The font to inspect.
@param {string} criterion - The font shorthand to match.
@returns {boolean} | conformsToShorthand | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function conformsToAnyReference(font, criteria)
{
for (const criterion of criteria) {
if (conformsToReference(font, criterion)) {
return true;
}
}
return false;
} | Determines if the given font matches any of the given criteria.
@param {FontFace} font - The font to inspect.
@param {FontFaceReference[]} criteria - A list of objects with property values to match.
@returns {boolean} | conformsToAnyReference | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findManyByReference(search)
{
const found = [];
for (const font of document.fonts) {
if (conformsToReference(font, search)) {
found.push(font);
}
}
return found;
} | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided `FontFaceReference`.
@param {FontFaceReference} font
@returns {FontFace[]} | findManyByReference | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findManyByShorthand(search)
{
const found = [];
for (const font of document.fonts) {
if (conformsToShorthand(font, search)) {
found.push(font);
}
}
return found;
} | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided font shorthand.
@param {string} font
@returns {FontFace[]} | findManyByShorthand | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findOneByReference(search)
{
for (const font of document.fonts) {
if (conformsToReference(font, criterion)) {
return font;
}
}
return null;
} | Returns the first `FontFace` from `document.fonts` that satisfies
the provided `FontFaceReference`.
@param {FontFaceReference} font
@returns {?FontFace} | findOneByReference | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function findOneByShorthand(search)
{
for (const font of document.fonts) {
if (conformsToShorthand(font, search)) {
return font;
}
}
return null;
} | Returns the first `FontFace` from `document.fonts` that satisfies
the provided font shorthand.
Examples:
- "Roboto"
- "italic bold 16px Roboto"
@param {string} font
@returns {?FontFace} | findOneByShorthand | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function getAny(search) {
if (search) {
switch (typeof search) {
case 'string':
return findOneByShorthand(search);
case 'object':
return findOneByReference(search);
}
}
throw new TypeError(
'Expected font query to be font shor... | Returns a `FontFace` from `document.fonts` that satisfies
the provided query.
@param {FontFaceReference|string} font - Either:
- a `FontFaceReference` object
- a font family name
- a font specification, for example "italic bold 16px Roboto"
@returns {?FontFace}
@throws {TypeError} | getAny | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function getMany(queries) {
if (!Array.isArray(queries)) {
queries = [ queries ];
}
const found = new Set();
queries.forEach((search) => {
if (search) {
switch (typeof search) {
case 'string':
found.add(...findManyByShorthand(search));
... | Returns an iterator of all `FontFace` from `document.fonts` that satisfy
the provided queries.
@param {FontFaceReference|string|(FontFaceReference|string)[]} queries
@returns {FontFace[]}
@throws {TypeError} | getMany | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function hasAny(search) {
if (search instanceof FontFace) {
return document.fonts.has(search);
}
return getAny(search) != null;
} | Determines if a font face is registered.
@param {FontFace|FontFaceReference|string} search - Either:
- a `FontFace` instance
- a `FontFaceReference` object
- a font family name
- a font specification, for example "italic bold 16px Roboto"
@returns {boolean} | hasAny | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function loadFonts(fontsToLoad, debug = false)
{
if ((fontsToLoad.size ?? fontsToLoad.length) === 0) {
throw new TypeError(
'Expected at least one font'
);
}
return await loadFontsWithAPI([ ...fontsToLoad ], debug);
} | Eagerly load fonts.
Most user agents only fetch and load fonts when they are first needed
("lazy loaded"), which can result in a perceptible delay.
This function will "eager load" the fonts.
@param {(FontFace|FontFaceReference)[]} fontsToLoad - List of fonts to load.
@param {boolean} [debug] - If TRU... | loadFonts | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function loadFontFaceWithAPI(font)
{
return await (font.status === 'unloaded'
? font.load()
: font.loaded
).then((font) => font, (err) => font)
} | Eagerly load a font using `FontFaceSet` API.
@param {FontFace} font
@returns {Promise} | loadFontFaceWithAPI | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function loadFontsWithAPI(fontsToLoad, debug = false)
{
debug && console.group('[loadFonts:API]', fontsToLoad.length, '/', document.fonts.size);
const fontsToBeLoaded = [];
for (const fontToLoad of fontsToLoad) {
if (fontToLoad instanceof FontFace) {
if (!document.fonts.has(fontT... | Eagerly load fonts using `FontFaceSet` API.
@param {FontFaceReference[]} fontsToLoad
@param {boolean} [debug]
@returns {Promise} | loadFontsWithAPI | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function trim(value) {
return value.replace(/['"]+/g, '');
} | Removes quotes from the the string.
When a `@font-face` is declared, the font family is sometimes
defined in quotes which end up included in the `FontFace` instance.
@param {string} value
@returns {string} | trim | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
async function whenReady(queries)
{
const fonts = getMany(queries);
return await Promise.all(fonts.map((font) => font.loaded));
} | Returns a Promise that resolves with the specified fonts
when they are done loading or failed.
@param {FontFaceReference|string|(FontFaceReference|string)[]} queries
@returns {Promise} | whenReady | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/fonts.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/fonts.js | MIT |
function setGridHelperStyles($container, gutterCssVar, marginCssVar) {
const elStyles = $container.style;
elStyles.zIndex = '10000';
elStyles.position = 'fixed';
elStyles.top = '0';
elStyles.left = '0';
elStyles.display = 'flex';
elStyles.width = '100%';
elStyles.height = '100%';
elS... | Set grid container styles
@param {HTMLElement} $container - DOM Element that contains a list of generated columns
@param {string} gutterCssVar - CSS variable used to define grid gutters.
@param {string} marginCssVar - CSS variable used to define grid margins. | setGridHelperStyles | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/grid-helper.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/grid-helper.js | MIT |
function setGridHelperColumns($container, rgbaColor) {
// Clear columns
$container.innerHTML = '';
// Loop through columns
const columns = Number(
window.getComputedStyle($container).getPropertyValue('--grid-columns')
);
let $col;
for (var i = 0; i < columns; i++) {
$col = ... | Set grid columns
@param {HTMLElement} $container - DOM Element that will contain a list of generated columns
@param {string} rgbaColor - RGBA color to stylize the generated columns | setGridHelperColumns | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/grid-helper.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/grid-helper.js | MIT |
function setGridEvents($container, rgbaColor) {
// Handle resize
window.addEventListener(
'resize',
setGridHelperColumns($container, rgbaColor)
);
// Toggle grid
let ctrlDown = false;
let isActive = false;
document.addEventListener('keydown', (e) => {
if (e.key == '... | Set grid events
Resize to rebuild columns
Keydown/Keyup to toggle the grid display
@param {HTMLElement} $container - DOM Element that contains a list of generated columns
@param {string} rgbaColor - RGBA color to stylize the generated columns | setGridEvents | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/grid-helper.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/grid-helper.js | MIT |
escapeHtml = str =>
str.replace(/[&<>'"]/g, tag => ({
'&': '&',
'<': '<',
'>': '>',
"'": ''',
'"': '"'
}[tag])) | Escape HTML string
@param {string} str - string to escape
@return {string} escaped string | escapeHtml | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
escapeHtml = str =>
str.replace(/[&<>'"]/g, tag => ({
'&': '&',
'<': '<',
'>': '>',
"'": ''',
'"': '"'
}[tag])) | Escape HTML string
@param {string} str - string to escape
@return {string} escaped string | escapeHtml | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
unescapeHtml = str =>
str.replace('&', '&')
.replace('<', '<')
.replace('>', '>')
.replace(''', "'")
.replace('"', '"') | Unescape HTML string
@param {string} str - string to unescape
@return {string} unescaped string | unescapeHtml | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
unescapeHtml = str =>
str.replace('&', '&')
.replace('<', '<')
.replace('>', '>')
.replace(''', "'")
.replace('"', '"') | Unescape HTML string
@param {string} str - string to unescape
@return {string} unescaped string | unescapeHtml | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getNodeData = node => {
// All attributes
const attributes = node.attributes
// Regex Pattern
const pattern = /^data\-(.+)$/
// Output
const data = {}
for (let i in attributes) {
if (!attributes[i]) {
continue
}
// Attributes name (ex: data-module)
... | Get element data attributes
@param {HTMLElement} node - node element
@return {array} node data | getNodeData | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getNodeData = node => {
// All attributes
const attributes = node.attributes
// Regex Pattern
const pattern = /^data\-(.+)$/
// Output
const data = {}
for (let i in attributes) {
if (!attributes[i]) {
continue
}
// Attributes name (ex: data-module)
... | Get element data attributes
@param {HTMLElement} node - node element
@return {array} node data | getNodeData | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getData = data => {
if (data === 'true') {
return true
}
if (data === 'false') {
return false
}
if (data === 'null') {
return null
}
// Only convert to a number if it doesn't change the string
if (data === +data+'') {
return +data
}
if (rbrace.... | Parse value to data type.
@link https://github.com/jquery/jquery/blob/3.1.1/src/data.js
@param {string} data - value to convert
@return {mixed} value in its natural data type | getData | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getData = data => {
if (data === 'true') {
return true
}
if (data === 'false') {
return false
}
if (data === 'null') {
return null
}
// Only convert to a number if it doesn't change the string
if (data === +data+'') {
return +data
}
if (rbrace.... | Parse value to data type.
@link https://github.com/jquery/jquery/blob/3.1.1/src/data.js
@param {string} data - value to convert
@return {mixed} value in its natural data type | getData | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getParents = $el => {
// Set up a parent array
let parents = []
// Push each parent element to the array
for (; $el && $el !== document; $el = $el.parentNode) {
parents.push($el)
}
// Return our parent array
return parents
} | Returns an array containing all the parent nodes of the given node
@param {HTMLElement} $el - DOM Element
@return {array} parent nodes | getParents | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getParents = $el => {
// Set up a parent array
let parents = []
// Push each parent element to the array
for (; $el && $el !== document; $el = $el.parentNode) {
parents.push($el)
}
// Return our parent array
return parents
} | Returns an array containing all the parent nodes of the given node
@param {HTMLElement} $el - DOM Element
@return {array} parent nodes | getParents | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/html.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/html.js | MIT |
getImageMetadata = $img => ({
url: $img.src,
width: $img.naturalWidth,
height: $img.naturalHeight,
ratio: $img.naturalWidth / $img.naturalHeight,
}) | Get an image meta data
@param {HTMLImageElement} $img - The image element.
@return {object} The given image meta data | getImageMetadata | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
getImageMetadata = $img => ({
url: $img.src,
width: $img.naturalWidth,
height: $img.naturalHeight,
ratio: $img.naturalWidth / $img.naturalHeight,
}) | Get an image meta data
@param {HTMLImageElement} $img - The image element.
@return {object} The given image meta data | getImageMetadata | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
loadImage = (url, options = {}) => {
return new Promise((resolve, reject) => {
const $img = new Image()
if (options.crossOrigin) {
$img.crossOrigin = options.crossOrigin
}
const loadCallback = () => {
resolve({
element: $img,
... | Load the given image.
@param {string} url - The URI to lazy load into $el.
@param {object} options - An object of options
@return {void} | loadImage | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
loadImage = (url, options = {}) => {
return new Promise((resolve, reject) => {
const $img = new Image()
if (options.crossOrigin) {
$img.crossOrigin = options.crossOrigin
}
const loadCallback = () => {
resolve({
element: $img,
... | Load the given image.
@param {string} url - The URI to lazy load into $el.
@param {object} options - An object of options
@return {void} | loadImage | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
loadCallback = () => {
resolve({
element: $img,
...getImageMetadata($img),
})
} | Load the given image.
@param {string} url - The URI to lazy load into $el.
@param {object} options - An object of options
@return {void} | loadCallback | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
loadCallback = () => {
resolve({
element: $img,
...getImageMetadata($img),
})
} | Load the given image.
@param {string} url - The URI to lazy load into $el.
@param {object} options - An object of options
@return {void} | loadCallback | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
lazyLoadImage = async ($el, url, callback) => {
let src = url ? url : $el.dataset.src
let loadedImage = LAZY_LOADED_IMAGES.find(image => image.url === src)
if (!loadedImage) {
loadedImage = await loadImage(src)
if (!loadedImage.url) {
return
}
LAZY_LOADED_IMAG... | Lazy load the given image.
@param {HTMLImageElement} $el - The image element.
@param {?string} url - The URI to lazy load into $el.
If falsey, the value of the `data-src` attribute on $el will be used as the URI.
@param {?function} callback - A function to call when the image is ... | lazyLoadImage | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
lazyLoadImage = async ($el, url, callback) => {
let src = url ? url : $el.dataset.src
let loadedImage = LAZY_LOADED_IMAGES.find(image => image.url === src)
if (!loadedImage) {
loadedImage = await loadImage(src)
if (!loadedImage.url) {
return
}
LAZY_LOADED_IMAG... | Lazy load the given image.
@param {HTMLImageElement} $el - The image element.
@param {?string} url - The URI to lazy load into $el.
If falsey, the value of the `data-src` attribute on $el will be used as the URI.
@param {?function} callback - A function to call when the image is ... | lazyLoadImage | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/image.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/image.js | MIT |
roundNumber = (number, precision = 2) => {
return Number.parseFloat(number.toPrecision(precision));
} | Round number to the specified precision.
This function is necessary because `Number.prototype.toPrecision()`
and `Number.prototype.toFixed()`
@param {number} number - The floating point number to round.
@param {number} [precision] - The number of digits to appear after the decimal point.
@return {number} The... | roundNumber | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/maths.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/maths.js | MIT |
roundNumber = (number, precision = 2) => {
return Number.parseFloat(number.toPrecision(precision));
} | Round number to the specified precision.
This function is necessary because `Number.prototype.toPrecision()`
and `Number.prototype.toFixed()`
@param {number} number - The floating point number to round.
@param {number} [precision] - The number of digits to appear after the decimal point.
@return {number} The... | roundNumber | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/maths.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/maths.js | MIT |
debounce = (callback, delay, immediate = false) => {
let timeout = null
return (...args) => {
clearTimeout(timeout)
const later = () => {
timeout = null
if (!immediate) {
callback(...args)
}
}
if (immediate && !timeout) {
... | Creates a debounced function.
A debounced function delays invoking `callback` until after
`delay` milliseconds have elapsed since the last time the
debounced function was invoked.
Useful for behaviour that should only happen _before_ or
_after_ an event has stopped occurring.
@template {function} T
@param {T} ... | debounce | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/tickers.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/tickers.js | MIT |
debounce = (callback, delay, immediate = false) => {
let timeout = null
return (...args) => {
clearTimeout(timeout)
const later = () => {
timeout = null
if (!immediate) {
callback(...args)
}
}
if (immediate && !timeout) {
... | Creates a debounced function.
A debounced function delays invoking `callback` until after
`delay` milliseconds have elapsed since the last time the
debounced function was invoked.
Useful for behaviour that should only happen _before_ or
_after_ an event has stopped occurring.
@template {function} T
@param {T} ... | debounce | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/tickers.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/tickers.js | MIT |
later = () => {
timeout = null
if (!immediate) {
callback(...args)
}
} | Creates a debounced function.
A debounced function delays invoking `callback` until after
`delay` milliseconds have elapsed since the last time the
debounced function was invoked.
Useful for behaviour that should only happen _before_ or
_after_ an event has stopped occurring.
@template {function} T
@param {T} ... | later | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/tickers.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/tickers.js | MIT |
later = () => {
timeout = null
if (!immediate) {
callback(...args)
}
} | Creates a debounced function.
A debounced function delays invoking `callback` until after
`delay` milliseconds have elapsed since the last time the
debounced function was invoked.
Useful for behaviour that should only happen _before_ or
_after_ an event has stopped occurring.
@template {function} T
@param {T} ... | later | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/tickers.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/tickers.js | MIT |
getTranslate = $el => {
if(!window.getComputedStyle) {
return
}
let translate
const style = getComputedStyle($el)
const transform = style.msTransform || style.webkitTransform || style.MozTransform || style.OTransform || style.transform
const matrix3D = transform.match(/^matrix3d\((.+)... | Get translate function
@param {HTMLElement} $el - DOM Element
@return {number|object} translate value | getTranslate | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/transform.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/transform.js | MIT |
getTranslate = $el => {
if(!window.getComputedStyle) {
return
}
let translate
const style = getComputedStyle($el)
const transform = style.msTransform || style.webkitTransform || style.MozTransform || style.OTransform || style.transform
const matrix3D = transform.match(/^matrix3d\((.+)... | Get translate function
@param {HTMLElement} $el - DOM Element
@return {number|object} translate value | getTranslate | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/transform.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/transform.js | MIT |
get isEnabled() {
return isVisibilityChangeObserved;
} | Checks if the "visibilitychange" event listener has been registered.
@return {boolean} Returns `false` if the event listener is not registered,
otherwise returns `true`. | isEnabled | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/visibility.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/visibility.js | MIT |
disableCustomEvents() {
if (isVisibilityChangeObserved) {
isVisibilityChangeObserved = false;
document.removeEventListener('visibilitychange', handleCustomVisibilityChange);
return true;
}
return false;
} | Removes the "visibilitychange" event listener.
@return {boolean} Returns `false` if the event listener was already unregistered,
otherwise returns `true`. | disableCustomEvents | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/visibility.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/visibility.js | MIT |
enableCustomEvents() {
if (!isVisibilityChangeObserved) {
isVisibilityChangeObserved = true;
document.addEventListener('visibilitychange', handleCustomVisibilityChange);
return true;
}
return false;
} | Registers the "visibilitychange" event listener.
@return {boolean} Returns `false` if the event listener was already registered,
otherwise returns `true`. | enableCustomEvents | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/visibility.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/visibility.js | MIT |
function handleCustomVisibilityChange(event) {
document.dispatchEvent(new CustomEvent(`visibility${document.visibilityState}`, {
detail: {
cause: event
}
}));
} | Dispatches a custom visibility event at the document derived
from the value of {@see document.visibilityState}.
@listens document#visibilitychange
@fires PageVisibility#visibilityhidden
@fires PageVisibility#visibilityvisible
@param {Event} event
@return {void} | handleCustomVisibilityChange | javascript | locomotivemtl/locomotive-boilerplate | assets/scripts/utils/visibility.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/assets/scripts/utils/visibility.js | MIT |
function configureServer(server, { paths, tasks }) {
const views = createViewsArray(paths.views);
// Reload on any changes to views or processed files
server.watch(
[
...views,
join(paths.scripts.dest, '*.js'),
join(paths.styles.dest, '*.css'),
join(p... | Configures the BrowserSync options.
@param {BrowserSync} server - The BrowserSync API.
@param {object} loconfig - The project configset.
@param {object} loconfig.paths - The paths options.
@param {object} loconfig.tasks - The tasks options.
@return {void} | configureServer | javascript | locomotivemtl/locomotive-boilerplate | build/watch.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/watch.js | MIT |
function createServerOptions({
paths,
server: options
}) {
const config = {
open: false,
notify: false,
ghostMode: false
};
// Resolve the URL for the BrowserSync server
if (isNonEmptyString(paths.url)) {
// Use proxy
config.proxy = paths.url;
} else ... | Creates a new object with all the BrowserSync options.
@param {object} loconfig - The project configset.
@param {object} loconfig.paths - The paths options.
@param {object} loconfig.server - The server options.
@return {object} Returns the server options. | createServerOptions | javascript | locomotivemtl/locomotive-boilerplate | build/watch.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/watch.js | MIT |
function createViewsArray(views) {
if (Array.isArray(views)) {
return Array.from(views);
}
switch (typeof views) {
case 'string':
return [ views ];
case 'object':
if (views != null) {
return Object.values(views);
}
}
thro... | Creates a new array (shallow-copied) from the views configset.
@param {*} views - The views configset.
@throws {TypeError} If views is invalid.
@return {array} Returns the views array. | createViewsArray | javascript | locomotivemtl/locomotive-boilerplate | build/watch.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/watch.js | MIT |
function prependSchemeToUrl(url, scheme = 'http') {
if (regexUrlStartsWithProtocol.test(url)) {
return url.replace(regexUrlStartsWithProtocol, `${scheme}://`);
}
return `${scheme}://${url}`;
} | Prepends the scheme to the URL.
@param {string} url - The URL to mutate.
@param {string} [scheme] - The URL scheme to prepend.
@return {string} Returns the mutated URL. | prependSchemeToUrl | javascript | locomotivemtl/locomotive-boilerplate | build/watch.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/watch.js | MIT |
function isNonEmptyString(value) {
return (typeof value === 'string' && value.length > 0);
} | Determines whether the passed value is a string with at least one character.
@param {*} value - The value to be checked.
@return {boolean} Returns `true` if the value is a non-empty string,
otherwise `false`. | isNonEmptyString | javascript | locomotivemtl/locomotive-boilerplate | build/watch.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/watch.js | MIT |
async function importGlob() {
for (let name of candidates) {
try {
let globModule = await import(name);
if (typeof globModule.default !== 'function') {
throw new TypeError(`Expected ${name} to be a function`);
}
/**
* Wrap the fu... | Imports the first available glob function.
@throws {TypeError} If no glob library was found.
@returns {GlobFn} | importGlob | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/glob.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/glob.js | MIT |
function createArrayableGlob(globFn) {
return (patterns, options) => {
/** [2] If `patterns` is a string, wraps into an array. */
patterns = [].concat(patterns);
const globs = patterns.map((pattern) => globFn(pattern, options));
return Promise.all(globs).then((files) => {
... | Creates a wrapper function for the glob function
to provide support for arrays of patterns.
@param {function} globFn - The glob function.
@returns {GlobFn} | createArrayableGlob | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/glob.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/glob.js | MIT |
function createPresetGlob(globFn, presets) {
return (patterns, options) => globFn(patterns, Object.assign({}, presets, options));
} | Creates a wrapper function for the glob function
to define new default options.
@param {function} globFn - The glob function.
@param {GlobOptions} presets - The glob function options to preset.
@returns {GlobFn} | createPresetGlob | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/glob.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/glob.js | MIT |
function notification(options, callback) {
if (typeof options === 'string') {
options = {
message: options
};
} else if (!options.title && !options.message) {
throw new TypeError(
'Notification expects at least a \'message\' parameter'
);
}
if (ty... | Sends a cross-platform native notification.
Wraps around node-notifier to assign default values.
@param {string|object} options - The notification options or a message.
@param {string} options.title - The notification title.
@param {string} options.message - The notification message.
@param... | notification | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/notification.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/notification.js | MIT |
function createProcessor(pluginsListOrMap, options)
{
if (!postcss) {
return null;
}
const plugins = parsePlugins(pluginsListOrMap, options);
return postcss(plugins);
} | Attempts to create a PostCSS Processor with the given plugins and options.
@param {PluginCollection} pluginsListOrMap - A list or map of plugins.
If a map of plugins, the plugin name looks up `options`.
@param {PostCSSOptions} options - The PostCSS wrapper options.
@returns {Processor|null} | createProcessor | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/postcss.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/postcss.js | MIT |
function parsePlugins(pluginsListOrMap, options)
{
if (Array.isArray(pluginsListOrMap)) {
return pluginsListOrMap;
}
/** @type {PluginList} */
const plugins = [];
for (let [ name, plugin ] of Object.entries(pluginsListOrMap)) {
if (name in options) {
plugin = plugin[nam... | Parses the PostCSS plugins and options.
@param {PluginCollection} pluginsListOrMap - A list or map of plugins.
If a map of plugins, the plugin name looks up `options`.
@param {PostCSSOptions} options - The PostCSS wrapper options.
@returns {PluginList} | parsePlugins | javascript | locomotivemtl/locomotive-boilerplate | build/helpers/postcss.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/helpers/postcss.js | MIT |
async function purgeUnusedCSS(outfile, label) {
const contentFiles = loconfig.tasks.purgeCSS?.content;
if (!Array.isArray(contentFiles) || !contentFiles.length) {
return;
}
label = label ?? basename(outfile);
const timeLabel = `${label} purged in`;
console.time(timeLabel);
const p... | Purge unused styles from CSS files.
@async
@param {string} outfile - The path of a css file
If missing the function stops.
@param {string} label - The CSS file label or name.
@return {Promise} | purgeUnusedCSS | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/styles.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/styles.js | MIT |
async function bumpVersions(versionOptions = null) {
if (versionOptions == null) {
versionOptions = productionVersionOptions;
} else if (
versionOptions !== developmentVersionOptions &&
versionOptions !== productionVersionOptions
) {
versionOptions = merge({}, defaultVersionO... | Bumps version numbers in file.
@async
@param {object} [versionOptions=null] - Customize the version options.
If `null`, default production options are used.
@return {Promise} | bumpVersions | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
function createVersionNumber(format, oldValue = null) {
let [ type, modifier ] = format.split(':', 2);
switch (type) {
case 'hex':
case 'hexadecimal':
try {
modifier = Number.parseInt(modifier);
if (Number.isNaN(modifier)) {
modif... | Creates a formatted version number or string.
@param {string} format - The version format.
@param {?string} [oldValue] - The old version value.
@return {string|number}
@throws TypeError If the format or value are invalid. | createVersionNumber | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
async function handleBumpVersionInJson(outfile, label, options) {
outfile = resolve(outfile);
let json;
try {
json = JSON.parse(await readFile(outfile, { encoding: 'utf8' }));
} catch (err) {
json = {};
message(`${label} is a new file`, 'notice');
await mkdir(dirname(... | Changes the version number for the provided JSON key in file.
@async
@param {string} outfile
@param {string} label
@param {object} options
@param {string} options.key
@return {Promise} | handleBumpVersionInJson | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
async function handleBumpVersionWithRegExp(outfile, label, options) {
outfile = resolve(outfile);
const bckfile = `${outfile}~`;
await rename(outfile, bckfile);
try {
const rl = readline.createInterface({
input: createReadStream(bckfile),
});
let newVersion = null... | Changes the version number for the provided RegExp in file.
@async
@param {string} outfile
@param {string} label
@param {object} options
@param {RegExp} options.key
@return {Promise} | handleBumpVersionWithRegExp | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
function incrementNumber(value, increment = 1) {
const version = Number.parseInt(value);
if (Number.isNaN(version)) {
throw new TypeError(
`Expected an integer version number, received [${value}]`
);
}
increment = Number.parseInt(increment);
if (Number.isNaN(increment)) ... | Increments the given integer.
@param {string|int} value - The number to increment.
@param {string|int} [increment=1] - The amount to increment by.
@return {int}
@throws TypeError If the version number is invalid. | incrementNumber | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
function incrementSemVer(value, target = 'patch', increment = 1) {
const found = value.match(REGEXP_SEMVER);
if (!found) {
throw new TypeError(
`Expected a SemVer version number, received [${value}]`
);
}
if (Array.isArray(target)) {
for (const group of target) {
... | Increments the given SemVer version number.
@param {string} value - The version to mutate.
@param {string|string[]} [target] - The segment to increment, one of:
'major', 'minor', 'patch', ~~'prerelease'~~, 'buildmetadata'.
@param {string|int} [increment=1] - The amount to increment by.
@retur... | incrementSemVer | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
function parseVersionKey(key) {
if (key instanceof RegExp) {
return key;
}
if (typeof key !== 'string') {
throw new TypeError(
'Expected \'key\' to be either a string or a RegExp'
);
}
const delimiter = key.indexOf(':');
if (delimiter === -1) {
// A... | Parses the version key.
@param {*} key - The version key.
@return {string|RegExp} | parseVersionKey | javascript | locomotivemtl/locomotive-boilerplate | build/tasks/versions.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/tasks/versions.js | MIT |
function escapeRegExp(str) {
return str.replace(regexUnescaped, '\\$&');
} | Quotes regular expression characters.
@param {string} str - The input string.
@return {string} Returns the quoted (escaped) string. | escapeRegExp | javascript | locomotivemtl/locomotive-boilerplate | build/utils/index.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/utils/index.js | MIT |
function flatten(input, prefix, target = {}) {
for (const key in input) {
const field = (prefix ? prefix + '.' + key : key);
if (isObjectLike(input[key])) {
flatten(input[key], field, target);
} else {
target[field] = input[key];
}
}
return target;
} | Creates a new object with all nested object properties
concatenated into it recursively.
Nested keys are flattened into a property path:
```js
{
a: {
b: {
c: 1
}
},
d: 1
}
```
```js
{
"a.b.c": 1,
"d": 1
}
```
@param {object} input - The object to flatten.
@param {string} prefix - The pare... | flatten | javascript | locomotivemtl/locomotive-boilerplate | build/utils/index.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/utils/index.js | MIT |
function isObjectLike(value) {
return (value != null && typeof value === 'object');
} | Determines whether the passed value is an `Object`.
@param {*} value - The value to be checked.
@return {boolean} Returns `true` if the value is an `Object`,
otherwise `false`. | isObjectLike | javascript | locomotivemtl/locomotive-boilerplate | build/utils/index.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/utils/index.js | MIT |
function merge(target, ...sources) {
for (const source of sources) {
if (target === source) {
throw new TypeError(
'Cannot merge, target and source are the same'
);
}
for (const key in source) {
if (source[key] != null) {
i... | Creates a new object with all nested object properties
merged into it recursively.
@param {object} target - The target object.
@param {object[]} ...sources - The source object(s).
@throws {TypeError} If the target and source are the same.
@return {object} Returns the `target` object. | merge | javascript | locomotivemtl/locomotive-boilerplate | build/utils/index.js | https://github.com/locomotivemtl/locomotive-boilerplate/blob/master/build/utils/index.js | MIT |
on() {
activeEffectScope = this;
} | This should only be called on non-detached scopes
@internal | on | javascript | icai/vue3-calendar | lib/calendar.js | https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js | MIT |
off() {
activeEffectScope = this.parent;
} | This should only be called on non-detached scopes
@internal | off | javascript | icai/vue3-calendar | lib/calendar.js | https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js | MIT |
stop(fromParent) {
if (this._active) {
let i, l;
for (i = 0, l = this.effects.length; i < l; i++) {
this.effects[i].stop();
}
for (i = 0, l = this.cleanups.length; i < l; i++) {
this.cleanups[i]();
}
if (this.scopes) {
for (i = 0, l = this.scopes.length; i... | This should only be called on non-detached scopes
@internal | stop | javascript | icai/vue3-calendar | lib/calendar.js | https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js | MIT |
function effectScope(detached) {
return new EffectScope(detached);
} | This should only be called on non-detached scopes
@internal | effectScope | javascript | icai/vue3-calendar | lib/calendar.js | https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js | MIT |
function recordEffectScope(effect, scope = activeEffectScope) {
if (scope && scope.active) {
scope.effects.push(effect);
}
} | This should only be called on non-detached scopes
@internal | recordEffectScope | javascript | icai/vue3-calendar | lib/calendar.js | https://github.com/icai/vue3-calendar/blob/master/lib/calendar.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.