GithubHelp home page GithubHelp logo

hebertcisco / nest-shared Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 2.49 MB

Shared code for nestjs projects: https://www.npmjs.com/package/nest-shared

Home Page: https://www.npmjs.com/package/nest-shared

License: MIT License

JavaScript 5.75% TypeScript 94.25%
nest nested-structures nestjs nestjs-backend nodejs typescript express

nest-shared's Introduction

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.

nest-shared's People

Contributors

dependabot[bot] avatar favelado-web avatar hebertcisco avatar

Stargazers

 avatar

Watchers

 avatar

nest-shared's Issues

[email protected]: Multer 1.x is affected by CVE-2022-24434.

This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.