From 86e421d4b79fdb97cb5a4718a308b361476de1d2 Mon Sep 17 00:00:00 2001 From: Simon Guo Date: Fri, 11 Nov 2022 16:56:24 +0800 Subject: [PATCH] fix(camelizeStyleName): fix ms prefix should be lowercase (#60) --- src/utils/camelizeStyleName.ts | 8 ++++++-- test/utilsSpec.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/utilsSpec.js diff --git a/src/utils/camelizeStyleName.ts b/src/utils/camelizeStyleName.ts index 2d43cbb..aa1d48b 100644 --- a/src/utils/camelizeStyleName.ts +++ b/src/utils/camelizeStyleName.ts @@ -1,5 +1,9 @@ import { camelize } from './stringFormatter'; -const msPattern = /^ms-/; +const msPattern = /^-ms-/; -export default (name: string) => camelize(name.replace(msPattern, 'ms-')); +export default function camelizeStyleName(name: string) { + // The `-ms` prefix is converted to lowercase `ms`. + // http://www.andismith.com/blog/2012/02/modernizr-prefixed/ + return camelize(name.replace(msPattern, 'ms-')); +} diff --git a/test/utilsSpec.js b/test/utilsSpec.js new file mode 100644 index 0000000..42a06d8 --- /dev/null +++ b/test/utilsSpec.js @@ -0,0 +1,14 @@ +import camelizeStyleName from '../src/utils/camelizeStyleName'; + +describe('Utils', () => { + describe('camelizeStyleName', () => { + // https://www.andismith.com/blogs/2012/02/modernizr-prefixed/ + it('Should return the correct Modernizr prefix', () => { + expect(camelizeStyleName('-ms-transform')).to.equal('msTransform'); + expect(camelizeStyleName('-moz-transform')).to.equal('MozTransform'); + expect(camelizeStyleName('-o-transform')).to.equal('OTransform'); + expect(camelizeStyleName('-webkit-transform')).to.equal('WebkitTransform'); + expect(camelizeStyleName('transform')).to.equal('transform'); + }); + }); +});