nest-shared v5.0.6
Installation
Install with yarn or npm:
yarn
ornpm
:
# 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.
11 months ago
12 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago