5.0.4 ā€¢ Published 4 months ago

nest-shared v5.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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.

5.0.4

4 months ago

5.0.3

10 months ago

5.0.2

1 year ago

0.4.62

1 year ago

0.4.60

1 year ago

5.0.1

1 year ago

0.4.61

1 year ago

5.0.0

1 year ago

0.4.54

1 year ago

0.4.59

1 year ago

0.4.57

1 year ago

0.4.58

1 year ago

0.4.55

1 year ago

0.4.56

1 year ago

0.4.53

2 years ago

0.4.51

2 years ago

0.4.52

2 years ago

0.4.5

2 years ago

0.3.9

2 years ago

0.3.6

2 years ago

0.4.4

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.4.1

2 years ago

0.3.2

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.4.3

2 years ago

0.3.4

2 years ago

0.4.2

2 years ago

0.3.3

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago