Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuke-helper

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuke-helper - npm Package Compare versions

Comparing version 2.1.10 to 2.2.2

build/deps.json

35

CHANGELOG.md

@@ -6,2 +6,37 @@ # Change Log

<a name="2.2.2"></a>
## [2.2.2](https://gitlab.alibaba-inc.com/nuke/helper/compare/v2.2.1...v2.2.2) (2018-08-23)
**Note:** Version bump only for package nuke-helper
<a name="2.2.1"></a>
## [2.2.1](https://gitlab.alibaba-inc.com/nuke/helper/compare/v2.2.0...v2.2.1) (2018-08-23)
**Note:** Version bump only for package nuke-helper
<a name="2.2.0"></a>
# [2.2.0](https://gitlab.alibaba-inc.com/nuke/helper/compare/v2.1.10...v2.2.0) (2018-08-23)
### Bug Fixes
* merge conflict ([7a4e427](https://gitlab.alibaba-inc.com/nuke/helper/commit/7a4e427))
### Features
* add jest test suite ([ebe6aba](https://gitlab.alibaba-inc.com/nuke/helper/commit/ebe6aba))
<a name="2.1.10"></a>

@@ -8,0 +43,0 @@ ## [2.1.10](https://gitlab.alibaba-inc.com/nuke/helper/compare/v2.1.9...v2.1.10) (2018-08-20)

45

lib/border-seperate.js

@@ -1,1 +0,44 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.borderSeperate=borderSeperate;function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function borderSeperate(style){var attrs=1<arguments.length&&void 0!==arguments[1]?arguments[1]:['Color','Style','Width'];return style.border&&('none'===style.border&&(style.borderWidth=0),delete style.border),attrs.map(function(attr){if(style.hasOwnProperty('border'+attr)){var _attrObj,attrObj=(_attrObj={},_defineProperty(_attrObj,'borderTop'+attr,style['border'+attr]),_defineProperty(_attrObj,'borderLeft'+attr,style['border'+attr]),_defineProperty(_attrObj,'borderRight'+attr,style['border'+attr]),_defineProperty(_attrObj,'borderBottom'+attr,style['border'+attr]),_attrObj),deleteFlag=!1;['Top','Left','Right','Bottom'].map(function(direction){style.hasOwnProperty('border'+direction+attr)&&(deleteFlag=!0,attrObj['border'+direction+attr]=style['border'+direction+attr])}),deleteFlag&&(delete style['border'+attr],style=Object.assign({},attrObj,style))}}),style}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.borderSeperate = borderSeperate;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* 用来处理 weex 下,同时有 borderWidth 和 borderTopWidth 时,weex 表现异常的问题
* @param {object} style
* @param {array} attrArray 需要修复 border 的哪些属性
* @return {object} style
*/
function borderSeperate(style) {
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['Color', 'Style', 'Width'];
if (style.border) {
if (style.border === 'none') {
style.borderWidth = 0;
}
delete style.border;
}
attrs.map(function (attr) {
if (style.hasOwnProperty('border' + attr)) {
var _attrObj;
var attrObj = (_attrObj = {}, _defineProperty(_attrObj, 'borderTop' + attr, style['border' + attr]), _defineProperty(_attrObj, 'borderLeft' + attr, style['border' + attr]), _defineProperty(_attrObj, 'borderRight' + attr, style['border' + attr]), _defineProperty(_attrObj, 'borderBottom' + attr, style['border' + attr]), _attrObj);
var deleteFlag = false;
['Top', 'Left', 'Right', 'Bottom'].map(function (direction) {
if (style.hasOwnProperty('border' + direction + attr)) {
deleteFlag = true;
attrObj['border' + direction + attr] = style['border' + direction + attr];
}
});
if (deleteFlag) {
delete style['border' + attr];
style = Object.assign({}, attrObj, style);
}
}
});
return style;
}

@@ -1,1 +0,6 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var bubbleKeys=exports.bubbleKeys=['display','justifyContent','alignItems','flexDirection','overflow','backgroundColor','visibility','outline','transition','zoom','flexWrap','position','zIndex','flex','width','height'];
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var bubbleKeys = exports.bubbleKeys = ['display', 'justifyContent', 'alignItems', 'flexDirection', 'overflow', 'backgroundColor', 'visibility', 'outline', 'transition', 'zoom', 'flexWrap', 'position', 'zIndex', 'flex', 'width', 'height'];

@@ -1,1 +0,66 @@

'use strict';var _extends=Object.assign||function(target){for(var source,i=1;i<arguments.length;i++)for(var key in source=arguments[i],source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key]);return target};Object.defineProperty(exports,'__esModule',{value:!0});exports.calcFixedFont=calcFixedFont;var _nukeEnv=require('nuke-env'),isIpad=void 0;if(_nukeEnv.isWeb)isIpad=-1<navigator.userAgent.indexOf('iPad');else{var env='string'==typeof WXEnvironment?{}:WXEnvironment;isIpad='ios'===env.platform.toLowerCase()&&-1<env.deviceModel.toLowerCase().indexOf('ipad')}function fitPad(style){var result=_extends({},style),fontSize=style.fontSize;return('string'==typeof fontSize&&0<fontSize.indexOf('rem')||'number'==typeof fontSize)&&(fontSize=parseInt(fontSize,10)),'string'==typeof fontSize&&0<fontSize.indexOf('px')&&(fontSize=2*parseInt(fontSize,10)),result.fontSize=fontSize,result}function calcFixedFont(style){var fixedFont=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],shouldFitPad=!(2<arguments.length&&void 0!==arguments[2])||arguments[2];if(!style||!style.fontSize||!fixedFont)return style;if(isIpad&&shouldFitPad)return fitPad(style);var result=_extends({},style),fontSize=style.fontSize;return('string'==typeof fontSize&&0<fontSize.indexOf('rem')||'number'==typeof fontSize)&&(fontSize=Math.floor(parseInt(fontSize,10)/2)),'string'==typeof fontSize&&0<fontSize.indexOf('px')&&(fontSize=parseInt(fontSize,10)),result.fontSize=fontSize+(_nukeEnv.isWeb?'px':'wx'),isIpad&&fitPad,result}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.calcFixedFont = calcFixedFont;
var _nukeEnv = require('nuke-env');
var isIpad = void 0;
if (_nukeEnv.isWeb) {
isIpad = navigator.userAgent.indexOf('iPad') > -1;
} else {
var env = typeof WXEnvironment !== 'string' ? WXEnvironment : {};
isIpad = env.platform.toLowerCase() === 'ios' && env.deviceModel.toLowerCase().indexOf('ipad') > -1;
}
function fitPad(style) {
var result = _extends({}, style);
var fontSize = style.fontSize;
if (typeof fontSize === 'string' && fontSize.indexOf('rem') > 0 || typeof fontSize === 'number') {
fontSize = parseInt(fontSize, 10);
}
if (typeof fontSize === 'string' && fontSize.indexOf('px') > 0) {
fontSize = parseInt(fontSize, 10) * 2;
}
result.fontSize = fontSize;
return result;
}
// appInfo.platform.toLowerCase() === 'ios' &&
// appInfo.deviceModel.toLowerCase() === 'ipad';
/**
* parse fontSize to a fixed font.
* if style:
* fontSize:'28rem' or
* fontSize:28, or
* fontSize:'14px'
* and fixedFont=true
* will turns to:
* font-size 14px (in web) / 14wx (in ios and android weex ).
* But if in ipad, things go other way, if you choose fitPad, font-size will roll back to rem to fit screen.
*/
function calcFixedFont(style) {
var fixedFont = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var shouldFitPad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (!style || !style.fontSize || !fixedFont) return style;
if (isIpad && shouldFitPad) return fitPad(style);
var result = _extends({}, style);
var fontSize = style.fontSize;
if (typeof fontSize === 'string' && fontSize.indexOf('rem') > 0 || typeof fontSize === 'number') {
fontSize = Math.floor(parseInt(fontSize, 10) / 2);
}
if (typeof fontSize === 'string' && fontSize.indexOf('px') > 0) {
fontSize = parseInt(fontSize, 10);
}
result.fontSize = fontSize + (_nukeEnv.isWeb ? 'px' : 'wx');
if (isIpad && fitPad) {}
return result;
}

@@ -1,1 +0,14 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.fixSmallUnit=fixSmallUnit;var _nukeEnv=require('nuke-env');function fixSmallUnit(unit){var num=parseInt(unit,10);return 6<num?unit:''+Math.floor(num/2).toString()+(_nukeEnv.isWeb?'px':'wx')}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fixSmallUnit = fixSmallUnit;
var _nukeEnv = require('nuke-env');
function fixSmallUnit(unit) {
var num = parseInt(unit, 10);
if (num > 6) return unit;
return '' + Math.floor(num / 2).toString() + (_nukeEnv.isWeb ? 'px' : 'wx');
}

@@ -1,1 +0,60 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.hairLine=void 0;var _nukeEnv=require('nuke-env'),_borderSeperate=require('./border-seperate'),hairLine={};hairLine.detect=function(){var hairLineFlag;if(!_nukeEnv.isWeb)return!0;if(window.OffsetHeightForRxBorder)hairLineFlag=window.OffsetHeightForRxBorder;else if(window&&window.devicePixelRatio&&2<=window.devicePixelRatio){var testElem=document.createElement('div');testElem.style.border='.5px solid transparent',testElem.style.height=0,testElem.style.boxSizing='content-box',document.body.appendChild(testElem),hairLineFlag=1===testElem.offsetHeight,window.OffsetHeightForRxBorder=hairLineFlag,document.body.removeChild(testElem)}return hairLineFlag},hairLine.fixBorder=function(style){if(!_nukeEnv.isWeb)return style;var borderWidthHair=hairLine.detect()?'0.5px':'1px';return style=(0,_borderSeperate.borderSeperate)(style,['Width']),['Top','Left','Right','Bottom'].map(function(direction){style['border'+direction+'Width']&&1===parseFloat(style['border'+direction+'Width'],10)&&(style['border'+direction+'Width']=borderWidthHair)}),style.borderWidth&&1===parseFloat(style.borderWidth,10)&&(style.borderWidth=borderWidthHair),style},exports.hairLine=hairLine;
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hairLine = undefined;
var _nukeEnv = require('nuke-env');
var _borderSeperate = require('./border-seperate');
var hairLine = {};
/**
* 设备是否支持 0.5px
* decide if container support 0.5px in web env
* @return {boolean} supportFlag
*/
hairLine.detect = function () {
var hairLineFlag = void 0;
if (!_nukeEnv.isWeb) return true;
if (window.OffsetHeightForRxBorder) {
hairLineFlag = window.OffsetHeightForRxBorder;
} else if (window && window.devicePixelRatio && window.devicePixelRatio >= 2) {
var testElem = document.createElement('div');
testElem.style.border = '.5px solid transparent';
testElem.style.height = 0;
testElem.style.boxSizing = 'content-box';
document.body.appendChild(testElem);
if (testElem.offsetHeight === 1) {
hairLineFlag = true;
} else {
hairLineFlag = false;
}
window.OffsetHeightForRxBorder = hairLineFlag;
document.body.removeChild(testElem);
}
return hairLineFlag;
};
/**
* 高清 0.5px 样式
* 0.5px hairline style
* @param {object} style
* @return {object} style
*/
hairLine.fixBorder = function (style) {
if (!_nukeEnv.isWeb) return style;
var borderWidthHair = hairLine.detect() ? '0.5px' : '1px';
style = (0, _borderSeperate.borderSeperate)(style, ['Width']);
['Top', 'Left', 'Right', 'Bottom'].map(function (direction) {
if (style['border' + direction + 'Width'] && parseFloat(style['border' + direction + 'Width'], 10) === 1) {
style['border' + direction + 'Width'] = borderWidthHair;
}
});
if (style.borderWidth && parseFloat(style.borderWidth, 10) === 1) {
style.borderWidth = borderWidthHair;
}
return style;
};
exports.hairLine = hairLine;

@@ -1,1 +0,62 @@

'use strict';var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&'function'==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};Object.defineProperty(exports,'__esModule',{value:!0});exports.valueToObj=valueToObj,exports.hexToRgb=hexToRgb,exports.rgba=rgba;function valueToObj(obj){return Object.keys(obj).forEach(function(name){'object'===_typeof(obj[name])&&(obj[name]={name:name,raw:obj[name]})}),obj}function hexToRgb(hex){var shorthandRegex=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;hex=hex.replace(shorthandRegex,function(m,r,g,b){return r+r+g+g+b+b});var result=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);return result?{r:parseInt(result[1],16),g:parseInt(result[2],16),b:parseInt(result[3],16)}:null}function rgba(hex,opacity){'object'===('undefined'==typeof hex?'undefined':_typeof(hex))&&'raw'in hex&&(hex=hex.raw),'object'===('undefined'==typeof opacity?'undefined':_typeof(opacity))&&'raw'in opacity&&(opacity=opacity.raw);var result=exports.hexToRgb(hex);return result?'rgba('+result.r+','+result.g+','+result.b+','+opacity+')':null}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.valueToObj = valueToObj;
exports.hexToRgb = hexToRgb;
exports.rgba = rgba;
/**
* @param {*} hex
* @param {*} opacity
*/
function valueToObj(obj) {
Object.keys(obj).forEach(function (name) {
if (_typeof(obj[name]) === 'object') {
obj[name] = {
name: name,
raw: obj[name]
};
}
});
return obj;
}
function hexToRgb(hex, opacity) {
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if (!result) return null;
return {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
};
}
/**
* @param {*} hex
* @param {*} opacity
*/
function rgba(hex, opacity) {
if ((typeof hex === 'undefined' ? 'undefined' : _typeof(hex)) === 'object' && 'raw' in hex) {
hex = hex.raw;
}
if ((typeof opacity === 'undefined' ? 'undefined' : _typeof(opacity)) === 'object' && 'raw' in opacity) {
opacity = opacity.raw;
}
var result = exports.hexToRgb(hex);
if (!result) return null;
// if ('raw' in hex) {
// return { raw: `rgba(${result.r},${result.g},${result.b},${opacity})` };
// }
return 'rgba(' + result.r + ',' + result.g + ',' + result.b + ',' + opacity + ')';
}

