style-value-types
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -5,2 +5,8 @@ # Changelog | ||
### [4.1.3] 2021-03-19 | ||
### Fixed | ||
- Fixing `main` entry point. | ||
### [4.1.2] 2021-03-19 | ||
@@ -7,0 +13,0 @@ |
import { isString, singleColorRegex, floatRegex } from '../utils.js'; | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp))); | ||
@@ -6,0 +6,0 @@ }; }; |
@@ -1,1 +0,1 @@ | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).valueTypes={})}(this,(function(r){"use strict";var t=function(){return(t=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var a in t=arguments[e])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r}).apply(this,arguments)},e=function(r,t){return function(e){return Math.max(Math.min(e,t),r)}},n=function(r){return r%1?Number(r.toFixed(5)):r},a=/(-)?([\d]*\.?[\d])+/g,s=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,o=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function u(r){return"string"==typeof r}var f={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},i=t(t({},f),{transform:e(0,1)}),p=t(t({},f),{default:1}),l=function(r){return{test:function(t){return u(t)&&t.endsWith(r)&&1===t.split(" ").length},parse:parseFloat,transform:function(t){return""+t+r}}},c=l("deg"),h=l("%"),m=l("px"),d=l("vh"),v=l("vw"),g=t(t({},h),{parse:function(r){return h.parse(r)/100},transform:function(r){return h.transform(100*r)}}),b=function(r,t){return function(e){return u(e)&&o.test(e)&&e.startsWith(r)||t&&Object.prototype.hasOwnProperty.call(e,t)}},y=function(r,t,e){return function(n){var s;if(!u(n))return n;var o=n.match(a),f=o[0],i=o[1],p=o[2],l=o[3];return(s={})[r]=parseFloat(f),s[t]=parseFloat(i),s[e]=parseFloat(p),s.alpha=void 0!==l?parseFloat(l):1,s}},x={test:b("hsl","hue"),parse:y("hue","saturation","lightness"),transform:function(r){var t=r.hue,e=r.saturation,a=r.lightness,s=r.alpha,o=void 0===s?1:s;return"hsla("+Math.round(t)+", "+h.transform(n(e))+", "+h.transform(n(a))+", "+n(i.transform(o))+")"}},w=e(0,255),F=t(t({},f),{transform:function(r){return Math.round(w(r))}}),O={test:b("rgb","red"),parse:y("red","green","blue"),transform:function(r){var t=r.red,e=r.green,a=r.blue,s=r.alpha,o=void 0===s?1:s;return"rgba("+F.transform(t)+", "+F.transform(e)+", "+F.transform(a)+", "+n(i.transform(o))+")"}};var j={test:b("#"),parse:function(r){var t="",e="",n="",a="";return r.length>5?(t=r.substr(1,2),e=r.substr(3,2),n=r.substr(5,2),a=r.substr(7,2)):(t=r.substr(1,1),e=r.substr(2,1),n=r.substr(3,1),a=r.substr(4,1),t+=t,e+=e,n+=n,a+=a),{red:parseInt(t,16),green:parseInt(e,16),blue:parseInt(n,16),alpha:a?parseInt(a,16)/255:1}},transform:O.transform},M={test:function(r){return O.test(r)||j.test(r)||x.test(r)},parse:function(r){return O.test(r)?O.parse(r):x.test(r)?x.parse(r):j.parse(r)},transform:function(r){return u(r)?r:r.hasOwnProperty("red")?O.transform(r):x.transform(r)}},N="${c}",P="${n}";function I(r){var t=[],e=0,n=r.match(s);n&&(e=n.length,r=r.replace(s,N),t.push.apply(t,n.map(M.parse)));var o=r.match(a);return o&&(r=r.replace(a,P),t.push.apply(t,o.map(f.parse))),{values:t,numColors:e,tokenised:r}}function T(r){return I(r).values}function $(r){var t=I(r),e=t.values,a=t.numColors,s=t.tokenised,o=e.length;return function(r){for(var t=s,e=0;e<o;e++)t=t.replace(e<a?N:P,e<a?M.transform(r[e]):n(r[e]));return t}}var k=function(r){return"number"==typeof r?0:r};var A={test:function(r){var t,e,n,o;return isNaN(r)&&u(r)&&(null!==(e=null===(t=r.match(a))||void 0===t?void 0:t.length)&&void 0!==e?e:0)+(null!==(o=null===(n=r.match(s))||void 0===n?void 0:n.length)&&void 0!==o?o:0)>0},parse:T,createTransformer:$,getAnimatableNone:function(r){var t=T(r);return $(r)(t.map(k))}},C=new Set(["brightness","contrast","saturate","opacity"]);function W(r){var t=r.slice(0,-1).split("("),e=t[0],n=t[1];if("drop-shadow"===e)return r;var s=(n.match(a)||[])[0];if(!s)return r;var o=n.replace(s,""),u=C.has(e)?1:0;return s!==n&&(u*=100),e+"("+u+o+")"}var _=/([a-z-]*)\(.*?\)/g,z=t(t({},A),{getAnimatableNone:function(r){var t=r.match(_);return t?t.map(W).join(" "):r}});r.alpha=i,r.color=M,r.complex=A,r.degrees=c,r.filter=z,r.hex=j,r.hsla=x,r.number=f,r.percent=h,r.progressPercentage=g,r.px=m,r.rgbUnit=F,r.rgba=O,r.scale=p,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).valueTypes={})}(this,(function(r){"use strict";var t=function(){return(t=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var a in t=arguments[e])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r}).apply(this,arguments)},e=function(r,t){return function(e){return Math.max(Math.min(e,t),r)}},n=function(r){return r%1?Number(r.toFixed(5)):r},a=/(-)?([\d]*\.?[\d])+/g,s=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,o=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function u(r){return"string"==typeof r}var f={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},i=t(t({},f),{transform:e(0,1)}),p=t(t({},f),{default:1}),l=function(r){return{test:function(t){return u(t)&&t.endsWith(r)&&1===t.split(" ").length},parse:parseFloat,transform:function(t){return""+t+r}}},c=l("deg"),h=l("%"),m=l("px"),d=l("vh"),v=l("vw"),g=t(t({},h),{parse:function(r){return h.parse(r)/100},transform:function(r){return h.transform(100*r)}}),b=function(r,t){return function(e){return Boolean(u(e)&&o.test(e)&&e.startsWith(r)||t&&Object.prototype.hasOwnProperty.call(e,t))}},y=function(r,t,e){return function(n){var s;if(!u(n))return n;var o=n.match(a),f=o[0],i=o[1],p=o[2],l=o[3];return(s={})[r]=parseFloat(f),s[t]=parseFloat(i),s[e]=parseFloat(p),s.alpha=void 0!==l?parseFloat(l):1,s}},x={test:b("hsl","hue"),parse:y("hue","saturation","lightness"),transform:function(r){var t=r.hue,e=r.saturation,a=r.lightness,s=r.alpha,o=void 0===s?1:s;return"hsla("+Math.round(t)+", "+h.transform(n(e))+", "+h.transform(n(a))+", "+n(i.transform(o))+")"}},w=e(0,255),F=t(t({},f),{transform:function(r){return Math.round(w(r))}}),O={test:b("rgb","red"),parse:y("red","green","blue"),transform:function(r){var t=r.red,e=r.green,a=r.blue,s=r.alpha,o=void 0===s?1:s;return"rgba("+F.transform(t)+", "+F.transform(e)+", "+F.transform(a)+", "+n(i.transform(o))+")"}};var j={test:b("#"),parse:function(r){var t="",e="",n="",a="";return r.length>5?(t=r.substr(1,2),e=r.substr(3,2),n=r.substr(5,2),a=r.substr(7,2)):(t=r.substr(1,1),e=r.substr(2,1),n=r.substr(3,1),a=r.substr(4,1),t+=t,e+=e,n+=n,a+=a),{red:parseInt(t,16),green:parseInt(e,16),blue:parseInt(n,16),alpha:a?parseInt(a,16)/255:1}},transform:O.transform},M={test:function(r){return O.test(r)||j.test(r)||x.test(r)},parse:function(r){return O.test(r)?O.parse(r):x.test(r)?x.parse(r):j.parse(r)},transform:function(r){return u(r)?r:r.hasOwnProperty("red")?O.transform(r):x.transform(r)}},N="${c}",P="${n}";function I(r){var t=[],e=0,n=r.match(s);n&&(e=n.length,r=r.replace(s,N),t.push.apply(t,n.map(M.parse)));var o=r.match(a);return o&&(r=r.replace(a,P),t.push.apply(t,o.map(f.parse))),{values:t,numColors:e,tokenised:r}}function T(r){return I(r).values}function $(r){var t=I(r),e=t.values,a=t.numColors,s=t.tokenised,o=e.length;return function(r){for(var t=s,e=0;e<o;e++)t=t.replace(e<a?N:P,e<a?M.transform(r[e]):n(r[e]));return t}}var k=function(r){return"number"==typeof r?0:r};var A={test:function(r){var t,e,n,o;return isNaN(r)&&u(r)&&(null!==(e=null===(t=r.match(a))||void 0===t?void 0:t.length)&&void 0!==e?e:0)+(null!==(o=null===(n=r.match(s))||void 0===n?void 0:n.length)&&void 0!==o?o:0)>0},parse:T,createTransformer:$,getAnimatableNone:function(r){var t=T(r);return $(r)(t.map(k))}},C=new Set(["brightness","contrast","saturate","opacity"]);function W(r){var t=r.slice(0,-1).split("("),e=t[0],n=t[1];if("drop-shadow"===e)return r;var s=(n.match(a)||[])[0];if(!s)return r;var o=n.replace(s,""),u=C.has(e)?1:0;return s!==n&&(u*=100),e+"("+u+o+")"}var _=/([a-z-]*)\(.*?\)/g,z=t(t({},A),{getAnimatableNone:function(r){var t=r.match(_);return t?t.map(W).join(" "):r}});r.alpha=i,r.color=M,r.complex=A,r.degrees=c,r.filter=z,r.hex=j,r.hsla=x,r.number=f,r.percent=h,r.progressPercentage=g,r.px=m,r.rgbUnit=F,r.rgba=O,r.scale=p,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})})); |
@@ -41,3 +41,3 @@ 'use strict'; | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp))); | ||
@@ -44,0 +44,0 @@ }; }; |
@@ -67,3 +67,3 @@ (function (global, factory) { | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp))); | ||
@@ -70,0 +70,0 @@ }; }; |
import { Color } from '../types'; | ||
export declare const isColorString: (type: string, testProp?: string) => (v: any) => any; | ||
export declare const isColorString: (type: string, testProp?: string) => (v: any) => boolean; | ||
export declare const splitColor: (aName: string, bName: string, cName: string) => (v: string | Color) => import("../types").RGBA | import("../types").HSLA | { | ||
@@ -4,0 +4,0 @@ [x: string]: number; |
import { floatRegex, isString, singleColorRegex } from '../utils'; | ||
export var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp))); | ||
@@ -5,0 +5,0 @@ }; }; |
{ | ||
"name": "style-value-types", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "Parsers, transformers and tests for special value types, eg: %, hex codes etc.", | ||
"main": "lib/index.js", | ||
"main": "dist/style-value-types.cjs.js", | ||
"types": "lib/index.d.ts", | ||
@@ -25,3 +25,3 @@ "module": "dist/es/index.js", | ||
"measure": "gzip -c dist/style-value-types.min.js | wc -c", | ||
"prepublishOnly": "npm run lint && npm run build" | ||
"prepublishOnly": "npm run test && npm run build" | ||
}, | ||
@@ -28,0 +28,0 @@ "repository": { |
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
62295