mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
Comments
This commit is contained in:
@ -1,18 +1,36 @@
|
|||||||
|
// Simple noop function
|
||||||
export function noop() {};
|
export function noop() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a min and max, restrict the given number
|
||||||
|
* to the range.
|
||||||
|
* @param min the minimum
|
||||||
|
* @param n the value
|
||||||
|
* @param max the maximum
|
||||||
|
*/
|
||||||
export function clamp(min, n, max) {
|
export function clamp(min, n, max) {
|
||||||
return Math.max(min, Math.min(n, max));
|
return Math.max(min, Math.min(n, max));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend the destination with an arbitrary number of other objects.
|
||||||
|
* @param dst the destination
|
||||||
|
* @param ... the param objects
|
||||||
|
*/
|
||||||
export function extend(dst) {
|
export function extend(dst) {
|
||||||
return baseExtend(dst, [].slice.call(arguments, 1), false);
|
return _baseExtend(dst, [].slice.call(arguments, 1), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do a deep extend (merge).
|
||||||
|
* @param dst the destination
|
||||||
|
* @param ... the param objects
|
||||||
|
*/
|
||||||
export function merge(dst) {
|
export function merge(dst) {
|
||||||
return baseExtend(dst, [].slice.call(arguments, 1), true);
|
return _baseExtend(dst, [].slice.call(arguments, 1), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function baseExtend(dst, objs, deep) {
|
function _baseExtend(dst, objs, deep) {
|
||||||
for (var i = 0, ii = objs.length; i < ii; ++i) {
|
for (var i = 0, ii = objs.length; i < ii; ++i) {
|
||||||
var obj = objs[i];
|
var obj = objs[i];
|
||||||
if (!isObject(obj) && !isFunction(obj)) continue;
|
if (!isObject(obj) && !isFunction(obj)) continue;
|
||||||
@ -23,7 +41,7 @@ function baseExtend(dst, objs, deep) {
|
|||||||
|
|
||||||
if (deep && isObject(src)) {
|
if (deep && isObject(src)) {
|
||||||
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
|
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
|
||||||
baseExtend(dst[key], [src], true);
|
_baseExtend(dst[key], [src], true);
|
||||||
} else {
|
} else {
|
||||||
dst[key] = src;
|
dst[key] = src;
|
||||||
}
|
}
|
||||||
@ -33,6 +51,11 @@ function baseExtend(dst, objs, deep) {
|
|||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply default arguments if they don't exist in
|
||||||
|
* the first object.
|
||||||
|
* @param the destination to apply defaults to.
|
||||||
|
*/
|
||||||
export function defaults(dest) {
|
export function defaults(dest) {
|
||||||
for (let i = arguments.length - 1; i >= 1; i--) {
|
for (let i = arguments.length - 1; i >= 1; i--) {
|
||||||
let source = arguments[i] || {};
|
let source = arguments[i] || {};
|
||||||
@ -52,6 +75,9 @@ export const isUndefined = val => typeof val === 'undefined'
|
|||||||
export const isObject = val => typeof val === 'object'
|
export const isObject = val => typeof val === 'object'
|
||||||
export const isArray = Array.isArray
|
export const isArray = Array.isArray
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a string in the format thisIsAString to a slug format this-is-a-string
|
||||||
|
*/
|
||||||
export function pascalCaseToDashCase(str = '') {
|
export function pascalCaseToDashCase(str = '') {
|
||||||
return str.charAt(0).toLowerCase() + str.substring(1).replace(/[A-Z]/g, match => {
|
return str.charAt(0).toLowerCase() + str.substring(1).replace(/[A-Z]/g, match => {
|
||||||
return '-' + match.toLowerCase();
|
return '-' + match.toLowerCase();
|
||||||
@ -63,6 +89,9 @@ export function nextUid() {
|
|||||||
return ++uid;
|
return ++uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple logger class.
|
||||||
|
*/
|
||||||
export class Log {
|
export class Log {
|
||||||
static log(...args) {
|
static log(...args) {
|
||||||
console.log.apply(console, args);
|
console.log.apply(console, args);
|
||||||
@ -94,6 +123,10 @@ export let array = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grab the query string param value for the given key.
|
||||||
|
* @param key the key to look for
|
||||||
|
*/
|
||||||
export function getQuerystring(key) {
|
export function getQuerystring(key) {
|
||||||
var queryParams = {};
|
var queryParams = {};
|
||||||
const startIndex = window.location.href.indexOf('?');
|
const startIndex = window.location.href.indexOf('?');
|
||||||
|
Reference in New Issue
Block a user