Install with yarn or npm:
yarn
ornpm
:
# yarn
yarn add nest-shared
# npm
npm i nest-shared --save
// es6
import shared from 'nest-shared';
// cjs
const shared = require('nest-shared');
#!/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`);
});
#!/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
#!/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
#!/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!
βββ 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
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a βοΈ if this project helped you!
Or buy me a coffee ππΎ
Copyright Β© 2023 Hebert F Barros.
This project is MIT licensed.