Skip to content

Latest commit

 

History

History
154 lines (104 loc) · 3.82 KB

README.md

File metadata and controls

154 lines (104 loc) · 3.82 KB

tornavida
Tools to make a Javascript developer's life easier

Build Status Coverage Status CodeFactor NPM JavaScript Style Guide npm bundle size NPM

🕺 Install

by using npm :

npm i tornavida

by using yarn :

yarn add tornavida

This repository has 3 general-purposes packages. Those are:

  • math
  • text
  • util

The priority of tornavida is to provide convenience for applications that uses ECMAScript modules.

If you want to use tornavida with cjs ( CommonJS ) modules in NodeJS (nodejs uses commonjs as a module system.) one thing you must do that follows the syntax as listed below.

For example, we assume that you would like to use a module from the util package.

Import Syntax

For ECMAScript Modules

Let's take a look at the syntax we should follow when using ECMAScript modules.

import { sortAscByField } from 'tornavida/util';
// import { sortAscByField } from 'tornavida';  (1)

const array = [
   {id: 10, text: '10'},
   {id: 15, text: '15'},
   {id: 25, text: '25'}
];

const sortedArray = sortAscByField(array, 'id');

(1) This is also valid but you should use follow the syntax which listed above <tornavida>/<package-name>. If you don't have any concerns about performance you could also use that import statement without subpackage indicator.

Output

[
  { id: 10, text: '10' },
  { id: 15, text: '15' },
  { id: 25, text: '25' }
]

For CommonJS Modules

Let's take a look at the syntax we should follow when using CommonJS modules.

You can import CommonJS modules as follows tornavida/<package-name>/cjs

This syntax is valid for all packages that tornavida has.

const { sortDescByField } = require('tornavida/util/cjs');

const array = [
    { id: 10, text: '10' },
    { id: 15, text: '15' },
    { id: 25, text: '25' }
];

const sortedDescArray = sortDescByField(array, 'id');

Output

[
  { id: 25, text: '25' },
  { id: 15, text: '15' },
  { id: 10, text: '10' }
]

📦 Packages

math

fieldMax(arr: any[], prop: string): number

Assume that you're just wondering what is the maximum value of the property that array has.

import { fieldMax } from 'tornavida/math';

const arr = [
    { uuid: 1923 },
    { uuid: 1444 },
    { uuid: 1363 },
    { uuid: 1071 }
];

const maxValueOfGivenProp = fieldMax(arr, 'uuid'); // 1923

random(min: number, max: number): number

random function generates random integer value.

import { random } from 'tornavida/math';

const randomInteger = random(1, 10); // Generates random integers between 1 to 10

License

MIT © enesusta