Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
/ basx Public archive

A set of useful helpers for JS/TS projects

License

Notifications You must be signed in to change notification settings

openizr/basx

Repository files navigation

⚠️ Please use @perseid/core instead

This NPM package is deprecated and no longer maintained. @perseid/store is the new official repository.

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.