Przeglądaj źródła

Merge pull request #49 from ckeditor/t/ckeditor5/211

Changed const to lower case.
Szymon Cofalik 9 lat temu
rodzic
commit
94fd187a44

+ 6 - 6
packages/ckeditor5-utils/src/comparearrays.js

@@ -11,9 +11,9 @@
  * a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
  * it means that arrays differ.
  *
- *		compareArrays( [ 0, 2 ], [ 0, 2 ] );		// 'SAME'
- *		compareArrays( [ 0, 2 ], [ 0, 2, 1 ] );		// 'PREFIX'
- *		compareArrays( [ 0, 2 ], [ 0 ] );			// 'EXTENSION'
+ *		compareArrays( [ 0, 2 ], [ 0, 2 ] );		// 'same'
+ *		compareArrays( [ 0, 2 ], [ 0, 2, 1 ] );		// 'prefix'
+ *		compareArrays( [ 0, 2 ], [ 0 ] );			// 'extension'
  *		compareArrays( [ 0, 2 ], [ 1, 2 ] );		// 0
  *		compareArrays( [ 0, 2 ], [ 0, 1 ] );		// 1
  *
@@ -35,12 +35,12 @@ export default function compareArrays( a, b ) {
 	// Both arrays were same at all points.
 	if ( a.length == b.length ) {
 		// If their length is also same, they are the same.
-		return 'SAME';
+		return 'same';
 	} else if ( a.length < b.length ) {
 		// Compared array is shorter so it is a prefix of the other array.
-		return 'PREFIX';
+		return 'prefix';
 	} else {
 		// Compared array is longer so it is an extension of the other array.
-		return 'EXTENSION';
+		return 'extension';
 	}
 }

+ 8 - 8
packages/ckeditor5-utils/src/diff.js

@@ -12,7 +12,7 @@
  * Calculates the difference between two arrays or strings producing an array containing a list of changes
  * necessary to transform input into output.
  *
- *		diff( 'aba', 'acca' ); // [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ]
+ *		diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
  *
  * @method utils.diff
  * @param {Array|String} a Input array or string.
@@ -27,7 +27,7 @@ export default function diff( a, b, cmp ) {
 		};
 
 	// Temporary action type statics.
