service-hash

Provides hashing algorithms through a web worker

idleberg

30

1

Bug Reports

0.1.0

MIT

GitHub

This package provides the following services:

service-hash

Provides hashing algorithms through a web worker

apm apm apm CircleCI David

Installation

apm

Install service-hash from Atom install view or use the command-line equivalent:

$ apm install service-hash

Using Git

Change to your Atom packages directory:

Windows

# Powershell
$ cd $Env:USERPROFILE\.atom\packages
:: Command Prompt
$ cd %USERPROFILE%\.atom\packages

Linux & macOS

$ cd ~/.atom/packages/

Clone the repository as service-hash:

$ git clone https://github.com/idleberg/atom-service-hash service-hash

Install dependencies:

$ cd service-hash && npm install

Build source:

$ npm run build

Usage

API

hash(input: string | Buffer | Uint8Array | Uint16Array | Uint32Array, algorithm: string | string[])

Supported algorithms: adler32, blake2b, blake2s, blake3, crc32, keccak224, keccak256, keccak384, keccak512, md4, md5, ripemd160, sha1, sha224, sha256, sha384, sha512, sm3, whirlpool, xxhash32, xxhash64, xxhash3, xxhash128.

Example

To consume the service in your package, add the following to your package.json:

"consumedServices": {
  "service-hash": {
    "versions": {
      "0.1.0": "consumeHash"
    }
  },
  "package-deps": [
    {
      "name": "service-hash"
    }
  ]
}

Install atom-package-deps to handle the package dependency:

npm install atom-package-deps

Next up, let's create a package:

import { CompositeDisposable, Disposable } from 'atom';

export default {
  // Consume the service
  consumeHash(hashService) {
    this.hash = hashService;

    return new Disposable(() => {
      this.hash = null;
    });
  },

  // Optional: Add a demo command
  activate() {
    this.subscriptions = new CompositeDisposable();

    this.subscriptions.add(
      atom.commands.add('atom-workspace', {
        "my-package:demo-command": async () =>
          await this.demoCommand(),
      })
    );
  },

  async demoCommand() {
    await this.hash(`It's demo time!`, 'sha512');
  }
};

Let me know if you have any feedback!

License

This work is licensed under the MIT License