1.4.6 • Published 4 years ago

thesmo-range-generator v1.4.6

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Range generator

npm GitHub GitHub last commit npm

Summary

This package contains the collection of methods for ranges generating. It includes simple numeric ranges and ranges of user types with custom member generators, so any approach can be used.

API

API methods clarification

ByBordersAndStep

Signature

/* arguments object */
({ 
    inclusiveDownBorder: number, 
    notInclusiveUpBorder: number, 
    step?: number //1 by default
})
/* returns */
number[]

Usage example

const { ByBordersAndStep } = require("thesmo-range-generator");

//[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const foo = ByBordersAndStep({ 
    inclusiveDownBorder: 0, 
    notInclusiveUpBorder: 10 
});

//[0, 4, 8, 12, 16]
const bar = ByBordersAndStep({ 
    inclusiveDownBorder: 0, 
    notInclusiveUpBorder: 20, 
    step: 4 
});

ByGeneratorAndQuitCondition

Signature

/* arguments object */
({ 
    firstMember: any, 
    generator: (previousMember: any, currentZeroBasedIndex: number) => any, 
    quitCondition: (member: any, arrayLength: number) => boolean
})
/* returns */
MemberType[]

Usage example

const { ByGeneratorAndQuitCondition } = require("thesmo-range-generator");

// [{ a: 1, index: 0 }, { a: 2, index: 1 }, { a: 4, index: 2 }, { a: 8, index: 3 }]
const generatedRangeOfTestEntities = ByGeneratorAndQuitCondition({
    quitCondition: (member, arrayLength) => member.a > 8,
    firstMember: {a: 1, index: 0},
    generator: (previousMember, currentZeroBasedIndex) => { 
        return { 
            a: previousMember.a * 2, 
            index: currentZeroBasedIndex 
        }
    }
})

CustomByBordersAndStep

Signature

/* arguments object */
({ 
    inclusiveDownBorder: any, 
    notInclusiveUpBorder: any,
    step: any,
    sumOperation: (firstOperand: any, secondOperand: any) => any, 
    firstOperandIsGreaterThanSecond: (firstOperand: any, secondOperand: any) => boolean
})
/* returns */
any[]

Usage example

const { CustomByBordersAndStep } = require("thesmo-range-generator");

// [ {a: 0}, {a: 1}, {a: 2}, {a: 3} ]
const rangeOfTestEntities = CustomByBordersAndStep({
    firstOperandIsGreaterThanSecond: (firstOperand, secondOperand) => firstOperand.a > secondOperand.a,
    inclusiveDownBorder: {a: 0},
    notInclusiveUpBorder: {a: 4},
    step: {a: 1},
    sumOperation: (firstOperand, secondOperand) => {
        return {
            a: firstOperand.a + secondOperand.a
        }
    }
});

RepeatMember

Signature

/* arguments object */
({ 
    member: any, 
    times: number,
    //no mutations will be applied if current parameter is not set
    mutateMemberByIndex?: (sourceMember: any, index: number) => any
})
/* returns */
MemberType[]

Usage example

const { RepeatMember } = require("thesmo-range-generator")

// [54, 54]
const numberRepeated2Times = RepeatMember({member: 54, times: 2});

// [{a: 11}, {a: 11}, {a: 11}, {a: 11}, {a: 11}]
const testEntityRepeated5Times = RepeatMember({member: {a: 11}, times: 5});

// [{a: 11}, {a: 12}, {a: 13}, {a: 14}, {a: 15}]
const testEntityRepeated5TimesWithMutator = RepeatMember({
    member: {a: 11}, 
    times: 5, 
    mutateMemberByIndex: (sourceMember, index) => {
        return { 
            a: sourceMember.a + index 
        };
    }
});
1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago