2.0.0 • Published 2 years ago

@mercury-labs/hashing v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Mercury Hashing

A simple NestJS module package for encoding/decoding string.

Install

npm install --save @mercury-labs/hashing

Register

HashingModule.forRoot({
  secretKey: 'GOo7cVgnCBnR8TvXIgvamXNb85cPVtJi',
  global: false
})

Register async

HashingModule.forRootAsync({
  useFactory: (config: ConfigService) => {
    return {
      secretKey: config.get('HASHING_SECRET_KEY') || '',
    }
  },
  inject: [ConfigService],
  global: false
})

Notes:

  • The secretKey should be 32 characters string.

Sample usages

import { HashTextService } from '@mercury-labs/hashing'
import { Injectable } from '@nestjs/common'

@Injectable()
export class TestService {
  public constructor(private readonly _hashTextService: HashTextService) {
  }

  public sample() {
    const hashed = this._hashTextService.encode('John Doe')

    const decoded = this._hashTextService.decode(hashed)
    
    const hashedObj = this._hashTextService.encodeJSON({
      name: 'John Doe',
      gender: 'male',
    })

    const decodedObj = this._hashTextService.decodeJSON<{
      name: string,
      gender: string
    }>(hashedObj)

    return {
      hashed,
      decoded
    }
  }
}
2.0.0

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago