2.0.1 • Published 2 years ago

basx v2.0.1

Weekly downloads
57
License
MIT
Repository
github
Last release
2 years ago

basx

A set of useful helpers for JS projects.

Build Status Coverage Status npm node Downloads

Table of Contents

  1. Installation
  2. Usage
  3. API documentation
  4. Contributing
  5. Sponsor
  6. Maintainers
  7. License

Installation

yarn add basx

Usage

basx

// main.js
// --------------------------

import { deepMerge, deepCopy } from 'basx';

const objectA = {
  propA: {
    propAA: 'test',
  },
  propB: ['test'],
  propC: 'test',
};

const objectB = {
  propA: {
    propAB: 'test',
  },
  propB: ['testB'],
  propC: 'testB',
};

const objectACopy = deepCopy(objectA);
console.log(objectA === objectACopy, objectA.propA === objectACopy.propA); // false, false

const mergedObject = deepMerge(objectA, objectB);
console.log(mergedObject); // { propA: { propAA: 'test', propAB: 'test' }, propB: ['test, 'testB'], propC: 'testB' }

basx/i18n

// main.js
// --------------------------

import i18n from 'basx/i18n';

i18n();
const locale = { LABEL_ANONYMOUS: "Welcome anonymous!", LABEL_HOME: "Welcome {{user}}!" };
console.log(locale.LABEL_ANONYMOUS); // "Welcome anonymous!"
console.log(locale.LABEL_HOME.t({ user: 'Charles' })); // "Welcome Charles!"

basx/requester

// main.js
// --------------------------

import requester from 'basx/requester';

const request = requester({
  baseUri: 'https://test.com',
  shouldMock: (process.env.NODE_ENV !== 'production'),
  mockedResponses: {
    'GET /test': {
      codes: [201, 401],
      durations: [250, 300],
      responses: [{ test: 'ok' }],
    },
  },
});

request({ endpoint: '/test', method: 'GET' }).then((response) => {
  console.log(response); // Will be the real HTTP response in production mode, '{ data: { "test": "ok" } }' in any other mode
});
request({ endpoint: '/test', method: 'GET' }).catch((error) => {
  console.log(error); // Will be the real HTTP error in production mode, '' in any other mode
});

API documentation

You can find the complete API documentation here

Contributing

You're free to contribute to this project by submitting issues and/or pull requests. For more information, please read the Contribution guide.

Sponsor

Love this project and want to support it? You can buy me a coffee :)

Or just sending me a quick message saying "Thanks" is also very gratifying, and keeps me motivated to maintain open-source projects I work on!

Maintainers

License

MIT

Copyright (c) Matthieu Jabbour. All Rights Reserved.

2.0.1

2 years ago

2.0.0

2 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago

0.0.1

4 years ago