浏览代码

Renamed dom/topx to dom/tounit which allows any kind of a unit.

Aleksander Nowodzinski 9 年之前
父节点
当前提交
7145693994

+ 0 - 13
packages/ckeditor5-utils/src/dom/topx.js

@@ -1,13 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * Adds `px` unit to the passed value.
- *
- * @method utils.dom.toPx
- * @param {*} value A value to be "pixelized".
- * @returns {String} A value with the trailing "px" unit.
- */
-export default ( value ) => `${ value }px`;

+ 24 - 0
packages/ckeditor5-utils/src/dom/tounit.js

@@ -0,0 +1,24 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * Returns a helper function, which adds a desired trailing
+ * `unit` to the passed value.
+ *
+ * @method utils.dom.toUnit
+ * @param {String} unit An unit like "px" or "em".
+ * @returns {utils.dom.toUnit.helper}
+ */
+export default function toUnit( unit ) {
+	/**
+	 * A function, which adds a pre–defined trailing `unit`
+	 * to the passed `value`.
+	 *
+	 * @function utils.dom.toUnit.helper
+ 	 * @param {*} value A value to be given the unit.
+ 	 * @returns {String} A value with the trailing unit.
+	 */
+	return ( value ) => value + unit;
+}

+ 0 - 21
packages/ckeditor5-utils/tests/dom/topx.js

@@ -1,21 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* bender-tags: dom */
-
-import toPx from '/ckeditor5/utils/dom/topx.js';
-
-describe( 'toPx', () => {
-	it( 'should be a function', () => {
-		expect( toPx ).to.be.a( 'function' );
-	} );
-
-	it( 'should always pixelize the value', () => {
-		expect( toPx( null ) ).to.equal( 'nullpx' );
-		expect( toPx( undefined ) ).to.equal( 'undefinedpx' );
-		expect( toPx( '10' ) ).to.equal( '10px' );
-		expect( toPx( 10 ) ).to.equal( '10px' );
-	} );
-} );

+ 27 - 0
packages/ckeditor5-utils/tests/dom/tounit.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: dom */
+
+import toUnit from '/ckeditor5/utils/dom/tounit.js';
+
+describe( 'toUnit', () => {
+	it( 'should be a function', () => {
+		expect( toUnit ).to.be.a( 'function' );
+	} );
+
+	it( 'should return a helper function', () => {
+		expect( toUnit( 'foo' ) ).to.be.a( 'function' );
+	} );
+
+	describe( 'helper function', () => {
+		it( 'should always add a trailing unit to the value', () => {
+			expect( toUnit( 'px' )( null ) ).to.equal( 'nullpx' );
+			expect( toUnit( 'em' )( undefined ) ).to.equal( 'undefinedem' );
+			expect( toUnit( 'rem' )( '10' ) ).to.equal( '10rem' );
+			expect( toUnit( '' )( 10 ) ).to.equal( '10' );
+		} );
+	} );
+} );