mirror of https://github.com/abpframework/abp.git
2 changed files with 25 additions and 2 deletions
@ -0,0 +1,10 @@ |
|||
import { generateHash } from '../utils'; |
|||
|
|||
describe('GeneratorUtils', () => { |
|||
describe('#generateHash', () => { |
|||
test('should generate a hash', async () => { |
|||
const hash = generateHash('some content \n with second line'); |
|||
expect(hash).toBe(1112440527); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -1,6 +1,19 @@ |
|||
// tslint:disable: no-bitwise
|
|||
|
|||
export function uuid(a?: any): string { |
|||
return a |
|||
? // tslint:disable-next-line: no-bitwise
|
|||
(a ^ ((Math.random() * 16) >> (a / 4))).toString(16) |
|||
? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16) |
|||
: ('' + 1e7 + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid); |
|||
} |
|||
|
|||
export function generateHash(value: string): number { |
|||
let hashed = 0; |
|||
let charCode: number; |
|||
|
|||
for (let i = 0; i < value.length; i++) { |
|||
charCode = value.charCodeAt(i); |
|||
hashed = (hashed << 5) - hashed + charCode; |
|||
hashed |= 0; |
|||
} |
|||
return hashed; |
|||
} |
|||
|
|||
Loading…
Reference in new issue