This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

basx
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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

Matthieu Jabbour

License

MIT

Copyright (c) Matthieu Jabbour. All Rights Reserved.

Package Sidebar

Install

npm i basx

Weekly Downloads

24

Version

2.0.1

License

MIT

Unpacked Size

20.8 kB

Total Files

13

Last publish

Collaborators

  • openizr2