-	let _INSERT, _DELETE;
+	let _insert, _delete;
 
 	// Swapped the arrays to use the shorter one as the first one.
 	if ( b.length < a.length ) {
@@ -37,11 +37,11 @@ export default function diff( a, b, cmp ) {
 		b = tmp;
 
 		// We swap the action types as well.
-		_INSERT = 'DELETE';
-		_DELETE = 'INSERT';
+		_insert = 'delete';
+		_delete = 'insert';
 	} else {
-		_INSERT = 'INSERT';
-		_DELETE = 'DELETE';
+		_insert = 'insert';
+		_delete = 'delete';
 	}
 
 	const m = a.length;
@@ -73,7 +73,7 @@ export default function diff( a, b, cmp ) {
 		}
 
 		// Push the action.
-		es[ k ].push( y1 > y2 ? _INSERT : _DELETE );
+		es[ k ].push( y1 > y2 ? _insert : _delete );
 
 		// Set the beginning coordinates.
 		let y = Math.max( y1, y2 );
@@ -84,7 +84,7 @@ export default function diff( a, b, cmp ) {
 			x++;
 			y++;
 			// Push no change action.
-			es[ k ].push( 'EQUAL' );
+			es[ k ].push( 'equal' );
 		}
 
 		return y;

+ 10 - 10
packages/ckeditor5-utils/src/difftochanges.js

@@ -14,9 +14,9 @@
  *		const changes = diffToChanges( diff( input, output ), output );
  *
  *		changes.forEach( change => {
- *			if ( change.type == 'INSERT' ) {
+ *			if ( change.type == 'insert' ) {
  *				input.splice( change.index, 0, ...change.values );
- *			} else if ( change.type == 'DELETE' ) {
+ *			} else if ( change.type == 'delete' ) {
  *				input.splice( change.index, change.howMany );
  *			}
  *		} );
@@ -24,7 +24,7 @@
  *		input.join( '' ) == output.join( '' ); // -> true
  *
  * @method utils.diffToChanges
- * @param {Array.<'EQUAL'|'INSERT'|'DELETE'>} diff Result of {@link utils.diff}.
+ * @param {Array.<'equal'|'insert'|'delete'>} diff Result of {@link utils.diff}.
  * @param {String|Array} output The string or array which was passed as diff's output.
  * @returns {Array.<Object>} Set of changes (insert or delete) which need to be applied to the input
  * in order to transform it into the output.
@@ -35,32 +35,32 @@ export default function diffToChanges( diff, output ) {
 	let lastOperation;
 
 	diff.forEach( change => {
-		if ( change == 'EQUAL' ) {
+		if ( change == 'equal' ) {
 			pushLast();
 
 			index++;
-		} else if ( change == 'INSERT' ) {
-			if ( isContinuationOf( 'INSERT' ) ) {
+		} else if ( change == 'insert' ) {
+			if ( isContinuationOf( 'insert' ) ) {
 				lastOperation.values.push( output[ index ] );
 			} else {
 				pushLast();
 
 				lastOperation = {
-					type: 'INSERT',
+					type: 'insert',
 					index: index,
 					values: [ output[ index ] ]
 				};
 			}
 
 			index++;
-		} else /* if ( change == 'DELETE' ) */ {
-			if ( isContinuationOf( 'DELETE' ) ) {
+		} else /* if ( change == 'delete' ) */ {
+			if ( isContinuationOf( 'delete' ) ) {
 				lastOperation.howMany++;
 			} else {
 				pushLast();
 
 				lastOperation = {
-					type: 'DELETE',
+					type: 'delete',
 					index: index,
 					howMany: 1
 				};

+ 6 - 6
packages/ckeditor5-utils/tests/comparearrays.js

@@ -9,31 +9,31 @@ import compareArrays from '/ckeditor5/utils/comparearrays.js';
 
 describe( 'utils', () => {
 	describe( 'compareArrays', () => {
-		it( 'should return SAME flag, when arrays are same', () => {
+		it( 'should return same flag, when arrays are same', () => {
 			let a = [ 'abc', 0, 3 ];
 			let b = [ 'abc', 0, 3 ];
 
 			let result = compareArrays( a, b );
 
-			expect( result ).to.equal( 'SAME' );
+			expect( result ).to.equal( 'same' );
 		} );
 
-		it( 'should return PREFIX flag, when all n elements of first array are same as n first elements of the second array', () => {
+		it( 'should return prefix flag, when all n elements of first array are same as n first elements of the second array', () => {
 			let a = [ 'abc', 0 ];
 			let b = [ 'abc', 0, 3 ];
 
 			let result = compareArrays( a, b );
 
-			expect( result ).to.equal( 'PREFIX' );
+			expect( result ).to.equal( 'prefix' );
 		} );
 
-		it( 'should return EXTENSION flag, when n first elements of first array are same as all elements of the second array', () => {
+		it( 'should return extension flag, when n first elements of first array are same as all elements of the second array', () => {
 			let a = [ 'abc', 0, 3 ];
 			let b = [ 'abc', 0 ];
 
 			let result = compareArrays( a, b );
 
-			expect( result ).to.equal( 'EXTENSION' );
+			expect( result ).to.equal( 'extension' );
 		} );
 
 		it( 'should return index on which arrays differ, when arrays are not the same', () => {

+ 8 - 8
packages/ckeditor5-utils/tests/diff.js

@@ -1,5 +1,5 @@
 /**
- * @license Copyright (c) 2003-20'INSERT'6, CKSource - Frederico Knabben. All rights reserved.
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  * For licensing, see LICENSE.md.
  */
 
@@ -9,27 +9,27 @@ import diff from '/ckeditor5/utils/diff.js';
 
 describe( 'diff', () => {
 	it( 'should diff strings', () => {
-		expect( diff( 'aba', 'acca' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ] );
+		expect( diff( 'aba', 'acca' ) ).to.deep.equals( [ 'equal', 'insert', 'insert', 'delete', 'equal' ] );
 	} );
 
 	it( 'should diff arrays', () => {
-		expect( diff( Array.from( 'aba' ), Array.from( 'acca' ) ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'INSERT', 'DELETE', 'EQUAL' ] );
+		expect( diff( Array.from( 'aba' ), Array.from( 'acca' ) ) ).to.deep.equals( [ 'equal', 'insert', 'insert', 'delete', 'equal' ] );
 	} );
 
 	it( 'should reverse result if the second string is shorter', () => {
-		expect( diff( 'acca', 'aba' ) ).to.deep.equals( [ 'EQUAL', 'DELETE', 'DELETE', 'INSERT', 'EQUAL' ] );
+		expect( diff( 'acca', 'aba' ) ).to.deep.equals( [ 'equal', 'delete', 'delete', 'insert', 'equal' ] );
 	} );
 
 	it( 'should diff if strings are same', () => {
-		expect( diff( 'abc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
+		expect( diff( 'abc', 'abc' ) ).to.deep.equals( [ 'equal', 'equal', 'equal' ] );
 	} );
 
 	it( 'should diff if one string is empty', () => {
-		expect( diff( '', 'abc' ) ).to.deep.equals( [ 'INSERT', 'INSERT', 'INSERT' ] );
+		expect( diff( '', 'abc' ) ).to.deep.equals( [ 'insert', 'insert', 'insert' ] );
 	} );
 
 	it( 'should use custom comparator', () => {
-		expect( diff( 'aBc', 'abc' ) ).to.deep.equals( [ 'EQUAL', 'INSERT', 'DELETE', 'EQUAL' ] );
-		expect( diff( 'aBc', 'abc', ( a, b ) => a.toLowerCase() == b.toLowerCase() ) ).to.deep.equals( [ 'EQUAL', 'EQUAL', 'EQUAL' ] );
+		expect( diff( 'aBc', 'abc' ) ).to.deep.equals( [ 'equal', 'insert', 'delete', 'equal' ] );
+		expect( diff( 'aBc', 'abc', ( a, b ) => a.toLowerCase() == b.toLowerCase() ) ).to.deep.equals( [ 'equal', 'equal', 'equal' ] );
 	} );
 } );

+ 4 - 4
packages/ckeditor5-utils/tests/difftochanges.js

@@ -53,9 +53,9 @@ describe( 'diffToChanges', () => {
 		const changes = diffToChanges( diff( input, output ), output );
 
 		changes.forEach( change => {
-			if ( change.type == 'INSERT' ) {
+			if ( change.type == 'insert' ) {
 				input.splice( change.index, 0, ...change.values );
-			} else if ( change.type == 'DELETE' ) {
+			} else if ( change.type == 'delete' ) {
 				input.splice( change.index, change.howMany );
 			}
 		} );
@@ -70,9 +70,9 @@ describe( 'diffToChanges', () => {
 			const oldStrChars = Array.from( oldStr );
 
 			changes.forEach( change => {
-				if ( change.type == 'INSERT' ) {
+				if ( change.type == 'insert' ) {
 					oldStrChars.splice( change.index, 0, ...change.values );
-				} else if ( change.type == 'DELETE' ) {
+				} else if ( change.type == 'delete' ) {
 					oldStrChars.splice( change.index, change.howMany );
 				}
 			} );