Skip to content

Commit

Permalink
* Support byte array input.
Browse files Browse the repository at this point in the history
* Remove ascii parameter.
* Improve performance.
* Add test cases.
  • Loading branch information
emn178 committed Feb 16, 2015
1 parent 4122482 commit 72f01d0
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 174 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ node_js:
- "0.11"
- "0.10"
- "0.8"
install:
before_install:
- npm install mocha -g
- npm install coveralls -g
- npm install mocha-lcov-reporter -g
- npm install
script:
- npm run-script coveralls
script: npm run-script coveralls
branches:
only:
- master
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.2.0 / 2015-02-16

* Support byte array input.
* Remove ascii parameter.
* Improve performance.
* Add test cases.

# v0.1.3 / 2015-01-07

* Add bower package.
Expand Down
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# js-sha1
[![Build Status](https://api.travis-ci.org/emn178/js-sha1.png)](https://travis-ci.org/emn178/js-sha1)
[![Build Status](https://coveralls.io/repos/emn178/js-sha1/badge.png?branch=master)](https://coveralls.io/r/emn178/js-sha1?branch=master)
[![Build Status](https://travis-ci.org/emn178/js-sha1.svg?branch=master)](https://travis-ci.org/emn178/js-sha1)
[![Coverage Status](https://coveralls.io/repos/emn178/js-sha1/badge.svg?branch=master)](https://coveralls.io/r/emn178/js-sha1?branch=master)
[![NPM](https://nodei.co/npm/js-sha1.png?stars&downloads)](https://nodei.co/npm/js-sha1/)
A simple SHA1 hash function for JavaScript supports UTF-8 encoding.

Expand Down Expand Up @@ -30,20 +30,6 @@ If you use node.js, you should require the module first:
sha1 = require('js-sha1');
```

### Methods

#### sha1(str, asciiOnly)

Hash string to sha1, set asciiOnly to true for better performace if you ensure input is ascii.

##### *str: `String`*

String to hash.

##### *asciiOnly: `Boolean` (default: `false`)*

Specify the string encoding is ASCII.

## Example
Code
```JavaScript
Expand All @@ -67,13 +53,25 @@ Output

7be2d2d20c106eee0836c9bc2b939890a78e8fb3

It also supports byte Array or Uint8Array input:

Code
```JavaScript
sha1([]);
sha1(new Uint8Array([]));
```
Output

da39a3ee5e6b4b0d3255bfef95601890afd80709
da39a3ee5e6b4b0d3255bfef95601890afd80709

## Extensions
### jQuery
If you prefer jQuery style, you can add following code to add a jQuery extension.

Code
```JavaScript
jQuery.sha1 = sha1
jQuery.sha1 = sha1;
```
And then you could use like this:
```JavaScript
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-sha1",
"version": "0.1.3",
"version": "0.2.0",
"main": ["build/sha1.min.js"],
"ignore": [
"samples",
Expand Down
9 changes: 6 additions & 3 deletions build/sha1.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-sha1",
"version": "0.1.3",
"version": "0.2.0",
"description": "A simple SHA1 hash function for JavaScript supports UTF-8 encoding.",
"main": "src/sha1.js",
"devDependencies": {
Expand Down
Loading

0 comments on commit 72f01d0

Please sign in to comment.