-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f9a947
commit 079705f
Showing
8 changed files
with
26 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
declare const sdbm: { | ||
/** | ||
[SDBM](http://www.cse.yorku.ca/~oz/hash.html#sdbm) non-cryptographic hash function. | ||
/** | ||
[SDBM](http://www.cse.yorku.ca/~oz/hash.html#sdbm) non-cryptographic hash function. | ||
@returns The hash as a positive integer. | ||
@returns The hash as a positive integer. | ||
@example | ||
``` | ||
import sdbm = require('sdbm'); | ||
@example | ||
``` | ||
import sdbm from 'sdbm'; | ||
sdbm('🦄🌈'); | ||
//=> 4053542802 | ||
``` | ||
*/ | ||
(string: string): number; | ||
|
||
// TODO: remove this in the next major version, refactor the whole definition to: | ||
// declare function sdbm(string: string): number; | ||
// export = sdbm; | ||
default: typeof sdbm; | ||
}; | ||
|
||
export = sdbm; | ||
sdbm('🦄🌈'); | ||
//=> 4053542802 | ||
``` | ||
*/ | ||
export default function sfbm(string: string): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
'use strict'; | ||
|
||
const sdbm = string => { | ||
export default function sdbm(string) { | ||
let hash = 0; | ||
|
||
for (let i = 0; i < string.length; i++) { | ||
hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash; | ||
} | ||
|
||
// Convert it to an unsigned 32-bit integer | ||
// Convert it to an unsigned 32-bit integer. | ||
return hash >>> 0; | ||
}; | ||
|
||
module.exports = sdbm; | ||
// TODO: remove this in the next major version | ||
module.exports.default = sdbm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {expectType} from 'tsd'; | ||
import sdbm = require('.'); | ||
import sdbm from './index.js'; | ||
|
||
expectType<number>(sdbm('🦄🌈')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,16 @@ | |
"description": "SDBM non-cryptographic hash function", | ||
"license": "MIT", | ||
"repository": "sindresorhus/sdbm", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
|
@@ -28,8 +31,8 @@ | |
"function" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.1", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters