How to use the discontinuous-range function in discontinuous-range

To help you get started, we’ve selected a few discontinuous-range examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heydenberk / stochator / src / string.js View on Github external
import ret from "ret";
import DRange from "discontinuous-range";
import _range from "lodash.range";

const LOWERCASE_RANGE = [97, 122];

const UPPERCASE_RANGE = [65, 90];

const ASCII_RANGE = [32, 126];

const UNICODE_RANGE = [0, 65535];

const AsciiDRange = DRange(...ASCII_RANGE);

const UnicodeDRange = DRange(...UNICODE_RANGE);

const inRange = ([min, max], n) => n >= min && n <= max;

const changeCase = (code) => {
    const lowercase = inRange(LOWERCASE_RANGE, code);
    const uppercase = inRange(UPPERCASE_RANGE, code);
    return lowercase || uppercase ? code + (lowercase ? -32 : 32) : code;
};

const createChar = (code, ignoreCase, prng) =>
    code === null ? '' : String.fromCharCode(
        ignoreCase && boolean.random(prng) ? changeCase(code) : code);

const expandCharacter = ({value}) => DRange(value);

const expandRange = ({from, to}) => DRange(from, to);
github heydenberk / stochator / src / string.js View on Github external
const expandRange = ({from, to}) => DRange(from, to);
github heydenberk / stochator / src / string.js View on Github external
const expandSet = (token, range) => {
    let drange = DRange();
    let setRanges = token.set.map((code) => expand(code, range));
    setRanges.forEach((setRange) => drange.add(setRange));
    return token.not ? range.clone().subtract(drange) : drange;
};
github heydenberk / stochator / src / string.js View on Github external
import integer from "./integer";
import set from "./set";

import ret from "ret";
import DRange from "discontinuous-range";
import _range from "lodash.range";

const LOWERCASE_RANGE = [97, 122];

const UPPERCASE_RANGE = [65, 90];

const ASCII_RANGE = [32, 126];

const UNICODE_RANGE = [0, 65535];

const AsciiDRange = DRange(...ASCII_RANGE);

const UnicodeDRange = DRange(...UNICODE_RANGE);

const inRange = ([min, max], n) => n >= min && n <= max;

const changeCase = (code) => {
    const lowercase = inRange(LOWERCASE_RANGE, code);
    const uppercase = inRange(UPPERCASE_RANGE, code);
    return lowercase || uppercase ? code + (lowercase ? -32 : 32) : code;
};

const createChar = (code, ignoreCase, prng) =>
    code === null ? '' : String.fromCharCode(
        ignoreCase && boolean.random(prng) ? changeCase(code) : code);

const expandCharacter = ({value}) => DRange(value);
github heydenberk / stochator / src / string.js View on Github external
const generateCharacterFromRange = ([min, max], {prng}) =>
    generateStringFromRange(DRange(min, max), '.', {prng});
github heydenberk / stochator / src / string.js View on Github external
const expandCharacter = ({value}) => DRange(value);

discontinuous-range

for adding, subtracting, and indexing discontinuous ranges of numbers

MIT
Latest version published 10 years ago

Package Health Score

65 / 100
Full package analysis

Popular discontinuous-range functions