0.5.1 • Published 2 years ago

@alarife/utils v0.5.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

alarife-utils

Library with similar utilities for the different components and plugins that make up the Alarife project.

Decorators

@Value

Value is a field decorator. @Value manages a store of data that you can inject into your classes.

valueStore.set('ip', '0.0.0.0')

class Main {

  @Value('core.ip') ip;

  constructor() {
    this.log.info('server ip: ' this.ip);
  }
}

ValueStore

You can save your own values to reuse them in your app.

// Store options
ValueStore.set('mongoose.url', mongooseUrl)
ValueStore.merge('mongoose.configuration', { ... }) // Merge over existing objects
ValueStore.get('mongoose.url')
ValueStore.delete('mongoose.url')

@Logger

Logger is a class decorator. Insert the entire Logger module to the class.

@Logger
class Service {
  constructor() {
    this.log.info('Message');
  }
}

Modules

DeveloperError

Exception Management for Development

  throw new DeveloperError('The Service Document can only be applied to classes.');

Logger

The App, Controller, and Service decorators add this functionality. Future plugin for server log and access log management

Morgan is used as a library for access log.

Configurations:

  • Allows different output levels ('info', 'debug', 'error', 'warn').
this.log.info('New message');
this.log.error('Error message', error);
this.log.warn('Warn message');

Lombok

Developing Proposal for a decorator based on Lombok to decorate classes in javascript.

Utils

Type validation capabilities

  /** return true or false */
  isDefined(value);
  isFunction(value);
  isClass(value);
  isObject(value);
  isString(value);
  isNumber(value);

Object functionalities

  defineProperty(prototype, key, value);
  merge(target, source);

File Features

  getFile(path); // file data
  getFiles(path);
  includesFile(path, key); // checks if a text exists in a file
  existsFile(path);
  createWriteStream(path);
  createFolder(path);
  writeFile(path, data);
0.5.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago