Skip to content

Commit

Permalink
fix(hippy-vue): fixed tryConvertNumber bug & some compatible issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomchan-cxj authored and ilikethese committed Nov 11, 2020
1 parent eb889bf commit ba8836d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions packages/hippy-vue-native-components/src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ function registerAnimation(Vue) {
let animationIds = Object.keys(otherStyles).map(key => style[key].animationId);
if (Array.isArray(transform) && transform.length > 0) {
const transformIds = [];
transform.forEach(entity => Object.values(entity)
.forEach(value => Number.isInteger(value.animationId)
&& transformIds.push(value.animationId)));
transform.forEach(entity => Object.keys(entity)
.forEach((key) => {
if (entity[key]) {
const { animationId } = entity[key];
if (typeof animationId === 'number' && animationId % 1 === 0) {
transformIds.push(animationId);
}
}
}));
animationIds = [...animationIds, ...transformIds];
}
return animationIds;
Expand Down
2 changes: 1 addition & 1 deletion packages/hippy-vue/src/util/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('tryConvertNumber output test', (t) => {
t.is(util.tryConvertNumber(123), 123);
t.is(util.tryConvertNumber('123'), 123);
t.is(util.tryConvertNumber('abc'), 'abc');
t.is(util.tryConvertNumber('123abc'), '123abc');
t.is(util.tryConvertNumber('123abc'), 123);
t.is(util.tryConvertNumber('abc123'), 'abc123');
const obj = {};
t.is(util.tryConvertNumber(obj), obj);
Expand Down
7 changes: 4 additions & 3 deletions packages/hippy-vue/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ function capitalizeFirstLetter(str) {
/**
* Convert string to number as possible
*/
const numberRegEx = new RegExp('^[+-]?(\\d+)?(\\.\\d+)?$');
// const numberRegEx = new RegExp('^[+-]?(\\d+)?(\\.\\d+)?$');
function tryConvertNumber(str) {
if (typeof str === 'number') {
return str;
}
if (typeof str === 'string' && numberRegEx.test(str)) {
if (typeof str === 'string') {
try {
return parseFloat(str);
const parsedNumber = parseFloat(str);
if (!Number.isNaN(parsedNumber)) return parsedNumber;
} catch (err) {
// pass
}
Expand Down

0 comments on commit ba8836d

Please sign in to comment.