npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nest-shared

v5.0.6

Published

Shared code for nestjs projects

Downloads

270

Readme

codecov

Open in Gitpod

Node.js Package

Running Code Coverage

📝 Update Lock

Installation

Install with yarn or npm: yarn or npm:

# yarn
yarn add nest-shared
# npm
npm i nest-shared --save

Import the lib with es6 or cjs:

// es6
import shared from 'nest-shared';
// cjs
const shared = require('nest-shared');

Usage examples:

Express usage

#!/usr/bin/env node
import { configService } from 'nest-shared';
import express, { Router } from 'express';

const app = express();
const router = Router();

router.get('/', (req, res) => {
  return res.send('Test');
});

app.use(router);
const port = configService.getPort();

app.listen(port, () => {
  process.stdout.write(`Server is running on port ${port}\n`);
});

Constants

#!/usr/bin/env node
import {
  NODE_PORT,
  CACHE_TTL,
  CACHE_TTL_50_SEC,
  API_HEADER_OPTIONS,
  WEBSOCKET_PORT,
  VALID_UUID_REGEX,
} from 'nest-shared';

console.log('NODE_PORT', NODE_PORT); // 4000
console.log('CACHE_TTL', CACHE_TTL); // 3600
console.log('CACHE_TTL_50_SEC', CACHE_TTL_50_SEC); // 50
console.log('API_HEADER_OPTIONS', API_HEADER_OPTIONS); // []
console.log('WEBSOCKET_PORT', WEBSOCKET_PORT); // 4001
console.log('VALID_UUID_REGEX', VALID_UUID_REGEX.test('28aebbd6-173b-4375-99eb-56dc04ec2bcb')); // true

Helpers

generateAPIKey
#!/usr/bin/env node
import { generateAPIKey } from 'nest-shared';

const api_key = generateAPIKey({
  str: 'Hello World',
  prefix: 'apk',
  digest: 'hex',
  size: 32,
});
console.log('api_key', api_key); // apk_f9cfa3c29500449828aebc910ce1d328
YourClass implements BufferBase
#!/usr/bin/env node
import { BufferBase } from 'nest-shared';
import { Buffer } from 'buffer';
import type { EncodeDataType, DecodeStrType } from 'nest-shared/lib/shared/types/buffer.type';

console.log(BufferBase.name); // BufferBase

class BufferBaseImpl implements BufferBase {
  encode(data: EncodeDataType): string {
    return Buffer.from(data).toString('base64');
  }
  decode(str: DecodeStrType): string {
    return Buffer.from(str, 'utf-8').toString('utf-8');
  }
}

const bufferBaseImpl = new BufferBaseImpl();

const content = 'Hello World!';

console.log(bufferBaseImpl.encode(content)); // SGVsbG8gV29ybGQh
console.log(bufferBaseImpl.decode(content)); // Hello World!

File structure

├── src
│   ├── common
│   │   ├── base
│   │   │   ├── buffer-base.ts
│   │   │   ├── class-base.ts
│   │   │   ├── crud-base.ts
│   │   ├── constants
│   │   │   ├── global.constants.ts
│   │   │   └── regex.constants.ts
│   │   ├── entity
│   │   │   ├── global-common.entity.ts
│   │   │   └── user.common.entity.ts
│   │   └── interfaces
│   │       ├── app-service.interface.ts
│   │       ├── http.responses.interface.ts
│   │       └── type-orm.interface.ts
│   ├── config
│   │   ├── application.config.ts
│   ├── modules
│   │   ├── file
│   │   │   ├── interfaces
│   │   │   │   ├── file.interface.ts
│   │   │   ├── services
│   │   │   │   ├── file.service.ts
│   │   │   └── types
│   │   │       └── file.type.ts
│   ├── shared
│   │   ├── helpers
│   │   │   ├── class
│   │   │   │   ├── getKeyFromClass.ts
│   │   │   ├── crypto
│   │   │   │   ├── Base64.ts
│   │   │   │   ├── generateAPIKey.ts
│   │   │   ├── fs
│   │   │   │   └── parseFile.ts
│   │   │   ├── http
│   │   │   │   ├── axiosErrorHandler.ts
│   │   │   │   ├── handleWithAxiosResponse.ts
│   │   │   │   └── parseQueryParams.ts
│   │   │   ├── math
│   │   │   │   ├── RandomNumber.ts
│   │   │   │   └── sum.ts
│   │   │   └── time
│   │   │       ├── date-handle.ts
│   │   └── types
│   │       ├── buffer.type.ts
│   │       ├── class.type.ts
│   │       ├── crud-base.type.ts
│   └── @types
│       └── unique-slug

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

Or buy me a coffee 🙌🏾

📝 License

Copyright © 2023 Hebert F Barros. This project is MIT licensed.