Ejemplo n.º 1
0
	it( 'should produce deterministic strings regardless of attribute or array order', function() {
		var options, optionsDifferentSort;
		options = {
			b: [ 2, 1 ],
			a: true
		};
		optionsDifferentSort = {
			a: true,
			b: [ 1, 2 ]
		};
		assert.equal( deterministicStringify( options ), deterministicStringify( optionsDifferentSort ) );
	} );
Ejemplo n.º 2
0
export const generateKey = ( params, applyHash = true ) => {
	var key = `${params.apiVersion || ''}-${params.method}-${params.path}`;

	if ( params.query ) {
		// sort parameters alphabetically
		key += '-' + deterministicStringify( qs.parse( params.query ) );
	}

	if ( applyHash ) {
		key = new Hashes.SHA1().hex( key );
	}

	key = SYNC_RECORD_NAMESPACE + key;
	return key;
}
Ejemplo n.º 3
0
function getNamespace( fetchOptions ) {
	return deterministicStringify( omit( fetchOptions, [ 'page', 'max' ] ) );
}
Ejemplo n.º 4
0
function getNamespace( fetchOptions ) {
	return deterministicStringify( omit( fetchOptions, [ 'number', 'offset' ] ) );
}
Ejemplo n.º 5
0
	it( 'should handle number', function() {
		assert.equal( '1', deterministicStringify( 1 ) );
	} );
Ejemplo n.º 6
0
	it( 'should handle boolean', function() {
		assert.equal( 'true', deterministicStringify( true ) );
		assert.equal( 'false', deterministicStringify( false ) );
	} );
Ejemplo n.º 7
0
	it( 'should alphabetize object attributes', function() {
		assert.equal( "a='a','b'&b=1", deterministicStringify( { b: 1, a: [ 'b', 'a' ] } ) );
	} );
Ejemplo n.º 8
0
	it( 'should allow nesting and sort nested arrays', function() {
		assert.equal( "a='a','blah','c'", deterministicStringify( { a: [ 'blah', 'a', 'c' ] } ) );
	} );
Ejemplo n.º 9
0
	it( 'should handle boolean as object values', function() {
		assert.equal( 'a=true', deterministicStringify( { a: true } ) );
	} );
Ejemplo n.º 10
0
	it( 'should handle nested objects', function() {
		assert.equal( '1,a=1', deterministicStringify( [ 1, { a: 1 } ] ) );
	} );
Ejemplo n.º 11
0
	it( 'should sort arrays', function() {
		assert.equal( '1,2,3', deterministicStringify( [ 2, 1, 3 ] ) );
	} );
Ejemplo n.º 12
0
	it( 'should handle undefined', function() {
		assert.equal( 'undefined', deterministicStringify( undefined ) );
	} );
Ejemplo n.º 13
0
	it( 'should handle null', function() {
		assert.equal( 'null', deterministicStringify( null ) );
	} );