@@ -1,1 +0,42 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.rem=exports.layout=exports.hex=exports.fixSmallUnit=exports.bubbleKeys=exports.borderSeperate=exports.textKeys=exports.hairLine=exports.calcTextSize=void 0;var _calcFixedFont=require('./calc-fixed-font'),_hairLine=require('./hair-line'),_textKeys=require('./text-keys'),_bubbleKeys=require('./bubble-keys'),_fixSmallUnit=require('./fix-small-unit'),_borderSeperate=require('./border-seperate'),_hex=require('./hex'),hex=_interopRequireWildcard(_hex),_layout=require('./layout'),layout=_interopRequireWildcard(_layout),_rem=require('./rem'),rem=_interopRequireWildcard(_rem);function _interopRequireWildcard(obj){if(obj&&obj.__esModule)return obj;var newObj={};if(null!=obj)for(var key in obj)Object.prototype.hasOwnProperty.call(obj,key)&&(newObj[key]=obj[key]);return newObj.default=obj,newObj}exports.calcTextSize=_calcFixedFont.calcFixedFont,exports.hairLine=_hairLine.hairLine,exports.textKeys=_textKeys.textKeys,exports.borderSeperate=_borderSeperate.borderSeperate,exports.bubbleKeys=_bubbleKeys.bubbleKeys,exports.fixSmallUnit=_fixSmallUnit.fixSmallUnit,exports.hex=hex,exports.layout=layout,exports.rem=rem;
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rem = exports.layout = exports.hex = exports.fixSmallUnit = exports.bubbleKeys = exports.borderSeperate = exports.textKeys = exports.hairLine = exports.calcTextSize = undefined;
var _calcFixedFont = require('./calc-fixed-font');
var _hairLine = require('./hair-line');
var _textKeys = require('./text-keys');
var _bubbleKeys = require('./bubble-keys');
var _fixSmallUnit = require('./fix-small-unit');
var _borderSeperate = require('./border-seperate');
var _hex = require('./hex');
var hex = _interopRequireWildcard(_hex);
var _layout = require('./layout');
var layout = _interopRequireWildcard(_layout);
var _rem = require('./rem');
var rem = _interopRequireWildcard(_rem);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
exports.calcTextSize = _calcFixedFont.calcFixedFont;
exports.hairLine = _hairLine.hairLine;
exports.textKeys = _textKeys.textKeys;
exports.borderSeperate = _borderSeperate.borderSeperate;
exports.bubbleKeys = _bubbleKeys.bubbleKeys;
exports.fixSmallUnit = _fixSmallUnit.fixSmallUnit;
exports.hex = hex;
exports.layout = layout;
exports.rem = rem;

