f-utility
Version:
functional utilities
97 lines (87 loc) • 3.74 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.substr = exports.startsWith = exports.__startsWith = exports.startsWithFromPosition = exports.replace = exports.padStart = exports.padEnd = exports.lastIndexOf = exports.__lastIndexOf = exports.lastIndexOfFromIndex = exports.indexOf = exports.__indexOf = exports.indexOfFromIndex = exports.endsWith = exports.__endsWith = exports.endsWithLength = exports.split = exports.search = exports.repeat = exports.match = exports.codePointAt = exports.charAt = exports.trim = undefined;
var _katsuCurry = require("katsu-curry");
var _entrust = require("entrust");
/**
* string.split(x) but delegatee last
* @method split
* @param {string} delimiter
* @param {string} string - to split
* @returns {strings[]}
* @public
* @example
* import {split} from `f-utility`
* split(`x`, `1x2x3`) // [`1`, `2`, `3`]
*/
/**
* string.trim() but delegatee last
* @method trim
* @param {string} string - to trim
* @returns {string} trimmed
* @public
* @example
* import {trim} from `f-utility`
* trim(` 20932 `) // `20932`
*/
/**
* string.replace but delegatee last
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
* @method replace
* @param {string} - a string or a regular expression
* @param {function} - a string or a function
* @returns {string} string with replacements
*/
// NULLARY
var trim = exports.trim = (0, _entrust.e0)("trim");
// UNARY
var charAt = exports.charAt = (0, _entrust.e1)("charAt");
var codePointAt = exports.codePointAt = (0, _entrust.e1)("codePointAt");
var match = exports.match = (0, _katsuCurry.curry)(function (a, b) {
var z = b.match(a);
return z === null ? [] : z;
});
// export const repeat = e1(`repeat`)
var repeat = exports.repeat = (0, _katsuCurry.curry)(function (x, n) {
var output = new Array(n);
for (var i = 0; i < n; i++) {
output[i] = x;
}
return output;
});
var search = exports.search = (0, _entrust.e1)("search");
var split = exports.split = (0, _entrust.e1)("split");
// BINARY
var endsWithLength = exports.endsWithLength = (0, _entrust.e2)("endsWith");
var __endsWith = exports.__endsWith = function __endsWith(x, i) {
var last = i[i.length - 1];
return Array.isArray(x) ? last === x[0] : last === x;
};
var endsWith = exports.endsWith = (0, _katsuCurry.curry)(__endsWith);
var indexOfFromIndex = exports.indexOfFromIndex = (0, _entrust.e2)("indexOf");
// the optional fromIndex param above is easy to forget
var __indexOf = exports.__indexOf = function __indexOf(toSearch, x) {
return indexOfFromIndex(toSearch, 0, x);
};
var indexOf = exports.indexOf = (0, _katsuCurry.curry)(__indexOf);
var lastIndexOfFromIndex = exports.lastIndexOfFromIndex = (0, _entrust.e2)("lastIndexOf");
// samesies
var __lastIndexOf = exports.__lastIndexOf = function __lastIndexOf(toSearch, x) {
return lastIndexOfFromIndex(toSearch, Infinity, x);
};
var lastIndexOf = exports.lastIndexOf = (0, _katsuCurry.curry)(__lastIndexOf);
var padEnd = exports.padEnd = (0, _entrust.e2)("padEnd");
var padStart = exports.padStart = (0, _entrust.e2)("padStart");
var replace = exports.replace = (0, _entrust.e2)("replace");
var startsWithFromPosition = exports.startsWithFromPosition = (0, _entrust.e2)("startsWith");
// export const __startsWith = (toSearch, x) =>
// startsWithFromPosition(toSearch, 0, x)
// export const startsWith = curry(__startsWith)
var __startsWith = exports.__startsWith = function __startsWith(x, i) {
var first = i[0];
return Array.isArray(x) ? first === x[0] : first === x;
};
var startsWith = exports.startsWith = (0, _katsuCurry.curry)(__startsWith);
var substr = exports.substr = (0, _entrust.e2)("substr");
;