@bolajiolajide/utils
v1.0.15
Published
<!-- markdownlint-disable MD033 --> <div align="center"> <img src="https://github.com/BolajiOlajide/utils/blob/master/alfred.png?raw=true" alt="alfred avatar" width="500px" /> <p align="center"> </div>
Downloads
20
Maintainers
Readme
@bolajiolajide/utils
Collection of utility functions/helpers I use in my everyday development.
Methods
- value string to be capitalize
const { capitalize } = require('@bolajiolajide/utils');
const data = capitalize('bolaji');
console.log(data);
// 'Bolaji'
- value string slice to convert
- separator string to use to separate the different items in the slice
const { convertSliceToString } = require('@bolajiolajide/utils');
const data = convertSliceToString('bolaji');
console.log(data);
// 'bolaji'
const data2 = convertSliceToString(['bol', 'aji']);
console.log(data2);
// 'bolaji'
const data3 = convertSliceToString(['bol', 'aji', 'pro', 'ton'], '**');
console.log(data3);
// 'bol**aji**pro**ton'
const { countries } = require('@bolajiolajide/utils');
console.log(countries);
// ['Afghanistan', ...]
const { delay } = require('@bolajiolajide/utils');
await delay(10000); // delay for 10seconds
const { generateCSV } = require('@bolajiolajide/utils');
const data = [
{ name: 'John Doe', age: 20 },
{ name: 'Jane Doe', age: 23 }
];
const csv = generateCSV(data);
console.log(csv);
// name, age
// John Doe, 20
// Jane Doe, 23
const { generateShortCode } = require('@bolajiolajide/utils');
const shortcode = generateShortCode(10);
console.log(shortcode);
// 637010000
- value literal to check type
const { isDict } = require('@bolajiolajide/utils');
const data = isDict('bolaji');
console.log(data);
// false
const data2 = isDict({ amount: 230329 });
console.log(data2);
// true
- value literal to check type
const { isString } = require('@bolajiolajide/utils');
const data = isString('bolaji');
console.log(data);
// true
const data2 = isString(230329);
console.log(data2);
// false
- fn the function to be run only once
const { runOnce } = require('@bolajiolajide/utils');
const addTogether = function(num1:number, num2:number):number{
return num1+num2
}
const addTogetherOnce = runOnce(addTogether)
let firstResult = addTogetherOnce(0,1)
let secondResult = addTogetherOnce(0,1)
console.log(firstResult)
console.log(secondResult)
});
// firstResult: 1
// secondResult: undefined
- limit how many items to receive per page
- page page number to be retrieved
- data the array of data to be paginated
const { paginate } = require('@bolajiolajide/utils');
const data = paginate(2, 2, [
'Jane',
'John',
'James',
'Bill',
'Steve',
'Melissa',
'Esther',
'Shannon'
]);
console.log(data);
// ['James', 'Bill']
- word the word/phrase to sentencize
- separator a string separating the words in a phrase, defaults to ' '
const { sentencize } = require('@bolajiolajide/utils');
const data = sentencize('APPLE_MUSIC', '_');
console.log(data);
// 'Apple Music'
const data = sentencize('SPOTIFY');
console.log(data);
// 'Spotify'
- url the url to be checked
const { isUrl } = require('@bolajiolajide/utils');
const response = isUrl('APPLE_MUSIC');
console.log(response);
// false
const response = isUrl('https://google.com');
console.log(response);
// true
- url the url to be checked
const { isHttpUrl } = require('@bolajiolajide/utils');
const response = isHttpUrl('ftp://dskjdslds');
console.log(response);
// false
const response = isUrl('https://google.com');
console.log(response);
// true