style-value-types
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,1 +0,1 @@ | ||
!function(r){function t(e){if(n[e])return n[e].exports;var a=n[e]={i:e,l:!1,exports:{}};return r[e].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};t.m=r,t.c=n,t.d=function(r,n,e){t.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:e})},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.p="",t(t.s=0)}([function(r,t,n){"use strict";function e(r){var n=r.length;return function(e){for(var a={},u=t.splitCommaDelimited(t.getValueFromFunctionString(e)),o=0;o<n;o++)a[r[o]]=void 0!==u[o]?parseFloat(u[o]):1;return a}}var a=this&&this.__assign||Object.assign||function(r){for(var t,n=1,e=arguments.length;n<e;n++){t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a])}return r};Object.defineProperty(t,"__esModule",{value:!0});var u=function(r,t){return function(n){return Math.max(Math.min(n,t),r)}},o=function(r){return function(t){return"string"==typeof t&&-1!==t.indexOf(r)}},s=function(r){return{test:o(r),parse:parseFloat,transform:function(t){return""+t+r}}},i=function(r){return function(t){return"string"==typeof t&&0===t.indexOf(r)}};t.getValueFromFunctionString=function(r){return r.substring(r.indexOf("(")+1,r.lastIndexOf(")"))},t.splitCommaDelimited=function(r){return"string"==typeof r?r.split(/,\s*/):[r]},t.splitColorValues=e,t.number={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},t.alpha=a({},t.number,{transform:u(0,1)}),t.degrees=s("deg"),t.percent=s("%"),t.px=s("px"),t.scale=a({},t.number,{default:1});var f=/(-)?(\d[\d\.]*)/g,c=function(r){return"${"+r+"}"};t.complex={test:function(r){var t=r.match&&r.match(f);return void 0!==t&&t.constructor===Array&&t.length>1},parse:function(r){var t={};return r.match(f).forEach(function(r,n){return t[n]=parseFloat(r)}),t},createTransformer:function(r){var t=0,n=r.replace(f,function(){return c(""+t++)});return function(r){var t=n;for(var e in r)r.hasOwnProperty(e)&&(t=t.replace(c(e),r[e].toString()));return t}}};var l=u(0,255);t.rgbUnit=a({},t.number,{transform:function(r){return Math.round(l(r))}});var p=function(r){var t=r.red,n=r.green,e=r.blue,a=r.alpha;return"rgba("+t+", "+n+", "+e+", "+(void 0===a?1:a)+")"};t.rgba={test:i("rgb"),parse:e(["red","green","blue","alpha"]),transform:function(r){var n=r.red,e=r.green,a=r.blue,u=r.alpha;return p({red:t.rgbUnit.transform(n),green:t.rgbUnit.transform(e),blue:t.rgbUnit.transform(a),alpha:u})}};var h=function(r){var t=r.hue,n=r.saturation,e=r.lightness,a=r.alpha;return"hsla("+t+", "+n+", "+e+", "+(void 0===a?1:a)+")"};t.hsla={test:i("hsl"),parse:e(["hue","saturation","lightness","alpha"]),transform:function(r){var n=r.hue,e=r.saturation,a=r.lightness,u=r.alpha;return h({hue:Math.round(n),saturation:t.percent.transform(e),lightness:t.percent.transform(a),alpha:u})}},t.hex=a({},t.rgba,{test:i("#"),parse:function(r){var t,n,e;return r.length>4?(t=r.substr(1,2),n=r.substr(3,2),e=r.substr(5,2)):(t=r.substr(1,1),n=r.substr(2,1),e=r.substr(3,1),t+=t,n+=n,e+=e),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(e,16),alpha:1}}});var g=function(r){return void 0!==r.red},b=function(r){return void 0!==r.hue};t.color={test:function(r){return t.rgba.test(r)||t.hsla.test(r)||t.hex.test(r)},parse:function(r){return t.rgba.test(r)?t.rgba.parse(r):t.hsla.test(r)?t.hsla.parse(r):t.hex.test(r)?t.hex.parse(r):r},transform:function(r){return g(r)?t.rgba.transform(r):b(r)?t.hsla.transform(r):r}}}]); | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(r["style-value-types"]={})}(this,function(r){"use strict";var t=Object.assign||function(r){for(var t,n=1,e=arguments.length;n<e;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r},n=function(r,t){return function(n){return Math.max(Math.min(n,t),r)}},e=function(r){return{test:(t=r,function(r){return"string"==typeof r&&-1!==r.indexOf(t)}),parse:parseFloat,transform:function(t){return""+t+r}};var t},a=function(r){return function(t){return"string"==typeof t&&0===t.indexOf(r)}},u=function(r){return r.substring(r.indexOf("(")+1,r.lastIndexOf(")"))},o=function(r){return"string"==typeof r?r.split(/,\s*/):[r]};function s(r){var t=r.length;return function(n){for(var e={},a=o(u(n)),s=0;s<t;s++)e[r[s]]=void 0!==a[s]?parseFloat(a[s]):1;return e}}var i={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},f=t({},i,{transform:n(0,1)}),c=e("deg"),p=e("%"),l=e("px"),h=t({},i,{default:1}),d=/(-)?(\d[\d\.]*)/g,m=function(r){return"${"+r+"}"},g={test:function(r){var t=r.match&&r.match(d);return void 0!==t&&t.constructor===Array&&t.length>1},parse:function(r){var t={};return r.match(d).forEach(function(r,n){return t[n]=parseFloat(r)}),t},createTransformer:function(r){var t=0,n=r.replace(d,function(){return m(""+t++)});return function(r){var t=n;for(var e in r)r.hasOwnProperty(e)&&(t=t.replace(m(e),r[e].toString()));return t}}},v=n(0,255),b=t({},i,{transform:function(r){return Math.round(v(r))}}),y={test:a("rgb"),parse:s(["red","green","blue","alpha"]),transform:function(r){var t=r.red,n=r.green,e=r.blue,a=r.alpha;return function(r){var t=r.red,n=r.green,e=r.blue,a=r.alpha;return"rgba("+t+", "+n+", "+e+", "+(void 0===a?1:a)+")"}({red:b.transform(t),green:b.transform(n),blue:b.transform(e),alpha:a})}},x={test:a("hsl"),parse:s(["hue","saturation","lightness","alpha"]),transform:function(r){var t=r.hue,n=r.saturation,e=r.lightness,a=r.alpha;return function(r){var t=r.hue,n=r.saturation,e=r.lightness,a=r.alpha;return"hsla("+t+", "+n+", "+e+", "+(void 0===a?1:a)+")"}({hue:Math.round(t),saturation:p.transform(n),lightness:p.transform(e),alpha:a})}},O=t({},y,{test:a("#"),parse:function(r){var t,n,e;return r.length>4?(t=r.substr(1,2),n=r.substr(3,2),e=r.substr(5,2)):(t=r.substr(1,1),n=r.substr(2,1),e=r.substr(3,1),t+=t,n+=n,e+=e),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(e,16),alpha:1}}}),F={test:function(r){return y.test(r)||x.test(r)||O.test(r)},parse:function(r){return y.test(r)?y.parse(r):x.test(r)?x.parse(r):O.test(r)?O.parse(r):r},transform:function(r){return function(r){return void 0!==r.red}(r)?y.transform(r):function(r){return void 0!==r.hue}(r)?x.transform(r):r}};r.getValueFromFunctionString=u,r.splitCommaDelimited=o,r.splitColorValues=s,r.number=i,r.alpha=f,r.degrees=c,r.percent=p,r.px=l,r.scale=h,r.complex=g,r.rgbUnit=b,r.rgba=y,r.hsla=x,r.hex=O,r.color=F,Object.defineProperty(r,"__esModule",{value:!0})}); |
@@ -10,3 +10,2 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var clamp = function (min, max) { return function (v) { return Math.max(Math.min(v, max), min); }; }; | ||
@@ -20,9 +19,9 @@ var contains = function (term) { return function (v) { return (typeof v === 'string' && v.indexOf(term) !== -1); }; }; | ||
var isFirstChars = function (term) { return function (v) { return (typeof v === 'string' && v.indexOf(term) === 0); }; }; | ||
exports.getValueFromFunctionString = function (value) { return value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')); }; | ||
exports.splitCommaDelimited = function (value) { return typeof value === 'string' ? value.split(/,\s*/) : [value]; }; | ||
function splitColorValues(terms) { | ||
export var getValueFromFunctionString = function (value) { return value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')); }; | ||
export var splitCommaDelimited = function (value) { return typeof value === 'string' ? value.split(/,\s*/) : [value]; }; | ||
export function splitColorValues(terms) { | ||
var numTerms = terms.length; | ||
return function (v) { | ||
var values = {}; | ||
var valuesArray = exports.splitCommaDelimited(exports.getValueFromFunctionString(v)); | ||
var valuesArray = splitCommaDelimited(getValueFromFunctionString(v)); | ||
for (var i = 0; i < numTerms; i++) { | ||
@@ -34,4 +33,3 @@ values[terms[i]] = (valuesArray[i] !== undefined) ? parseFloat(valuesArray[i]) : 1; | ||
} | ||
exports.splitColorValues = splitColorValues; | ||
exports.number = { | ||
export var number = { | ||
test: function (v) { return typeof v === 'number'; }, | ||
@@ -41,10 +39,10 @@ parse: parseFloat, | ||
}; | ||
exports.alpha = __assign({}, exports.number, { transform: clamp(0, 1) }); | ||
exports.degrees = createUnitType('deg'); | ||
exports.percent = createUnitType('%'); | ||
exports.px = createUnitType('px'); | ||
exports.scale = __assign({}, exports.number, { default: 1 }); | ||
export var alpha = __assign({}, number, { transform: clamp(0, 1) }); | ||
export var degrees = createUnitType('deg'); | ||
export var percent = createUnitType('%'); | ||
export var px = createUnitType('px'); | ||
export var scale = __assign({}, number, { default: 1 }); | ||
var FLOAT_REGEX = /(-)?(\d[\d\.]*)/g; | ||
var generateToken = function (token) { return '${' + token + '}'; }; | ||
exports.complex = { | ||
export var complex = { | ||
test: function (v) { | ||
@@ -74,3 +72,3 @@ var matches = v.match && v.match(FLOAT_REGEX); | ||
var clampRgbUnit = clamp(0, 255); | ||
exports.rgbUnit = __assign({}, exports.number, { transform: function (v) { return Math.round(clampRgbUnit(v)); } }); | ||
export var rgbUnit = __assign({}, number, { transform: function (v) { return Math.round(clampRgbUnit(v)); } }); | ||
var rgbaTemplate = function (_a) { | ||
@@ -80,3 +78,3 @@ var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b; | ||
}; | ||
exports.rgba = { | ||
export var rgba = { | ||
test: isFirstChars('rgb'), | ||
@@ -87,5 +85,5 @@ parse: splitColorValues(['red', 'green', 'blue', 'alpha']), | ||
return rgbaTemplate({ | ||
red: exports.rgbUnit.transform(red), | ||
green: exports.rgbUnit.transform(green), | ||
blue: exports.rgbUnit.transform(blue), | ||
red: rgbUnit.transform(red), | ||
green: rgbUnit.transform(green), | ||
blue: rgbUnit.transform(blue), | ||
alpha: alpha | ||
@@ -99,3 +97,3 @@ }); | ||
}; | ||
exports.hsla = { | ||
export var hsla = { | ||
test: isFirstChars('hsl'), | ||
@@ -107,4 +105,4 @@ parse: splitColorValues(['hue', 'saturation', 'lightness', 'alpha']), | ||
hue: Math.round(hue), | ||
saturation: exports.percent.transform(saturation), | ||
lightness: exports.percent.transform(lightness), | ||
saturation: percent.transform(saturation), | ||
lightness: percent.transform(lightness), | ||
alpha: alpha | ||
@@ -114,3 +112,3 @@ }); | ||
}; | ||
exports.hex = __assign({}, exports.rgba, { test: isFirstChars('#'), parse: function (v) { | ||
export var hex = __assign({}, rgba, { test: isFirstChars('#'), parse: function (v) { | ||
var r, g, b; | ||
@@ -139,13 +137,13 @@ if (v.length > 4) { | ||
var isHsla = function (v) { return v.hue !== undefined; }; | ||
exports.color = { | ||
test: function (v) { return exports.rgba.test(v) || exports.hsla.test(v) || exports.hex.test(v); }, | ||
export var color = { | ||
test: function (v) { return rgba.test(v) || hsla.test(v) || hex.test(v); }, | ||
parse: function (v) { | ||
if (exports.rgba.test(v)) { | ||
return exports.rgba.parse(v); | ||
if (rgba.test(v)) { | ||
return rgba.parse(v); | ||
} | ||
else if (exports.hsla.test(v)) { | ||
return exports.hsla.parse(v); | ||
else if (hsla.test(v)) { | ||
return hsla.parse(v); | ||
} | ||
else if (exports.hex.test(v)) { | ||
return exports.hex.parse(v); | ||
else if (hex.test(v)) { | ||
return hex.parse(v); | ||
} | ||
@@ -156,6 +154,6 @@ return v; | ||
if (isRgba(v)) { | ||
return exports.rgba.transform(v); | ||
return rgba.transform(v); | ||
} | ||
else if (isHsla(v)) { | ||
return exports.hsla.transform(v); | ||
return hsla.transform(v); | ||
} | ||
@@ -162,0 +160,0 @@ return v; |
{ | ||
"name": "style-value-types", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Parsers, transformers and tests for special value types, eg: %, hex codes etc.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"module": "dist/style-value-types.es.js", | ||
"jsnext:main": "dist/style-value-types.es.js", | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"src" | ||
"dist" | ||
], | ||
"scripts": { | ||
"watch": "tsc -w", | ||
"build": "tsc && webpack && npm run measure", | ||
"build": "rollup -c", | ||
"watch": "rollup -c -w", | ||
"lint": "tslint -c tslint.json 'src/**/*.{ts}'", | ||
@@ -39,2 +40,4 @@ "test": "jest", | ||
"jest": "^20.0.4", | ||
"rollup-plugin-typescript2": "^0.14.0", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"ts-jest": "^20.0.10", | ||
@@ -54,3 +57,8 @@ "typescript": "^2.4.2", | ||
"testRegex": "/_tests/.*\\.(ts|tsx|js)$" | ||
}, | ||
"unpkg": "./dist/style-value-types.min.js", | ||
"prettier": { | ||
"parser": "typescript", | ||
"singleQuote": true | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
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
33429
560
6
1
1