2.0.1 • Published 2 years ago
basx v2.0.1
basx
A set of useful helpers for JS projects.
Table of Contents
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
Copyright (c) Matthieu Jabbour. All Rights Reserved.