@@ -1,1 +0,14 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.alignCenter=alignCenter;function alignCenter(){return{display:'flex',flexDirection:'row',alignItems:'center',justifyContent:'center'}}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.alignCenter = alignCenter;
function alignCenter() {
return {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
};
}

@@ -1,1 +0,40 @@

'use strict';var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&'function'==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};Object.defineProperty(exports,'__esModule',{value:!0});exports.caculateRemToPx=caculateRemToPx,exports.removeRemUnit=removeRemUnit;var _nukeEnv=require('nuke-env');function caculateRemToPx(rem){var defaultWidth=1<arguments.length&&void 0!==arguments[1]?arguments[1]:750;if('object'===('undefined'==typeof rem?'undefined':_typeof(rem))&&'raw'in rem&&(rem=rem.raw),_nukeEnv.isWeex)return rem;rem=exports.removeRemUnit(rem);var defaultPixUnit=document.documentElement.clientWidth/defaultWidth,num=Math.round(parseFloat(rem)*defaultPixUnit);return 0==num%2?num+'px':num-1+'px'}function removeRemUnit(rem){return rem+='',rem.replace('rem','')}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports.caculateRemToPx = caculateRemToPx;
exports.removeRemUnit = removeRemUnit;
var _nukeEnv = require('nuke-env');
/**
* @description parse rem to even px to solve andoird float px issue.
*/
function caculateRemToPx(rem) {
var defaultWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 750;
// Default 1 rem to 1 px
if ((typeof rem === 'undefined' ? 'undefined' : _typeof(rem)) === 'object' && 'raw' in rem) {
rem = rem.raw;
}
if (_nukeEnv.isWeex) return rem;
rem = exports.removeRemUnit(rem);
var defaultPixUnit = document.documentElement.clientWidth / defaultWidth;
var num = Math.round(parseFloat(rem) * defaultPixUnit);
if (num % 2 === 0) {
return num + 'px';
}
return num - 1 + 'px';
}
/**
* @description remove rem unit for string like 12rem => 12
* @param {string or number} rem
*/
function removeRemUnit(rem) {
rem = String(rem);
return rem.replace('rem', '');
}

@@ -1,1 +0,6 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var textKeys=exports.textKeys=['color','fontSize','fontStyle','fontWeight','lineHeight','textAlign','textDecoration'];
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var textKeys = exports.textKeys = ['color', 'fontSize', 'fontStyle', 'fontWeight', 'lineHeight', 'textAlign', 'textDecoration'];

10

package.json
{
"name": "nuke-helper",
"version": "2.1.10",
"version": "2.2.2",
"description": "辅助函数",

@@ -44,7 +44,7 @@ "main": "lib/index",

"dependencies": {
"nuke-env": "^2.1.10"
"nuke-env": "^2.2.2"
},
"devDependencies": {
"nuke-text": "^2.1.10",
"nuke-view": "^2.1.10"
"nuke-text": "^2.2.2",
"nuke-view": "^2.2.2"
},

@@ -55,3 +55,3 @@ "publishConfig": {

"license": "Apache",
"gitHead": "3f456cd7f92241938769ceee9057f543a2034fd1"
"gitHead": "ffcb4269489cb30dfded592190c4997ff2376c18"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc