Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
my-easy-fp
Advanced tools
Simple utility functions that can use browser, node.
name | description |
---|---|
isFalse | If argument false, return true |
isTrue | If argument true, return true |
invert | return inverted boolean value |
name | description |
---|---|
populate | populate array zero base, if you pass second argument true that populate one base |
chunk | array split given size |
last | pick last element from array |
first | pick first element from array |
toArray | make array given argument |
settify | make it set and convert it back to array |
name | description |
---|---|
isUndefined | if argument undefiend, return true |
isNotUndefined | if argument not undefined, return true |
isNull | if argument null, return true |
isNotNull | if argument not null, return true |
isNotEmpty | if argument not null and undefined, return true |
isEmpty | if argument null or undefined, return true |
isComplexEmpty | if argument not undefined and null, do additional test isNaN, empty string, empty array, empty object |
isNotComplexEmpty | return inverted value isComplexEmpty |
name | description |
---|---|
typedkey | same work Object.keys, but typed key in Recoed |
getRandomRange | return random value in min and max |
getRandomRangeInt | return random integer value in min and max |
isError | if argument is Error return Error or return undefined |
name | description |
---|---|
sleep | sleep given millisecond |
name | description |
---|---|
TResolvePromise | get type resolved promise |
TResolveArray | get type resolve array |
TNullablePick | convert specific field to nullable |
TNonNullableObject | object type each field to non nullable |
TNonNullablePick | convert specific field to non nullable |
Why need this utility?
import { isFalse } from 'my-easy-fp';
const iamboolean = false;
// this line easily miss in refactoring or changing
if (!iamboolean) {
console.log('I am execute false-case');
}
// more than better!
if (isFalse(iamboolean)) {
console.log('I am execute false-case');
}
Why need this utility?
const iamempty?: string | null = undefined;
// this line some boring task
if (iamempty === undefined || iamempty === null || iamempty !== '') {
console.log('i am empty');
}
// more than better!
if (isComplexEmpty(iamempty)) {
console.log('i am empty');
}
You need only undefined
and null
check, use double equal operator.
const iamempty?: string | null = undefined;
// Recently ESLint allow double equal for null check
// see https://eslint.org/docs/latest/rules/eqeqeq#allow-null
if (iamempty == null) {
console.log('i am empty');
}
Why need this utility?
const ms = 1000;
// this line some boring task
await new Promise((resolve) => setTimeout(() => resolve(), ms));
// more than better!
await sleep(ms);
populate, chunk utility here.
// seq is [0,1,2,3,4,5,6,7,8,9]
const seq = populate(10);
// seq is [1,2,3,4,5,6,7,8,9,10]
const seq = populate(10, true);
// chunked is [[1,2],[3,4],[5,6],[7]]
const chunked = chunk([1, 2, 3, 4, 5, 6, 7], 2);
// settify is [ 1, 2, 3, 4 ]
const settified = settify([1, 1, 2, 3, 2, 3, 4]);
// zeroIndex is 1
const zeroIndex = atOrThrow([1, 2, 3], 0);
resolve promise, array. But you can use type-fest or ts-essentials. Recommand use type-fest and tsessentials.
// you can get string | Buffer type
type TResolvedPromiseType = TResolvePromise<ReturnType<typeof fs.promises.readFile>>;
// you can get number type
type TResolvedArrayType = TResolveArray<number[]>;
interface IStudent {
name: string;
major: string;
grade: number;
}
// you can get { name?: string; major?: string; grade: number; }
// converted Omit<IStudent, 'name' | 'major'> & Pick<Partial<IStudent>, 'name' | 'major'>
type TCliArgumentStudent = TNullablePick<IStudent, 'name' | 'major'>;
FAQs
Simple functional programming utility & Misc programming tool
The npm package my-easy-fp receives a total of 33,664 weekly downloads. As such, my-easy-fp popularity was classified as popular.
We found that my-easy-fp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.