@daybrush/utils
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -17,2 +17,4 @@ export interface IObject<T> { | ||
export declare const IS_WINDOW: boolean; | ||
declare const doc: Document; | ||
export { doc as document }; | ||
export declare const getCrossBrowserProperty: (property: string) => string; | ||
@@ -19,0 +21,0 @@ export declare const TRANSFORM: string; |
export * from "./consts"; | ||
export * from "./color"; | ||
export * from "./utils"; | ||
export * from "./css"; | ||
export * from "./dom"; |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.4.2 | ||
@version 0.5.0 | ||
*/ | ||
@@ -145,2 +145,14 @@ /** | ||
var IS_WINDOW = typeof window !== UNDEFINED; | ||
/** | ||
* Check whether the environment is window or node.js. | ||
* @memberof Consts | ||
* @name document | ||
* @example | ||
import {IS_WINDOW} from "@daybrush/utils"; | ||
console.log(IS_WINDOW); // false in node.js | ||
console.log(IS_WINDOW); // true in browser | ||
*/ | ||
var doc = typeof document !== UNDEFINED && document; | ||
var prefixes = ["webkit", "ms", "moz", "o"]; | ||
@@ -167,7 +179,7 @@ /** | ||
function (property) { | ||
if (typeof document === UNDEFINED) { | ||
if (!doc) { | ||
return ""; | ||
} | ||
var styles = (document.body || document.documentElement).style; | ||
var styles = (doc.body || doc.documentElement).style; | ||
var length = prefixes.length; | ||
@@ -686,5 +698,16 @@ | ||
/** | ||
* @namespace DOM | ||
*/ | ||
* Checks if the specified class value exists in the element's class attribute. | ||
* @memberof DOM | ||
* @param - A DOMString containing one or more selectors to match | ||
* @param - If multi is true, a DOMString containing one or more selectors to match against. | ||
* @example | ||
import {$} from "@daybrush/utils"; | ||
console.log($("div")); // div element | ||
console.log($("div", true)); // [div, div] elements | ||
*/ | ||
function $(selector, multi) { | ||
return multi ? doc.querySelectorAll(selector) : doc.querySelector(selector); | ||
} | ||
/** | ||
@@ -701,2 +724,3 @@ * Checks if the specified class value exists in the element's class attribute. | ||
*/ | ||
function hasClass(element, className) { | ||
@@ -784,3 +808,3 @@ if (element.classList) { | ||
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, now, requestAnimationFrame, hasClass, addClass, removeClass, fromCSS }; | ||
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, now, requestAnimationFrame, $, hasClass, addClass, removeClass, fromCSS }; | ||
//# sourceMappingURL=utils.esm.js.map |
@@ -7,3 +7,3 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.4.2 | ||
@version 0.5.0 | ||
*/ | ||
@@ -151,2 +151,14 @@ (function (global, factory) { | ||
var IS_WINDOW = typeof window !== UNDEFINED; | ||
/** | ||
* Check whether the environment is window or node.js. | ||
* @memberof Consts | ||
* @name document | ||
* @example | ||
import {IS_WINDOW} from "@daybrush/utils"; | ||
console.log(IS_WINDOW); // false in node.js | ||
console.log(IS_WINDOW); // true in browser | ||
*/ | ||
var doc = typeof document !== UNDEFINED && document; | ||
var prefixes = ["webkit", "ms", "moz", "o"]; | ||
@@ -173,7 +185,7 @@ /** | ||
function (property) { | ||
if (typeof document === UNDEFINED) { | ||
if (!doc) { | ||
return ""; | ||
} | ||
var styles = (document.body || document.documentElement).style; | ||
var styles = (doc.body || doc.documentElement).style; | ||
var length = prefixes.length; | ||
@@ -692,5 +704,16 @@ | ||
/** | ||
* @namespace DOM | ||
*/ | ||
* Checks if the specified class value exists in the element's class attribute. | ||
* @memberof DOM | ||
* @param - A DOMString containing one or more selectors to match | ||
* @param - If multi is true, a DOMString containing one or more selectors to match against. | ||
* @example | ||
import {$} from "@daybrush/utils"; | ||
console.log($("div")); // div element | ||
console.log($("div", true)); // [div, div] elements | ||
*/ | ||
function $(selector, multi) { | ||
return multi ? doc.querySelectorAll(selector) : doc.querySelector(selector); | ||
} | ||
/** | ||
@@ -707,2 +730,3 @@ * Checks if the specified class value exists in the element's class attribute. | ||
*/ | ||
function hasClass(element, className) { | ||
@@ -806,2 +830,3 @@ if (element.classList) { | ||
IS_WINDOW: IS_WINDOW, | ||
document: doc, | ||
getCrossBrowserProperty: getCrossBrowserProperty, | ||
@@ -830,2 +855,3 @@ TRANSFORM: TRANSFORM, | ||
requestAnimationFrame: requestAnimationFrame, | ||
$: $, | ||
hasClass: hasClass, | ||
@@ -832,0 +858,0 @@ addClass: addClass, |
@@ -7,5 +7,5 @@ /* | ||
repository: https://github.com/daybrush/utils | ||
@version 0.4.2 | ||
@version 0.5.0 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.utils=t()}(this,function(){"use strict";var u="rgb",c="rgba",f="hsl",l="hsla",e=[u,c,f,l],t="function",n="object",r="string",i="undefined",a=typeof window!==i,o=["webkit","ms","moz","o"],s=function(e){if(typeof document===i)return"";var t=(document.body||document.documentElement).style,n=o.length;if(typeof t[e]!==i)return e;for(var r=0;r<n;++r){var a="-"+o[r]+"-"+e;if(typeof t[a]!==i)return a}return""},m=s("transform"),p=s("filter"),d=s("animation"),h=d.replace("animation","keyframes");function g(e){var t=e.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return t?t.map(function(e){return e.trim()}):[]}function v(e){var t=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(e);return!t||t.length<4?{}:{prefix:t[1],value:t[2],suffix:t[3]}}function w(){return Date.now?Date.now():(new Date).getTime()}var A=function(){var n=w(),e=a&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame);return e?e.bind(window):function(e){var t=w();return window.setTimeout(function(){e(t-n)},1e3/60)}}();function y(e){return e.replace("#","")}function R(e){var t=y(e),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),a=parseInt(t.substring(4,6),16),i=parseInt(t.substring(6,8),16)/255;return isNaN(i)&&(i=1),[n,r,a,i]}function N(e){var t=e.charAt(1),n=e.charAt(2),r=e.charAt(3),a=e.charAt(4);return["#",t,t,n,n,r,r,a,a].join("")}function b(e){var t=e[0],n=e[1],r=e[2];t<0&&(t+=360*Math.floor((Math.abs(t)+360)/360)),t%=360;var a,i=(1-Math.abs(2*r-1))*n,o=i*(1-Math.abs(t/60%2-1)),s=r-i/2;return t<60?a=[i,o,0]:t<120?a=[o,i,0]:t<180?a=[0,i,o]:t<240?a=[0,o,i]:t<300?a=[o,0,i]:t<360&&(a=[i,0,o]),[Math.round(255*(a[0]+s)),Math.round(255*(a[1]+s)),Math.round(255*(a[2]+s)),3<e.length?e[3]:1]}return{RGB:u,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:e,FUNCTION:t,PROPERTY:"property",ARRAY:"array",OBJECT:n,STRING:r,NUMBER:"number",UNDEFINED:i,IS_WINDOW:a,getCrossBrowserProperty:s,TRANSFORM:m,FILTER:p,ANIMATION:d,KEYFRAMES:h,cutHex:y,hexToRGBA:R,toFullHex:N,hslToRGBA:b,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?R(N(e)):R(e);if(-1!==e.indexOf("(")){var t=v(e),n=t.prefix,r=t.value;if(!n||!r)return;var a=g(r),i=[],o=a.length;switch(n){case u:case c:for(var s=0;s<o;++s)i[s]=parseFloat(a[s]);return i;case f:case l:for(s=0;s<o;++s)-1!==a[s].indexOf("%")?i[s]=parseFloat(a[s])/100:i[s]=parseFloat(a[s]);return b(i)}}},isUndefined:function(e){return typeof e===i},isObject:function(e){return e&&typeof e===n},isArray:function(e){return Array.isArray(e)},isString:function(e){return typeof e===r},isFunction:function(e){return typeof e===t},splitSpace:function(e){return e.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:g,splitBracket:v,splitUnit:function(e){var t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(e);if(!t)return{prefix:"",unit:"",value:NaN};var n=t[1],r=t[2];return{prefix:n,unit:t[3],value:parseFloat(r)}},camelize:function(e){return e.replace(/[\s-_]([a-z])/g,function(e,t){return t.toUpperCase()})},decamelize:function(e,r){return void 0===r&&(r="-"),e.replace(/([a-z])([A-Z])/g,function(e,t,n){return""+t+r+n.toLowerCase()})},now:w,requestAnimationFrame:A,hasClass:function(e,t){return e.classList?e.classList.contains(t):!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){e.classList?e.classList.add(t):e.className+=" "+t},removeClass:function(e,t){if(e.classList)e.classList.remove(t);else{var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}},fromCSS:function(e,t){if(!e||!t||!t.length)return{};var n;if(e instanceof Element)n=e;else{if(!e.length)return{};n=e[0]}for(var r={},a=window.getComputedStyle(n),i=t.length,o=0;o<i;++o)r[t[o]]=a[t[o]];return r}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.utils=t()}(this,function(){"use strict";var u="rgb",c="rgba",f="hsl",l="hsla",e=[u,c,f,l],t="function",n="object",r="string",i="undefined",a=typeof window!==i,o=typeof document!==i&&document,s=["webkit","ms","moz","o"],m=function(e){if(!o)return"";var t=(o.body||o.documentElement).style,n=s.length;if(typeof t[e]!==i)return e;for(var r=0;r<n;++r){var a="-"+s[r]+"-"+e;if(typeof t[a]!==i)return a}return""},p=m("transform"),d=m("filter"),h=m("animation"),g=h.replace("animation","keyframes");function v(e){var t=e.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return t?t.map(function(e){return e.trim()}):[]}function w(e){var t=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(e);return!t||t.length<4?{}:{prefix:t[1],value:t[2],suffix:t[3]}}function A(){return Date.now?Date.now():(new Date).getTime()}var y=function(){var n=A(),e=a&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame);return e?e.bind(window):function(e){var t=A();return window.setTimeout(function(){e(t-n)},1e3/60)}}();function R(e){return e.replace("#","")}function N(e){var t=R(e),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),a=parseInt(t.substring(4,6),16),i=parseInt(t.substring(6,8),16)/255;return isNaN(i)&&(i=1),[n,r,a,i]}function S(e){var t=e.charAt(1),n=e.charAt(2),r=e.charAt(3),a=e.charAt(4);return["#",t,t,n,n,r,r,a,a].join("")}function b(e){var t=e[0],n=e[1],r=e[2];t<0&&(t+=360*Math.floor((Math.abs(t)+360)/360)),t%=360;var a,i=(1-Math.abs(2*r-1))*n,o=i*(1-Math.abs(t/60%2-1)),s=r-i/2;return t<60?a=[i,o,0]:t<120?a=[o,i,0]:t<180?a=[0,i,o]:t<240?a=[0,o,i]:t<300?a=[o,0,i]:t<360&&(a=[i,0,o]),[Math.round(255*(a[0]+s)),Math.round(255*(a[1]+s)),Math.round(255*(a[2]+s)),3<e.length?e[3]:1]}return{RGB:u,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:e,FUNCTION:t,PROPERTY:"property",ARRAY:"array",OBJECT:n,STRING:r,NUMBER:"number",UNDEFINED:i,IS_WINDOW:a,document:o,getCrossBrowserProperty:m,TRANSFORM:p,FILTER:d,ANIMATION:h,KEYFRAMES:g,cutHex:R,hexToRGBA:N,toFullHex:S,hslToRGBA:b,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?N(S(e)):N(e);if(-1!==e.indexOf("(")){var t=w(e),n=t.prefix,r=t.value;if(!n||!r)return;var a=v(r),i=[],o=a.length;switch(n){case u:case c:for(var s=0;s<o;++s)i[s]=parseFloat(a[s]);return i;case f:case l:for(s=0;s<o;++s)-1!==a[s].indexOf("%")?i[s]=parseFloat(a[s])/100:i[s]=parseFloat(a[s]);return b(i)}}},isUndefined:function(e){return typeof e===i},isObject:function(e){return e&&typeof e===n},isArray:function(e){return Array.isArray(e)},isString:function(e){return typeof e===r},isFunction:function(e){return typeof e===t},splitSpace:function(e){return e.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:v,splitBracket:w,splitUnit:function(e){var t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(e);if(!t)return{prefix:"",unit:"",value:NaN};var n=t[1],r=t[2];return{prefix:n,unit:t[3],value:parseFloat(r)}},camelize:function(e){return e.replace(/[\s-_]([a-z])/g,function(e,t){return t.toUpperCase()})},decamelize:function(e,r){return void 0===r&&(r="-"),e.replace(/([a-z])([A-Z])/g,function(e,t,n){return""+t+r+n.toLowerCase()})},now:A,requestAnimationFrame:y,$:function(e,t){return t?o.querySelectorAll(e):o.querySelector(e)},hasClass:function(e,t){return e.classList?e.classList.contains(t):!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){e.classList?e.classList.add(t):e.className+=" "+t},removeClass:function(e,t){if(e.classList)e.classList.remove(t);else{var n=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className=e.className.replace(n," ")}},fromCSS:function(e,t){if(!e||!t||!t.length)return{};var n;if(e instanceof Element)n=e;else{if(!e.length)return{};n=e[0]}for(var r={},a=window.getComputedStyle(n),i=t.length,o=0;o<i;++o)r[t[o]]=a[t[o]];return r}}}); | ||
//# sourceMappingURL=utils.min.js.map |
{ | ||
"name": "@daybrush/utils", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "utils for daybrush", | ||
@@ -12,2 +12,3 @@ "main": "dist/utils.js", | ||
"utils", | ||
"dom", | ||
"css", | ||
@@ -59,3 +60,3 @@ "color", | ||
"devDependencies": { | ||
"@daybrush/jsdoc": "^0.3.0", | ||
"@daybrush/jsdoc": "^0.3.1", | ||
"daybrush-jsdoc-template": "^1.5.0", | ||
@@ -62,0 +63,0 @@ "gh-pages": "^2.0.1", |
@@ -16,2 +16,3 @@ # @daybrush/utils [![npm version](https://badge.fury.io/js/%40daybrush%2Futils.svg)](https://badge.fury.io/js/%40daybrush%2Futils) | ||
### [Consts](http://daybrush.com/utils/release/latest/doc/Consts.html) | ||
* document | ||
* OBJECT | ||
@@ -47,2 +48,3 @@ * PROPERTY | ||
### [DOM](http://daybrush.com/utils/release/latest/doc/DOM.html) | ||
* $ | ||
* hasClass | ||
@@ -49,0 +51,0 @@ * removeClass |
@@ -134,2 +134,16 @@ /** | ||
/** | ||
* Check whether the environment is window or node.js. | ||
* @memberof Consts | ||
* @name document | ||
* @example | ||
import {IS_WINDOW} from "@daybrush/utils"; | ||
console.log(IS_WINDOW); // false in node.js | ||
console.log(IS_WINDOW); // true in browser | ||
*/ | ||
const doc = typeof document !== UNDEFINED && document; | ||
export {doc as document}; | ||
const prefixes: string[] = ["webkit", "ms", "moz", "o"]; | ||
@@ -154,6 +168,6 @@ | ||
export const getCrossBrowserProperty = /*#__PURE__*/(property: string) => { | ||
if (typeof document === UNDEFINED) { | ||
if (!doc) { | ||
return ""; | ||
} | ||
const styles = (document.body || document.documentElement).style as any; | ||
const styles = (doc.body || doc.documentElement).style as any; | ||
const length = prefixes.length; | ||
@@ -160,0 +174,0 @@ |
@@ -5,2 +5,2 @@ | ||
export * from "./utils"; | ||
export * from "./css"; | ||
export * from "./dom"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
163562
2370
66