Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mad-utils

andfaulkner1.1kMIT0.96.0TypeScript support: included

A set of misc utilties I find myself repeatedly re-writing between projects.

util, utils, utilities, utility, object, function, string, core, date, search, find, match, type, types, typing, typings, typescript, express, middleware, middlewares, omakase, kitchen-sink, query, query-params, query-parameters, location, browser-location, routing-utils, routes, route, routing, higher-order-functions, hocs, validation, validator, validate, validates, webpack, test, testing, tdd, mocha, tests, test-driven-development, events, event-handling, browser-events, file, files, file-system, file-handling, enums, enum, errors, error, error-handling, custom-errors, error-utils, error-utilities, error-utility, decorator, decorators, helpers, json, json-handling, language, test, testing, tests, unit-tests, numbers, number, integer, math, collections, collection, swiss-army-knife, react, dom, local-storage, isomorphic, translations, locale, i18n, scss, css, scss-mixins, scss-utils, css-utils

readme


mad-utils

Collection of utilities I keep repeatedly rewriting across projects.

mad-utils


Examples - most useful methods

(see full docs in lower sections for more details)

cap1LowerRest :: (string) => string

Capitalize first letter, convert rest to lowercase.

cap1LowerRest('aSdF'); // => 'Asdf'

capitalize :: (string) => string

Capitalize first letter. Leave the rest as-is.

capitalize('asdf'); // => 'Asdf'
capitalize('asDf'); // => 'AsDf'

eliminateWhitespace :: (string) => string

eliminateWhitespace('    asdf 123    ff    '); // => 'asdf123ff'

switchExpr :: ((cond: any, valueToReturnIfCondTruthy: V)*, defaultValue?: W) => V | W | never;

Function-based switch statement. Takes 2 or more args.

  • Args 1, 3, 5, 7, etc. are the conditions, and 2, 4, 6, etc. their corresponding return values.
    • On hitting a truthy odd-numbered arg, switchExpr returns the next (even-numbered) arg, then exits.
    • If none are truthy, the default value is returned (the last argument - which must be an odd-numbered arg).
      • If no default value is present after all conditions returned false, throws an error.

Examples:

switchExpr(true, 'val1');                // Output: 'val1'

switchExpr(false, 'val1', 'defaultVal'); // Output: 'defaultVal'

switchExpr(
    false, 'v1',
    true, 'v2',
    'defaultReturnVal');                 // Output: 'v2'

switchExpr(undefined, 'v1', '', 'v2');   // Throws Error

first :: (Array<T|any>) => T|any;

first([1,2,3]); => 1

last :: (Array<T|any>) => T|any;

last([1,2,3]); => 3

matchAny :: (any[]) => (any) => boolean

Search array for value. Returns true if array contains value. Uses simple JSON.stringify for comparison.

matchAny([1, 2, 3])(2);
// => true

matchAny(['a', 6, [1, 2, 3], 'gr'])([1, 2, 3]);
// => true

uuid :: () => string

uuid(); // => 5A42CCCF-6B10-488B-B957-4D1E5A113DA4
uuid(); // => 38259F99-73D5-4EE1-B11F-5D33CE8AD2C6

get :: (Object, string, any?) => any

Safely get the item at the given object path.

const obj = {a: {b: {c: 'value'}}};
get(obj, 'a.b.c');                    // => 'value'
get(obj, 'a.b.zzz', 'default value'); // => 'default value'

isBoolean :: (any) => boolean

isBoolean(true); // => true
isBoolean(false); // => true
isBoolean({}); // => false

isFalse :: (any) => boolean

isFalse(true); // => false
isFalse(false); // => true
isFalse('ok'); // => false

isInt :: (any) => boolean

isInt(5); // => true
isInt(-10); // => true
isInt(1.6); // => false
isInt('okok'); // => false

pushIfNew :: (T[], T) => T[]

const arr = [1, 2, 3]

pushIfNew(3); // => [1, 2, 3]
pushIfNew(4); // => [1, 2, 3, 4]

console.log(arr); // => [1, 2, 3, 4]

repeatChars :: (string, number) => string

repeatChars('a', 5); // => 'aaaaa'
repeatChars('aa', 5); // => 'aaaaaaaaaa'

getLangFromURLPathname ::

Signature:

<T = ('en' | 'fr')>(
    string? = location.pathname,
    T[]?    = ['en', 'fr']
    T?      = 'en'
) => string

TODO confirm getLangFromURLPathname signature

Example usage:

// With URL http://example.com/auth/fr/ok:
getLangFromURLPathname(); // => 'fr'

// With URL http://example.com/en/auth/ok:
getLangFromURLPathname(); // => 'en'

// With URL given as param:
getLangFromURLPathname(`http://example.com/auth/sp/ok`, [`en`, `fr`, `sp`]); // => 'sp'

parseQueryParams :: (queryParamsString?: string = window.location.search) => Object

// With URL http://example.com/home?hello=everyone&gr=argh:
parseQueryParams(); // => { hello: 'everyone', gr: 'argh' }

Installation

  • npm:

    npm install --save mad-utils
  • yarn:

    yarn add mad-utils

  • NOTE: the documentation is an extreme work-in-progress.
  • Recent versions have considerably changed the design, API, and even structure from earlier ones.
    • Considerably more functions are available
    • Existing functions have been massively changed (mostly to be more robust & less surprising);
    • The library has been split into 3 parts:
      • node
      • browser
      • isomorphic/shared
        • consumed by default, and also used by both the node and browser submodules.
    • A few exports have been deprecated (such as the parseDate function and ParsedDate type)
      • Mostly due to irrelevance (items were taken from my own projects).
    • (The docs still remain mostly up to date)

Sub-modules

  • Broken into 3 sub-modules: node, browser, and isomorphic.
  • The node and browser sub-modules each include the entirety of the isomorphic sub-module.

Isomorphic

Importing isomorphic (default) submodule

// Import all namespaces, functions, types, etc. from isomorphic submodule
import {m_} from 'mad-utils';

// Import isomorphic namespaces
import {array, json, enum, number, object, query, string, types} from 'mad-utils';

// Import individual isomorphic functions, types, classes, etc.
import {first, isNumberLike, parseQueryParams, castToNum, stringToEnumVal} from 'mad-utils';
  • All modules exported from mad-utils provide everything in the isomorphic module.

Isomorphic namespaces

  • array
  • date
  • enum
  • error
  • func / functionUtils
  • json
  • locale
  • number
  • object
  • query
  • search
  • string
  • types
  • validation

All of the above namespaces are also importable from the NodeJS and Browser modules.

NodeJS submodule

  • Isomorphic exports, plus exports that will only work in a Node environment, such as:

    • Anything using the NodeJS core API.
    • Anything requiring file handling.
    • Anything based on DOM-free unit testing.
    • Anything intended for use with (or relying on) on a browser-unfriendly library:
      • e.g. Express, Mocha, Chai.
  • Will generally crash your application if imported into the browser.

Importing node sub-module

// Import all namespaces, functions, types, etc. from node & isomorphic submodules
import {m_} from 'mad-utils/lib/node';

// Import node (and isomorphic) namespaces
import {file, test, middleware, webpackUtils, nodeError, date} from 'mad-utils/lib/node';

// Import individual node (and isomorphic) functions, types, classes, etc.
import {
    isDir,
    wasRunAsScript,
    replaceInFile,
    getJsFilesInDir,
    globalActivateCleanStack,
    useMiddlewareInProductionOnly,
    third,
    thirdLast,
    splitLines,
    composeExpressMiddlewares,
    isNonMinFile,
    eliminateWhitespace
} from 'mad-utils/lib/node';

Node-specific namespaces

  • file
  • middleware
  • nodeError
  • test
  • webpackUtils
  • types (expanded to include both isomorphic and Node-specific types)

Browser submodule

  • Exports that will only work in a browser environment, or one with a mocked DOM (e.g. JSDom)
  • Generally causes errors to throw if used in Node without a special environment set up
    • e.g. JSDom, or inclusion of various window mocks/polyfills

Importing browser submodule

// Import all namespaces, functions, types, etc. from browser submodule
import {m_} from 'mad-utils/lib/browser';

// Import namespaces from browser (and isomorphic) submodules
import {dom, types} from 'mad-utils/lib/node';

// Import individual browser (and isomorphic) functions, types, classes, etc.
import {
    browserVersion,
    browserEngineVersion,
    getUserAgentString,
    assignFrozenClone
} from 'mad-utils/lib/node';

Browser namespaces

  • dom
  • types (expanded to include both isomorphic and Browser-specific types)

Functions, by namespace

More import notes

If using a high-level import (mUtils, m_, __), you can access functions either via their namespaces or directory. E.g.

mUtils.search.replaceAll
mUtils.replaceAll
__.number.isInt
__.isInt
m_.date.isLeapYear
m_.isLeapYear
m_.array.secondLast
m_.secondLast
...etc...

mUtils, __, and m_ are 'full collection' exports

You can also get them like this if you hate named imports:

import madUtils from 'mad-utils';
const h = madUtils.m_;

Namespace strategy

Inclusive, overlapping namespace strategy used.

Namespaces treated more like keywords than parent types.

  • Many functions are included in more than 1 namespace.

The main philosophy behind this API design is to make common functions maximally available.

  • Repeatedly checking sifthing through namespaces trying to remember where a function lives is annoying.
  • However, having 100s of functions together in a giant namespace with no other form of organization available is also annoying.
  • I opted for a compromise, where everything was included in a giant namespace, while also including smaller "sub-namespaces".
    • This also has import advantages, since you can opt to pull in as much or as little as you need on each reference to mad-utils, without having to import whole namespaces and pluck individual functions off.

Common types [WIP]

NumLike

Either a number, or a string that can be parsed to a number

StrOrNever

Either a string, or 'Never' (indicating an error threw in the function)




Namespace contents



Namespace: array (isomorphic)

Get items from array by position

first :: (T[]) => T

Return first item in given array

first(['a', 'b', 'c', 'd']);  // => 'a'

second :: (T[]) => T

Return second item in given array

second(['a', 'b', 'c', 'd']);  // => 'b'

third :: (T[]) => T

Return third item in given array

third(['a', 'b', 'c', 'd']);  // => 'c'

last :: (T[]) => T

Return last item in given array

last(['a', 'b', 'c', 'd']);  // => 'd'

secondLast :: (T[]) => T

Return secondLast item in given array

secondLast(['a', 'b', 'c', 'd']);  // => 'c'

thirdLast :: (T[]) => T

Return thirdLast item in given array

thirdLast(['a', 'b', 'c', 'd']);  // => 'b'

first2 :: (T[]) => T[]

Return first 2 items in given array

first2(['a', 'b', 'c', 'd']);  // => ['a', 'b']

first3 :: (T[]) => T[]

Return first 3 items in given array

first3(['a', 'b', 'c', 'd']);  // => ['a', 'b', 'c']

last2 :: (T[]) => T[]

Return last 2 items in given array

last2(['a', 'b', 'c', 'd']);  // => ['c', 'd']

last3 :: (T[]) => T[]

Return last 3 items in given array

last3(['a', 'b', 'c', 'd']);  // => ['b', 'c', 'd']

firstN :: (T[], number) => T[]

Return first 'n' number of items from given array

firstN(['a', 'b', 'c', 'd'], 2);  // => ['a', 'b']

lastN :: (T[], Int) => T[]

Return last 'n' items from given array. Return full array if too many items requested.

lastN(['a', 'b', 'c', 'd'], 2);  // => ['c', 'd']

Create array

arrayN :: (length: Int) => undefined[]

Create empty array of given length (integer).

arrayN(3);  // => [undefined, undefined, undefined]

splitLines :: (string, {preserveEmptyLines: false}) => string[]

Split large multiline string into array where each line is an item. Removes blank lines by default, unless preserveEmptyLines option is set to true.

splitLines(
    'first line' +
    '\n ' +
    'third line' +
    '\n',
    'fourth line'
);
// => ['first line', ' ', 'third line', 'fourth line']

splitLines(`
    first line

    second line`,
    {preserveEmptyLines: true}
);
// => ['', 'first line', '', 'second line']

Exclude items from array by position

withoutFirst :: (T[] | string) => T[] | string

Remove first character or array item.

withoutFirst([1, 2, 3, 4, 5]) // => [2, 3, 4, 5]
withoutFirst('hello');  // => 'ello'

withoutFirst2 :: (T[] | str) => T[] | str

Remove first 2 characters or array items.

withoutFirst2([1, 2, 3, 4, 5]); // => [3, 4, 5]
withoutFirst2('abcdef'); // => 'cdef'

withoutFirst3 :: (T[] | string) => T[] | string

Remove first 3 characters or array items.

withoutFirst3([1, 2, 3, 4, 5]); // => [4, 5]

withoutLast :: (T[] | string) => T[] | string

Remove last character or array item.

withoutLast([1, 2, 3, 4, 5]); // => [1, 2, 3, 4]

withoutLast2 :: (T[] | string) => T[] | string

Remove last 2 characters or array items.

withoutLast2([1, 2, 3, 4, 5]); // => [1, 2, 3]

withoutLast3 :: (T[] | string) => T[] | string

Remove last 3 characters or array items.

withoutLast3([1, 2, 3, 4, 5]); // => [1, 2]

withoutFirstN :: (T[]|str, number) => T[] | string

Remove first N characters or array items.

withoutFirstN([1, 2, 3, 4, 5], 3); // => [4, 5]

withoutLastN :: (T[] | string, number) => T[] | string

Remove last N characters or array items.

withoutLastN([1, 2, 3, 4, 5], 3); // => [1, 2]

Array typechecking

isArray :: (T[] | T) => boolean

True if item is an array

isArray([]); // => true

class CustomArray extends Array { }

isArray(new CustomArray()); // => true

Add to or subtract from array

removeMatches :: (any[], any[] | any) => any[]

NON-MUTATIVE. PERFORMANCE-INTENSIVE.

Return new array with all items in arr2OrItem removed from array1. If array2 is not an array, remove matching item from array1.

removeMatches([1, 2, 3], 2); // => [1, 3]

removeMatches([1, 2, 3, 4, 5], [1, 4]); // => [2, 3, 5]

rmAllFalsy

(arr: any[]) => arr[]

  • Return new array with all falsy values in the given array eliminated.
  • NON-MUTATIVE

Examples:

rmAllFalsy([1, 2, 3, false, null, 4, 0, 'asdf', '', 'ok', undefined, 'fine']);
// => [1, 2, 3, 4, 'asdf', 'ok']

Array searching

matchAny: (haystack: T[]) => (needle: T) => boolean

Search an array for a value.

  • Returns true if array haystack contains needle.

Note that it uses simple JSON.stringify for array and object comparison

  • use something else if deep comparisons are required.

Sane behaviour for matching against null, undefined, NaN, etc.

  • e.g. NaN matched against an array with NaN returns true

Curried.

Examples:

matchAny([1, 2, 3])(2);
// => true

matchAny(['a', 6, [1, 2, 3], 'gr'])([1, 2, 3]);
// => true

matchAny(['a', 6, null, 'last'])(null);
// => true

Namespace: date (isomorphic)

[TYPE] NumRange0To6

Shorthand for any number between 0 and 6

[CONSTANT] defaultTimestampFormat :: string

String that creates a timestamp in a nice, human-readable format when passed to MomentJS. YYYY/MM/DD : hh:mm:ss

Examples:

console.log(defaultTimestampFormat);
// => `YYYY/MM/DD : HH:mm:ss`;

isLeapYear :: (year: NumLike) => boolean

Returns true if given year is a leap year. Accepts integers, strings that can be converted to integers, and arrays with a single item, where said item is an integer or string convertable to an integer. Any other input will throw.

Examples:

isLeapYear(2004); // => true
isLeapYear(2003); // => false

convertDayOfWeekNumToString :: (day: 0..6, abbrev: boolean) => string | never

Converts numeric day of the week to string day of the week. e.g. 0 -> 'Sunday', 6 -> 'Saturday' Args:

  • day: number from 0 to 6 for conversion
  • abbrev: If true, return the shorthand day names (e.g. 'Mon' vs. 'Monday'). Default: false.

Examples:

convertDayOfWeekNumToString(5); // => 'Friday'
convertDayOfWeekNumToString(2, true); // => 'Tues'

now

(timeFormat?: string) => string

Examples:

now(); // => 2017/05/28 : 02:51:39
now(`YYYY/MM hh:mm`); // => 2017/02 02:51

isDateLike (exported from types-iso - see below)


Namespace: dom (browser)

getUserAgentString :: () => string

Return raw and unparsed browser user agent string (convenience function)

Example:

getUserAgentString();
// => "Mozilla/4.0 (Macintosh; Intel Mac OS X 7_12_6) AppleWebKit/501.16 (KHTML, like Gecko) Chrome/50.0.1010.99 Safari/210.22"

osName :: () => string

Extract name of current user's OS (operating system) from browser user agent string. (Note: Memoizes result - i.e. 1st call to function stores result; all future calls reference stored result).

Example:

osName(); // => "Mac OS"

osNameSnakeCase :: () => string

Extract name of OS from browser user agent string, & convert it to snake_case. (Note: memoizes result)

Example:

osNameSnakeCase(); // => "mac_os"

browserName :: () => string

Extract name of current browser from browser user agent string. (Note: memoizes result)

Example:

browserName(); // => "Firefox"

browserEngineName :: () => string

Extract name of current browser's rendering engine from browser user agent string. (Note: memoizes result)

Example:

browserEngineName(); // => "Webkit"

osVersion

Extract version of current OS from browser user agent string. (Note: memoizes result)

Example:

osVersion(); // => "15.9.1"

browserVersion :: () => string

Extract version of current browser from browser user agent string. (Note: memoizes result)

Example:

browserVersion(); // => "64.1.5284.259"

browserEngineVersion :: () => string

Extract version of current browser's rendering engine from browser's user agent string. (Note: memoizes result)

Example:

browserEngineVersion(); // => "530.12"

Namespace: enum (isomorphic)

enumToStringArray

  • WIP documentation

enumValToString

  • WIP documentation

stringToEnumVal

  • WIP documentation

isNumericEnumItem

  • WIP documentation

isIndexEnumItem

  • WIP documentation

isDataEnumItem

  • WIP documentation

Namespace: error (isomorphic)

DecoratorError

  • WIP documentation

scrubStackTrace

  • WIP documentation

Namespace: error (node)

globalActivateCleanStack :: () => void

Remove pointless stacktrace items (node core). Modify the stacktrace length to be unlimited. Effects get applied globally immediately on running the function.

  • Affects error handling behaviour for the entire life of the Node process this was run in.

Examples:

globalActivateCleanStack();
// /\-- This is literally the only way to use it.

Namespace: file (node)

isDir :: (fileOrDirPath: string) => boolean

Returns true if inode (aka file, directory, socket, etc.) at absolute path is a directory.

isDir(path.join(rootPath, 'node_modules')); // => isTrue

wasRunAsScript :: () => boolean

Must always be called like this: wasRunAsScript(path.basename(__filename)). WARNING: has some edge cases (Fixing them is a WIP TODO):

  • Will (incorrectly) return true if the current file has the same name as the file that launched the process.
    • e.g. if process was launched by [project root]/server/index.js, and wasRunAsScript is run in [project root]/server/api/index.js, it will return true.
  • Will not work for filenames with certain characters, such as (, ), [, ], and certain other special regex chars (. and - are OK).

Example (in some-file.js, with process launched via node some-file.js):

wasRunAsScript(path.basename(__filename)); // => true

pathFromRoot

WIP documentation

replaceInFile

WIP documentation

getJsFilesInDir

WIP documentation

isFileInDir

WIP documentation

isNonMinFile

WIP documentation

endsInDotJs :: (string) => boolean

True if the given string (generally a path) ends in .js.

Example:

endsInDotJs(`asdf.js`); // => true

getBaseFilenameFromPath

WIP documentation


Namespace: function (isomorphic)

switchExpr :: (...(cond: any, retValIfCondTru: V), def?: W) => V | W | never;

Function-based switch statement.

For each pair of args:

  • the 1st arg is a condition that passes if truthy.
  • the 2nd arg is the value returned if the condition passes.

If no conditions pass, and there was:

  • ...an odd number of arguments given, then the final arg given to the function is returned.
  • ...an even number of arguments given, an error is thrown.

Examples:

switchExpr(true, 'val1');                                // => 'val1'
switchExpr(true, 'val1', 'defaultVal');                  // => 'val1'
switchExpr(false, 'val1', 'defaultVal');                 // => 'defaultVal'
switchExpr(false, 'v1', 'condition1', 'v2');             // => 'v2'
switchExpr(false, 'v1', null, 'v2', 'defaultReturnVal'); // => 'v2'
switchExpr(false, 'v1', null, 'v2');                     // => [throws error]
switchExpr(false, 'v1');                                 // => [throws error]

let size = 'large';

switchExpr(
    size === 'tiny',   8,
    size === 'small',  10,
    size === 'medium', 12,
    size === 'large',  16,
    size === 'huge',   20,
                       12
);
// => 16

General syntax:

switchExpr(
    COND1, val_returned_if_COND1_truthy,
    COND2, val_returned_if_COND2_truthy,
    ...,
    defaultReturnVal
)

loopN :: (number, (...args) => T) => T[]

Run given function the given number of times.

Return results of all runs of the function as an array containing all N return vals.

Examples:

loopN(2, () => 'return_value'); // => ['return_value', 'return_value']

let i = 0;
loopN(10, () => i++); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(i)        // => 10

loop2 :: ((...args) => T) => T[]

Run given function twice, and return results of both runs of the function as an array.

Example:

loop2(() => 'return_value'); // => ['return_value', 'return_value']

loop3, loop4, loop5

See loop2 above, but run the associated number of times

  • e.g. loop4 runs 4 the function 4X instead of twice

Examples:

loop3(() => 'ret_val'); // => ['ret_val', 'ret_val', 'ret_val']
loop4(() => 'ret_val'); // => ['ret_val', 'ret_val', 'ret_val', 'ret_val']
loop5(() => 'ret_val'); // => ['ret_val', 'ret_val', 'ret_val', 'ret_val', 'ret_val']

let i = 0;
loop5(() => i++); // => [0, 1, 2, 3, 4]
console.log(i)    // => 5

getFnAsArr :: (fn: Function) => string[]

Return a function's source code in nicely spaced array format.

Examples:

getFnAsArr(() => 'ok')
// => [ 'function () { return \'ok\'; }' ]

function testFn() {
    console.log('log 1');
    return 'output';
}
getFnAsArr(testFn);
// => [ 'function testFn() {',
//      '    console.log(\'log 1\');',
//      '    return \'output\';',
//      '}']

Namespace: json (isomorphic)

jsonStringifyWFuncs :: (Object) => string

Stringify, while keeping the functions in position by pre-converting them to strings.

Example:

jsonStringifyWFuncs({a: 123, b: 'asdf', c: () => 'asdf'})
// =>
    '{"a":123,"b":"asdf","c":"function () { return \'asdf\'; }"}'

WIP documentation


Namespace: locale (isomorphic)

commonLangsObj :: Record<string, string>

  • Object containing a set of common languages and their common ID codes
  • e.g. {af: 'Afrikaans', en: 'English', ...}

commonLangAbbrevs :: string[]

  • Array of common abbreviations for the most common languages
  • e.g. ['af', 'en', ...]

commonLangNames :: string[]

  • Array of the names of the most common languages
  • e.g. ['Afrikaans', 'English', ...]

canadaLangsObj :: Record<string, string>

  • Object mapping Canada's official languages to their abbreviations
  • {en:English, fr:French}

canadaLangAbbrevs :: string[]

  • Array of the abbreviations of Canada's official languages
  • ['en', 'fr']

canadaLangNames :: string[]

  • Array of the names of Canada's official languages
  • ['English', 'French']

englishVariants

  • Array of variants of English, by locale (codes)
  • ['english', 'en', 'en_ca', 'en_us', ...]

frenchVariants :: string[]

  • Array of variants of French, by locale (codes)
  • ['french', 'fr', 'fr_fr', 'fr_ca', ...]

Namespace: middleware (node)

useMiddlewareInProdOnly

WIP documentation

composeExpressMiddlewares

WIP documentation


Namespace: number (isomorphic)

isInteger :: (any) => boolean

Returns true if given value is an integer.

Examples:

isInteger(1);      // => true
isInteger(232);    // => true
isInteger(82.12);  // => false
isInteger('232');  // => false
isInteger('asdf'); // => false

(Alias: isInt)

isIntegerLike :: (any) => boolean

Returns true if given value is an integer-like string or integer.

Examples:

isIntegerLike(232);    // => true
isIntegerLike('232');  // => true
isIntegerLike('asdf'); // => false
isInteger(82.12);      // => false

isNumberLike :: (any) => boolean

Returns true if given value is a number-like string or number.

Examples:

isNumberLike(1);         // => true
isNumberLike(9267.84);   // => true
isNumberLike('1');       // => true
isNumberLike('9267.84'); // => true
isNumberLike('1.2');     // => true
isNumberLike('.2');      // => true

isNumberLike('1.2.2');   // => false
isNumberLike('asdf');    // => false
isNumberLike(true);      // => false

(Alias: isNumLike)

uuid () => string

Generate a UUID, in format e.g. 3A0BF2C7-3077-45A0-97ED-EC5F13F127F1.

Examples:

uuid(); // => 'F6779B17-8CD1-409B-A2AA-1FE80CB86654'
uuid(); // => 'B574571F-097A-4ADB-837C-DCE8472C3314'

Namespace: object (isomorphic)

get :: (obj: Object, path: string, default: any?) => any

Safely get the item at the given object path.

Arguments:

  • 1st: object to get from.
  • 2nd: object path to get value from.
  • 3rd: default value (if no value found at given path).

Examples:

const obj = {a: {b: {c: 'value'}}};

get(obj, 'a.b.c'); // => 'value'

get(obj, 'a.b.zzz', 'default value'); // => 'default value'

assignFrozenClone :: (Object, ...Object[]) => Readonly<Object>

Non-mutatively merge all given objects together (like Object.assign) & deep-freeze the result.

Examples:

const obj = assignFrozenClone({a: 1, b: 2}, {c: 3, d: 4});
// => {a: 1, b: 2, c: 3, d: 4}

obj.a = 6;
obj.a // => 1
            ^--- note that it didn't change

deepFreeze :: (Object) => Readonly<Object>

Deep freeze given object MUTATIVE! (But still returns original)

Examples:

const obj = deepFreeze({a: 1, b: 2, c: 3, d: 4});
// obj = {a: 1, b: 2, c: 3, d: 4}

obj.a = 6;
console.log(obj.a); // => 1
                    //    ^--- note that it didn't change

// Note that it also mutates the object:
const obj = {a: 1, b: 2, c: 3, d: 4};
deepFreeze(obj);
obj.a = 6;
console.log(obj.a); // => 1

eachPair :: <T extends object>(data: T, fn: (val, key) => any) => T

Run given function on each pair in given object. CURRIED, NON-MUTATIVE.

Examples:

const arr = [];
const putKeyValPairInArr = eachPair((v, k) => arr.push(k + v));
putKeyValPairInArr({a: 1, b: 2});

console.log(arr); // => ['a1', 'b2']

numKeys :: (Object) => number

Return number of keys in given object.

Examples:

numKeys({a: 1, b: 2}); // => 2

hasKey :: (Object, string) => boolean

Return true if given object has given key.

Examples:

hasKey({a: 1, b: 2}, 'a');  // => true
hasKey({a: 1, b: 2}, 'c');  // => false

defineProps :: (obj: I, string, val: any, mutable?: bool) => N & I {Object}

Add {key} with value {val} to {obj}. If {mutable} true, make new prop mutable.

Generics:

  1. N (NewKVPair) extends Object = {}
    • New key-value pair to add to object.
  2. I (InputObject) extends Object = {}
    • Original input object to mutate (and return).

Arguments:

  • obj: InputObject - object to mutate.
  • key: string - new key to add to given object (at arg 'obj').
  • val: Any - value to assign to new key.
  • isMutable: boolean? - if true, make new property mutable. Default: false.

Return value: (InputObject & NewKVPair)

  • InputObject with new key-value pair properties merged in.
  • Note that it also mutates the original value.

Examples:

const obj = {a: 'eh', b: 'bee'}
defineProps(obj, 'c', 'sea');
// returns (and new value of obj) :: {a: 'eh', b: 'bee', c: 'sea'}

const obj = {a: 'eh', b: 'bee'}
defineProps(obj, 'c', 'sea');
defineProps(obj, 'c', 'seeeee');
// returns (and new value of obj) :: {a: 'eh', b: 'bee', c: 'sea'}

const obj = {a: 'eh', b: 'bee'}
defineProps(obj, 'c', 'sea', true);
defineProps(obj, 'c', 'seeeee', true);
// returns (and new value of obj) :: {a: 'eh', b: 'bee', c: 'seeeee'}

Namespace: url (isomorphic)

getLangFromURLPathname

Signature:

(
    string? = window.location.pathname,
    string[]? = ['en','fr'],
    string? = 'en'
) => string

Get the currently selected language out of the current URL.

Note: this is a 'rough' method not intended to work in all circumstances.

  • You need to be storing the language in the URL for this to work

In Node, default value window.location.pathname gets set to '' if it doesn't exist.

Examples:

// Assuming we're at URL 'http://example.com/auth/fr/ok':
getLangFromURLPathname();
// => 'fr'

// Assuming we're at URL 'http://example.com/auth/fr/ok':
getLangFromURLPathname(window.location.pathname);
// => 'fr'

getLangFromURLPathname('/asdf/123asdfawzu/en/eiuherg/awzp1');
// => 'en'

getLangFromURLPathname('/asdf/123asdfawzu/sp/eiuherg/awzp1', ['en', 'sp']);
// => 'sp'

getLangFromURLPathname('/asdf/123asdfawzu/au/eiuherg/awzp1', ['en', 'fr', 'sp']);
// => 'en'

getLangFromURLPathname('/asdf/123asdfawzu/au/eiuherg/awzp1', ['en', 'fr', 'sp'], 'fr');
// => 'fr'

parseQueryParams :: (queryParamsString?: string = window.location.search) => Object

Convert the current query params into an object.

Note that running it without explicitly passing the queryParamsString works, but can give stale results.

  • It will still point to the query params present on initial page load if window.location.search not explicitly passed.
  • Not a problem unless something changes the query params after page load.

Examples (at URL 'http://example.com/home?hello=everyone&gr=argh'):

parseQueryParams(window.location.search);
// => {hello: 'everyone', gr: 'argh'}

parseQueryParams();
// => {hello: 'everyone', gr: 'argh'}

lastUrlPath :: (url: string = hrefDef, strict: boolean = true) => string

Get the last path in the given URL, with no / prepended, & query params excluded.

Returns '' if no paths in url.

Sets 'strict mode' to true by default, meaning trailing slashes aren't ignored.

  • If one is present, return value becomes ''.

If first param is null or undefined, uses the current page's URL as the url value.

Examples:

// Assuming we're at URL 'http://example.com/home?hello=everyone&gr=argh'
lastUrlPath(); // => 'home'

// Assuming we're at URL 'http://example.com/asdf/?hello=everyone&gr=argh'
lastUrlPath(); // => ''
lastUrlPath(null, false); // => 'asdf'

lastUrlPath('http://example.com'); // => ''
lastUrlPath('http://example.com/'); // => ''
lastUrlPath('http://example.com/', false); // => ''
lastUrlPath('http://example.com/asdf'); // => 'asdf'
lastUrlPath('http://example.com/asdf/'); // => ''
lastUrlPath('http://example.com/asdf/', false); // => 'asdf'

normalizeURLPathname (url: string) => string

Normalize given [url] {string}, converting to this format:

  • /main/en/home
  • /main/en/home?key=value

Does the following actions:

  • Remove leading & trailing whitespace, and trailing /
  • Precedes URL with single /
  • Removes all repeat slashes (e.g. // -> /; /// -> /)
  • Replace /? with ?

Examples:

normalizeURLPathname(``);                         // Output: ``
normalizeURLPathname(`/asdf/123`);                // Output: `/asdf/123`
normalizeURLPathname(`  /  `);                    // Output: `/`
normalizeURLPathname(`/////`);                    // Output: `/`
normalizeURLPathname(`/asdf//123`);               // Output: `/asdf/123`
normalizeURLPathname(`asdf`);                     // Output: `/asdf`
normalizeURLPathname(`/asdf/?key=val`);           // Output: `/asdf?key=val`
normalizeURLPathname(` ab//cd/ef///?key=val/  `); // Output: `/ab/cd/ef?key=val`

Namespace: search (isomorphic)

escapeRegExp

  • WIP documentation

matches

  • WIP documentation

matchesIgnoreCase

  • WIP documentation

replaceAll

  • WIP documentation

Namespace: string ((Alias: str)) (isomorphic)

cap1LowerRest :: (string) => string

Make the first letter uppercase and the rest lowercase.

Examples:

cap1LowerRest('asdf'); // => 'Asdf'
cap1LowerRest('aSdF'); // => 'Asdf'
cap1LowerRest('This was already cap.'); // => 'This was already cap.'
cap1LowerRest('This Was Already Cap.'); // => 'This was already cap.'
cap1LowerRest('not Already Cap.'); // => 'Not already cap.'

capitalize :: (string) => string

Make the first letter uppercase, and leave the rest as-is.

Examples:

capitalize('asdf'); // => 'Asdf'
capitalize('aSdF'); // => 'ASdF'
capitalize('This was already cap.'); // => 'This was already cap.'
capitalize('not Already Cap.'); // => 'Not Already Cap.'

removeMatchingText :: (string, string|RegExp) => string

Return copy of string with all instances of substring or regexp (matcherToRm) removed.

Examples:

removeMatchingText('HeRMlloRM woRMrldRM', 'RM');     // => 'Hello world'
removeMatchingText('RMqwertyRM uioprm',   /rm ?/ig); // => 'qwertyuiop'
removeMatchingText('Hello world',         'ASafer'); // => 'Hello world'

replaceAll :: (string, match: string|RegExp, replace: string) => string

Replace all matching strings or regexes in a text segment with given replacement string. All matching strings get replaced.

Args:

  • 1st arg: string to replace text in
  • match: string(s) to replace (replace all matches)
  • replace: string to replace matches with

Examples:

replaceAll('The duck here is the best Jerry! The best!', 'best', 'bees-knees');
// => 'The duck here is the bees-knees Jerry! The bees-knees!'

replaceAll('The duck here is the best Jerry! The best!', /[tT]he best/g, 'OK');
// => 'The duck here is OK Jerry! OK!'

chomp :: (string, charsToChomp: string = '\n\r') => string

Remove all chars in charsToChomp string from end of given string (1st arg).

Defaults to eliminating carriage return and newline (\n\r).

Examples:

chomp('asdf\n\r\n\r');                        // => 'asdf'
chomp('asdf\n \r  \n\r', '\n\r ');            // => 'asdf'
chomp('\n  \ras\ndf\n \r  \n\r   ', '\n\r '); // => '\n  \ras\ndf'
chomp('asdf\r \n', ' \n');                    // => 'asdf\r'

escapeRegExp

  • WIP documentation

isVoidOrString

  • WIP documentation

matches

  • See docs in search namespace.

matchesIgnoreCase

  • WIP documentation

stringToEnumVal

  • WIP documentation

Namespace: test (node)

expectNonEmptyObjectExists

Create Mocha test that passes if given object exists and is not empty

Examples:

expectEmptyObject({}); // << will not pass
expectEmptyObject({ a: 1 }); // << will pass

expectEmptyObject

Create Mocha test that passes if given object is empty

Examples:

expectEmptyObject({}); // << will pass
expectEmptyObject({ a: 1 }); // << will not pass

expectFunctionExists (ALIAS: expectFuncExists)

Create Mocha test that passes if given function exists

Examples:

const inc = (a: number) => a + 1;
expectFunctionExists({}); // << will not pass
expectFunctionExists(() => null); // << will pass
expectFunctionExists(inc); // << will pass

Namespace: types (Alias: type) (isomorphic)

isDateLike :: (any) => boolean

Return true if arg is a moment or Date instance; or a string, object, or number that moment can parse.

Excludes:

  • negative numbers
  • strings that parse to negative numbers
  • objects with date-irrelevant keys e.g. {year: 1123, bear: 'grizzly'}

Examples:

isDateLike('1990-12-10'); // => true
isDateLike(moment());     // => true
isDateLike(new Date());   // => true
isDateLike('asdf');       // => false
isDateLike(false);        // => false

isBoolean :: (any) => boolean

Return true if arg is a boolean value (either true or false)

Examples:

isBoolean(false);         // => true
isBoolean(true);          // => true
isBoolean(Boolean(true)); // => true
isBoolean('');            // => false
isBoolean(0);             // => false
isBoolean('true');        // => false
isBoolean(() => true);    // => false

isArray

  • (see array section above)

isNumberLike

  • True if given item is a number or a string that can be parsed into a number
  • WIP documentation

isMultilangTextObj

  • (see locale section above)

matches

  • curried, matcher-first match function
  • WIP documentation

matchesIgnoreCase

  • True if 2 given strings' match, with casing ignored.
  • WIP documentation

isVoidOrString

  • True if given item doesn't exist, or is a string.
  • WIP documentation

isInteger

  • True if given item is an integer
  • (see "number" section above)

isIntegerLike

  • True if given item is an integer or string containing an item that can be converted to an integer.
  • (see "number" section above)

Namespace: type (node)

MWare

WIP documentation

Middleware

WIP documentation

ApplyMiddlewareFn

WIP documentation

ExpressApp

WIP documentation

Color

WIP documentation


Namespace: type (browser)

WIP documentation


Namespace: validation (isomorphic)

isValidString

WIP documentation

isEmailPotentiallyValid

WIP documentation

noLowercase

WIP documentation

noUppercase

WIP documentation

noNumber

WIP documentation

noSpecialChars

WIP documentation

latinLangCharRegex

WIP documentation


Namespace: webpack (node)

WIP documentation

Documentation is a major WIP. TODO More documentation in README. TODO Document special React module.

changelog

0.96.0

[MAJOR CHANGE]

Module dependency changes

  • Upgrade uuid module to v9.0.0
    • This will break older browsers (IE 11)
  • Move express & React to peerDependencies
  • Allow any React version >= 16 (instead of explicitly 16)
  • Move express into peerDependencies, allow any version >= 4
  • Move ts-node into devDependencies
  • Move @types/chai, @types/react, and @types/react-dom to devDependencies
    • Also move @types/react, and @types/react-dom to peerDependencies

Module removals

  • Remove chokidar, remove watch-test script
  • Remove all uses of Enzyme
  • Remove handlebars-webpack-plugin
  • Remove supertest
  • Remove test-console
  • Remove sinon
  • Remove uglifyjs-webpack-plugin

Function & type removals

  • Remove incredibly silly and outdated sex & gender types & objects:
    • biologicalSexes, biologicalSexesWithBoth, biologicalSexesWithOther, genderFull, BiologicalSex BiologicalSexWithOther, BiologicalSexWithBoth, commonBiologicalSexes, sexes, commonSexes commonBiologicalSexesWithBoth, sexesWithBoth, commonSexesWithBoth, sexWithBoth, sexesWithOther, commonSexesWithOther, commonBiologicalSexesWithOther, Sex, CommonSex, BinarySex, SexWithOther, CommonSexWithOther, SexWithBoth, CommonSexWithBoth, VaccineSex, VaccineSexes, Gender, GenderCommon, GenderWithBoth, GenderCommonWithBoth, gender, genderCommon, genderWithBoth, genderCommonWithBoth, GenderExtensive, GenderExtended

Docs

  • Minor doc & type fixes in string.ts
  • Partial conversion of "=======.." style headers to "-------.."

0.95.0

  • Remove .static CSS class (it causes some compilers to fail)
    • Renamed it to .stat

0.94.1

  • Recompile
  • Allow publish script to run without global replace-in-file package
  • Fix typo in publish script

0.94.0

  • Add removeIndent string function, for removing indents from tag templates.
  • Add oneLine string function, for converting multiline strings into single-line strings.

0.93.1

  • Upgrade reflect-metadata to 0.1.13 (potential breaking change)

0.92.2

  • Add new peekMulti method to CharInputStream
  • New CharInputStream alias CharStream

0.92.1

  • Add new len4 & len16 functions to uuid namespace that generates a 4 and 16-character UUIDs (respectively).
  • Fix doc for len8 method.

0.92.0

For boolStringToBool:

  • Better docs.
  • Strict mode now off by default.
  • Tests for correct strict mode default state.

0.91.2

Fix typings and docs in stream module.

0.91.1

Apply all SCSS utils dependent on flex to work with inline-flex.

Minor documentation fixes.

0.91.0

Add new debounce function: Arguments: cb: (...fnArgs: A[]) => any, wait: number, immediate: boolean = false

Returns:
    type of cb, but with return type replaced with void

0.90.2

Add new colour: slightDarkPink: #f9adba Includes CSS classes:

  • slight-dark-pink
  • bg-slight-dark-pink
  • bg-slight-dark-pink-hover
  • bg-slight-dark-pink-active
  • border-slight-dark-pink-active produce<T extends ProduceConditions, U extends { [key in keyof T]: any }>(conditions: T, input: any): Promise | U

0.90.1

Add more specificiity to opacity, visibility, and z-index SCSS utilities i.e. .opa-7 became * * *.opa-7

0.90.0 [BREAKING CHANGES]

Upgrade Typescript to v3.3.3 Upgrade Node to v10.15.0

Add getType function to types-iso, to get the "extended" type (in string form).

- Adds types 'null', 'nan', 'regexp', 'array'; detects 'symbol' & 'bigint' in all environments.

Add DataTypesExpanded type to types-iso, containing extended list of types emitted by new getType function.

Breaking change: Swap 1st & 2nd generic in omit function, to work with Typescript 3.3+.


0.89.6

Add isObject function to types-iso

0.89.5

Remove postinstall - it causes install fail in receiving project

0.89.4

Add .overflow-word-break scss utils, including aliases: .ov-wrap-break-word, .break-word, .word-break-wrap, .wrap-word .ov-word-break, .wrap-break-word, .wrap-word-break

Add postinstall to ensure typings install always works with npm (as opposed to only yarn).

Minor typing fix.

0.89.3

arrayRemove function can now take predicate that removes elements that return true. New signature: arrayRemove(haystack, needle: (NonFunction | (item) => boolean), returnRemovals? = false)

0.89.2

Add 3rd param to arrayRemove function, to return the removed elements from the array.

  • ...instead of the new value of the array, as displayed if true not passed as 3rd arg.
  • New signature: arrayRemove(haystack, needle, returnRemovals? = false).

0.89.1

Add number handling to get function

0.89.0

Fix toCamelCase to work correctly when given snake_case strings.

  • Previously it didn't capitalize the character after each _.

0.88.1

  • Add fuzzySearch function - does a fuzzy search for string needle in string haystack.

0.88.0 [BREAKING CHANGES]

  • Remove from dom.ts:

    • Export parseUserAgent
    • Export getUserAgentParsed
  • Remove module event.ts, including:

    • mouseEventFactory function
    • removeClickEventFromId function
    • addClickEventToId function
    • EventFunction type
  • Remove module local-store.ts, including:

    • getFromStorage function
    • isAuthenticated function
  • Remove decorator.ts module, including:

    • notForWebUse and methodNotForWebUse decorators
    • getDecoratorType function
    • Secondary export of singleton decorator (still present in types-iso.ts)

0.87.1

Allow symbols and numbers in:

  • defineProp
  • defineMethod
  • defineImmutableProp
  • defineMutableProp
  • defineDeletableProp
  • defineGetterProp

0.87.0

Remove layout SCSS utils:

  • display-col
  • display-inline
  • display-block
  • display-inline-block
  • display-flex
  • display-table
  • display-col
  • display-td
  • display-table-col
  • display-table-column
  • display-row
  • display-tr
  • display-table-row
  • display-cell
  • display-table-cell
  • inflex & inlineflex (inline-flex instead)

Remove unneeded justify-content SCSS util aliases:

  • All with prefixes:
    • "jc-" e.g. ".jc-start"
    • "flex-justifycontent-" e.g. ".flex-justifycontent-start"
    • "justify-content-" e.g. ".justify-content-start"
  • flex-start, flex-center, flex-end
  • flex-middle, middle, mid
  • flex-sa, flex-spacearound, flex-space-around, sa, spacearound [Use .space-around only]
  • flex-sb, flex-spacebetween, flex-space-between, sb, spacebetween [Use .space-between only]

Remove unneeded align-items SCSS util aliases:

  • All with prefixes:
    • flex-ai-
    • flex-alignitems-
    • flex-align-items-
    • alignitems-
  • ai-mid, ai-middle, align-items-mid, align-items-middle
  • ai-fs, ai-fe, ai-flexstart, ai-flexend
  • align-items-fs, align-items-fe, align-items-flexstart, align-items-flexend
  • align-items-fstart
  • align-items-fend

Remove unneeded align-self SCSS util aliases:

  • All with prefixes:
    • flex-align-self-
    • flex-alignself-
    • alignself-
    • flex-as-
    • as-
  • align-self-mid, align-self-middle
  • align-self-fs, align-self-fe, align-self-flexstart, align-self-flexend
  • align-self-fstart
  • align-self-fend

Remove unneeded align-self SCSS util aliases:

  • flex-dir-*
  • flex-direction-*

Remove "overflow-" prefixed SCSS util aliases (use .ovx-* and .ovy-* utils instead)


0.86.1

Replace use of specific elements (div, span, etc) to increase selectivity in SCSS utils with use of *s.

  • Done in all remaining SCSS util files.

0.86.0

Rename ReactChildString & ChildString types.

  • Reason: They're useless. It's easier to just write {children?: string}.

In margin.scss, padding.scss, size.scss, position.scss:

  • Replace use of divs to increase selectivity in SCSS utils with use of *s.
  • Remove redundant selectors.

0.85.2

Add missing uuid module

  • Large issue - this caused mad-utils to break in projects that didn't install uuid module separately

0.85.1

Add colour darkerRed to SCSS, including utils:

  • dark-red, bg-dark-red, bg-dark-red-hover, bg-dark-red-active, border-dark-red

0.85.0

Migrate to use esModuleInterop=true in TS config


0.84.0

Renamed condSwitch to switchExpr

  • Deprecated condSwitch

0.83.0

Remove getBaseFilenameFromPath function (it's already in Node as path.basename)

Fix SCSS error in text.scss causing newer SCSS build tools (Webpack plugins) to crash


0.82.1

Remove StrOrVoid type (it's causing build errors)

0.82.0 [BREAKING CHANGES]

Remove numerous SCSS position utils (top-, bottom-, left-, right- e.g. top-450):

  • 55p (e.g. top-55p)
  • n6, n7, n8, n9, n11, n12, n13, n14 (e.g. bottom-n14)
  • 11, 12, 13, 14, 55, 65, 85, 95 (e.g. left-11)
  • 225, 275, 325, 350, 375, 425, 450, 475, 525 (e.g. right-225)
  • 550, 575, 600, 650, 700, 800, 850, 900, 950 (e.g. top-550)

0.81.0 [BREAKING CHANGES]

Add SCSS utils:

  • fw-400, fw-600, & fw-700 - font-weights 400, 600, 700
  • fs-9 - font-size 9

Remove SCSS utils:

  • no-bold (it's confusing)
  • fw-bold (redundant - covered by bold util)
  • fs-31, fs-32, fs-33, fs-34, fs-36, fs-38, fs-45
    • That level of precision unneeded at those sizes
  • all text-indent SCSS utils - ti-*
    • e.g. ti-1
  • Remove whitespace-* prefixed aliases for white-space SCSS utils
    • e.g. ws-no-wrap
    • Leaves ws- prefixed forms in place
  • p*-55, p*-57, p*-60, p*-65, p*-70
    • e.g. pt-55, p-55
    • That level of precision unneeded
  • ov-*
    • e.g. ov-hidden, ov-auto
  • m*-32, 34, 45, 57, 90, 125, 150, 175, 225, 275, 300, 400, 600, 700, 750, 800, 900, 1000
    • e.g. m-32, mb-n34p, mt-57, mt-n57, mr-n1000
  • float-r, f-right, float-l, f-left
    • Unneeded, use float-right, float-left
  • w-mincont, w-mincontent, w-maxcont, w-maxcontent, w-maxc, w-max-c, w-minc, w-min-c
  • h-mincont, h-mincontent, h-maxcont, h-maxcontent, h-maxc, h-max-c, h-minc, h-min-c

Clean specificity for all SCSS utils in:

  • margin.scss (e.g. margin-auto / m-auto)
  • padding.scss
  • size.scss
  • text.scss

0.80.0

Fixed bug in throttle where values from prototype weren't propagating to returned function

Remove exported React types:

  • AnyComponent
  • NamedSFC
  • ReactSFC

Allow displayName in Newable React types

0.79.2

Remove append function Remove osNameSnakeCase function (just use osName, and run a snake_case function on it)

Rename userAgent to getUserAgentParsed, make it an exported function

  • Purposes:
    • Make it clearer that it returns parsed userAgent object, not a string
    • Ensure memoization and calculation doesn't occur until function is called, rather than having it happen greedily when the module is loaded (for performance and safety)

Add return types to DOM module

Major improvements to README

Simplify logger higher-order-component


0.78.2

Upgrade mad-logs to isomorphic variant

Fix docs in hocs module

0.78.1

toSnakeCase and toDashCase now:

  • Replace most special characters with _ (or -)
  • Replace quotes with _ (or -)
    • Previously they were just eliminated
  • Handle accented characters (e.g. é)
  • Surround Þ þ ø µ and ß with _ (or -)
    • e.g. toDashCase('someµOf') // => some-µ-of
  • Handle spaces correctly

0.78.0

Saner toSnakeCase behaviour:

  • Consistently handles consecutive caps correctly e.g.:
    goToHomeURLPath -> go_to_home_url_path
    goToHomeURL!Path -> go_to_home_url_path
    goToHOME URL!Path -> go_to_home_url_path
    etc...
  • Defaults to having special consecutive cap handling on
    • Remove option to shut it off
  • Punctuation treated the same as a word break
  • Handles null & empty strings

New toDashCase function


0.77.0

Remove ".wrap-wrap" SCSS util

Add flex.as-* SCSS util collection

  • e.g. .flex.as-mid, .flex.as-start
  • Shorthands for .flex-as-* series

Add SCSS utils: .table-cell, .table-row, .table-col, .table-column

  • Aliases for .display-table-cell, .display-table-row, etc

0.76.3

isAbsoluteURL now handles missing // for all protocols but http & https

0.76.2

Make isAbsoluteURL handle null & undefined without crashing (it returns false)

0.76.1

Fix typings in locale module

Add isAbsoluteURL function

0.76.0 [MAJOR REFACTOR] [BREAKING CHANGES]

Include all shared namespaces in browser module export

Namespaces export changes:

  • Shared module export:
    • Add err namespace alias (for error namespace)
    • Add stream namespace
  • Browser module export:
    • Add srch and find namespace aliases (for search namespace)
    • Add numeric & num namespace aliases (for number namespace)
    • Remove browser types namespace export
  • Node module export:
    • Add srch and find namespace aliases (for search namespace)
    • Add numeric & num namespace aliases (for number namespace)
    • Remove Node errorShared namespace export

Remove common namespace exports:

  • Remove common, commonIso & commonShared exports from ./mad-utils/lib/shared
  • Remove common export from ./mad-utils/lib/browser & ./mad-utils/lib/node

Node type changes:

  • Remove Colors type export from types-node (Node export)
  • More restrictive ApplyMiddlewareFn type: only allow Object & Function values

0.75.2

Fill in max-/min-width & max-/min-height SCSS utils for 27px, 28px, 27%, 28%

  • They existed for width & height, so the oversight is confusing

0.75.1

Fix & expand docs for extractFromUrl Fully unit test extractFromUrl

0.75.0

Add new functions to url submodule:

*   `extractFromUrl`
*   `normalizeURLPathname`
*   `urlPathnameWithQuery`
*   `urlPathname`

Add urlGetQuery alias urlQuery in URL module

Add new function arrayRemove to array submodule

Add mad-utils REPL for experiments


0.74.2

Add normalizeURLPathname function

  • Perform cleanups on a given pathname string:
    • Remove preceding & trailing whitespace, and trailing /
    • Replace // with /, /// with /, etc.
    • Replace ?/ with ?
    • Ensure a single / at beginning

Large changes to README IDE-friendlier docs in url module

0.74.1

Fix Canadian postal code validation

  • no longer rejects some valid postal codes
  • doesn't crash when given null
  • handles 3 character case correctly

Add isCanadaPostalCode alias for validateCanadaPostalCode

0.74.0 [BREAKING CHANGE]

Remove castToNum function

  • Reason: its behaviour is weird & confusing, and it provides little benefit over parseInt, in exchange for a large mental load

Remove convertDayOfWeekNumToString function

  • Reasons:
    • it's not internationalization-friendly (it only handles English)
    • it's confusing

Fix uuidRegex to correctly detect UUIDs

Add new isUUID function for detecting if a value is a v4 UUID


0.73.1 [BREAKING CHANGE]

Saner behaviour from countOccurrences function:

  • It now only returns a number, never a map
  • 'Value to search for' (needle) argument goes 1st & is no longer optional
  • 'Collection to search' (haystack) argument now goes 2nd
  • New example usage:
    countOccurrences(`a`, [`a`, `z`, `a`]) // => 2

Add smoosh alias for flatten 😈

More IDE-friendly & extensive docs in array module

Logs no longer include trailing ' ;' after the file tag (e.g. "🍀🍀🍀[filename.ts]🍀🍀🍀 ;")


0.72.1

Add diacritic handling to isAlphabeticChar Add isUndefined function

0.72.0

New validateCanadaPostalCode function

  • Remove invalid characters from Canadian postal code validations

Add canadaPostalCodePartialRegex

  • Case-insensitive regular expression for matching full & partial Canadian postal codes

Remove isValidString function

Remove (validation-related) types:

  • ValidationCondition
  • _RegCond
  • _NoMatcherCond
  • _Matcher
  • ValidationCondition
  • IsVStrOpt

Remove isEmailPotentiallyValid alias for isEmailValidBasic


0.71.1

Remove BoolOrError convenience type aliases:

- BoolOrErr
- ErrOrBool
- ErrorOrBool
- ErrorOrBoolean
- BooleanOrError

Improve various comment docs to make more friendly to Typescript tooling (cross-IDE)

0.71.0

Remove isMultilangTextObj function (it's confusing and bad practice) Object module improvements:

- Reduced size (should be more performant)
- Eliminated unneeded imports
- Expanded and cleaned docs

0.70.1

Add isNullOrUndefined function Remove more spaces from SCSS files (shrink file size slightly)

0.70.0 [BREAKING]

Removed TitleCased SCSS util class aliases/names:

  • .HelveticaNeue
  • .HelveticaNeue-serif

Removed all SCSS util class aliases/names preceded by ff- (uses util classes with raw font names instead):

  • .ff-better-helvetica
    • instead use .better-helvetica
  • .ff-helvetica-neue-medium
    • instead use .helvetica-neue-medium
  • .ff-helvetica-neue
    • instead use .helvetica-neue
  • .ff-helvetica-neue-serif
    • instead use .helvetica-neue-serif
  • .ff-helvetica-neue-light
    • instead use .helvetica-neue-light
  • .ff-helvetica-neue-light-serif
    • instead use .helvetica-neue-light-serif

Add new .helvetica-neue-medium font-family SCSS util class


0.69.1

Add more sizes for min-width, min-height, max-width, and max-height SCSS utils Reduce filesize of pasition.scss & size.scss util modules (remove spaces before & after block braces)

0.69.0 [BREAKING]

Add new deindent function in string module, for removing spaces before template strings

Remove withLeftIndent function (string module)

Remove entire webpack module

  • Eliminates function handlebarsPluginFactory

0.68.0

Working catch statement for modify class name in singleton function

  • Should get transpiled singleton function working in Safari 9

[BREAKING CHANGE] More robust isIntegerLike function

  • Removes edge case allowing '.0', which can't be parsed
  • Shorter, cleaner implementation
  • More unit tests

Downgrade ts-node -> v6.1.* (needed to run tests)


0.67.1

Remove dev module fs-extra (there's fs-extra-promise already)

Upgrade dev modules

  • synk -> v1.90.2
  • prettier -> v1.14.2
  • nodemon -> v1.18.3
  • ts-node -> v7.0.1
  • sinon -> 6.1.5
  • tslint -> 5.11.0
    • Also upgrade all plugins to latest

0.67.0 [BREAKING]

Remove node-polyglot module Remove PolyglotProps type

Gets singleton method (from types-iso) to work in most environments where both:

  • running Object.defineProperty on a read-only value throws
  • all classes are read-only

Makes isDateLike more robust:

  • Includes moment.isMoment check
  • Returns false immediately on receiving undefined, null, or false

0.66.3 [BREAKING]

Upgrade env-var-helpers to v5.0.0 (a semi-breaking change) Upgrade errorsmith to v0.4.1 (semi-breaking) Upgrade mad-logs to v10.3.3 (semi-breaking)

Remove errorsmith


0.65.1

throttle function:

  • Fix typings
  • Can now handles arguments
  • Transfers data keys on source function to throttled return function
  • Leaves "this" binding alone in throttled return function

0.65.0 [BREAKING CHANGES]

Remove entire JSON module

  • Remove jsonParseWFuncRehydrate_unsafe function
  • Remove jsonStringifyWFuncs function

More missing tests (sortObject)

0.64.4 (version jump due to release error)

dateStringWithMonthTextToMoment improvements:

  • Handles 2-part date strings (returns null)
  • Handles text strings with dashes in them (returns null)
  • Handles text 'phrases' - i.e. strings with spaces in them (returns null)

0.63.2

dateStringWithMonthTextToMoment improvements:

  • Handles moment objects (returns them as-is)
  • Handles single digit values for month & date

0.63.1

Warning always shown when null returned from dateStringWithMonthTextToMoment

0.63.0

moment.js is now a peer dependency (to allow for proper locale handling)

Various typing & doc fixes

Add dateStringWithMonthTextToMoment function

  • Converts any date string containing a text-based month into a moment object
  • Handles fallback strings if fallback given

0.62.1

Add isAlphaChar alias for isAlphabeticChar

More robust check for moment object validity

0.62.0

Rename character utility types (capitalize the names):

  • char -> Char
  • chars -> Chars
  • character -> Character
  • characters -> Characters

Add isAlphabeticChar function that returns true if given an alphabetic character

README.md changes:

  • Remove merge function
  • Update 'get' function description

0.61.0

Add isStringOrNumber aliases isStringOrNum & isStrOrNum

More TS-usable docs in function module

Remove 'location' module - moved to storage in wip/old/browser--geocode.ts

  • Reason: too specific, too brittle, too tied to Google
  • Eliminates "getCurrentCity" function

Remove unwanted log in node/test.ts module

  • Previously, expectEmptyObject would log typeof testValue

0.60.0 [BREAKING CHANGES]

Remove confusing DecoratorError pseudo-class/function

getArgsFromFuncAsString (now getArgNames):

- Rename to getArgNames
- Returns an array of arguments rather than a comma-separated string
- Remove aliases getParamNames, getParameterNames, getArgumentNames, getArgs
- Add unit tests

Export getRandomInt function to generate a random integer between min and max values

condSwitch docs improved (adds note about usage with prettier)

Unit tests for:

- runAll
- getRandomInt

0.59.0 [BREAKING CHANGES]

New function 'runAll' - runs all functions in the given array & return results of each

Remove functions:

- delegateAll - it's too dangerous & erratic to use safely
- merge - it's pointless and confusing. Use ES7 object spread syntax instead
          e.g. {key: val, ...something}

nyc working (test-coverage) File cleanups (prettier, docs more consistent)


0.58.4

Formatted CHANGELOG

Fix typings for isFunction

SCSS text utils:

*   Convert ls-#.# to ls-#pt# & ls-#p#
*   Higher specificity for font-family utils
*   Higher specificity for font-size

"sample" function:

*   handles empty Maps & Sets
*   unit tests for Map & Set
*   type signatures for Map & Set inputs

0.58.1

Fix typings (to allow TS v2.9.2 to work) in object module for:

*   defineProp
*   defineMethod
*   defineMethod
*   defineImmutableProp
*   defineMutableProp
*   defineDeletableProp
*   defineGetterProp

Code cleanup (prettier, doc fixes) on all tests, object module, & types-iso module

0.58.0

Upgrade Typescript to v2.9.2

Add rmAllFalsy alias rmFalsyVals

  • Reason: the name 'rmAllFalsy' is unsemantic, because the function can be configured to instead remove a selected subset of falsy val types

Remove NumberLike, NumLike types

isNumberLike function no longer handles string & nunber arrays with 1 item isLeapYear function no longer takes string & nunber arrays with 1 item


0.57.5

Add optional 2nd config param to rmAllFalsy (alias: compact) function, with options:

*   'allFalsy'  - Remove all falsy values [DEFAULT]
*   'nullUndef' - Remove only null & undefined values
*   'keep0'     - Remove all falsy values except 0
*   'keepStr'   - Remove all falsy values except ''

0.57.4

Add deburrFrenchEnglish function

  • Deburr map contains all accents/diacritics found in both English and French
    • These get mapped to the accentless versions

0.57.3

Add more z-indexes to SCSS utils

0.57.2

New alias for rmAllFalsy: compact Function 'sample' working for Set & Map objects Rm logs from function 'get'

0.57.1

Revamped get function:

  • Can now handle symbol, string, boolean, function, & number types as input
    • Traverses all of the above
  • Returns null if value at final path is null
  • Handles trailing and preceding dots in path
  • Many more function tests

New ls-0pt* namespace/aliases (e.g. ls-0pt5) for letter-spacing SCSS utils

  • Previously it was only found at ls-0p* (e.g. ls-0p5), which caused confusion

0.56.0

Add robust isString function to types-iso module Add type guards to types-iso functions More robust isStringOrNumber function (detects more string cases) Simpler isTrue & isFalse functions Replace typeof comparisons in types-iso with more robust detection functions (isString, etc)


0.55.3

Fix dark-sky-blue color class names (in SCSS util classes)

0.55.2

Add throttle function Clean up after changes to blue SCSS util class changes

0.55.1

Add border-radius by percentage util-styles e.g. br-10p Update & clean up general rules in in-code docs for SCSS utils (in util-styles)

0.55.0

Changes to blue colour SCSS util classes:

*   Rename SCSS variable   ::  "midLightBlue"       => "lighterSkyBlue"
    *   Rename SCSS class  ::  "mid-light-blue"     => "lighter-sky-blue"
*   Rename SCSS variable   ::  "paleSkyBlue"        => "skyBlue"
    *   Rename SCSS class  ::  "pale-sky-blue"      => "sky-blue"
*   Rename SCSS variable   ::  "skyBlue"            => "darkSkyBlue"
    *   Rename SCSS class  ::  "sky-blue"           => "dark-sky-blue"
*   Rename SCSS variable   ::  "slightlyDarkBlue"   => "palestDarkBlue"
    *   Rename SCSS class  ::  "slightly-dark-blue" => "palest-dark-blue"
*   New SCSS variable  :: "palerDarkBlue"
    *   New SCSS class :: "pale-dark-blue"
*   Rename SCSS variable   ::  "slightDarkBlue"     => "paleDarkBlue"
    *   Rename SCSS class  ::  "slight-dark-blue"   => "pale-dark-blue"

0.54.3

Quick patch to fix .outline-none & .no-outline CSS util classes

*   set to operate on focus rather than always

0.54.2

Add .gitattributes Add .outline-none & .no-outline CSS util classes Upgrade colors module to 1.2.4 (and @types/colors to 1.2.1)

0.54.1

Add getCookieFromReq function to express-routing

  • Extracts cookie from express request headers property

isSupportedLang (express-routing):

  • now eliminates trailing slashes before comparison
  • Unit tests

0.54.0

Fix express-routing: getNoTrailingSlashUrl function

*   Rename getNoTrailingSlashUrl -> getUrlPathFromReq
*   Fix docs
*   Takes keepTrailingSlash param (default false) that leaves trailing slash on end if true
*   It no longer sometimes duplicates pre-slash string parts
*   Removed lodash dependency (from getUrlPathFromReq)
*   Unit tests

Rename checks for request type (express-routing): isJsAsset -> isRequestForJsAsset isJSAsset -> isJsAssetRequest isCssAsset -> isRequestForCssAsset isCSSAsset -> isCssAssetRequest


0.53.4

Upgrade common-constants -> v4.1.0 Upgrade dev modules (prettier, tslint, etc)

0.53.3

Width & height utils for 0px (h-0, w-0, maxw-0, maxh-0, minw-0, minh-0, w-all-0, h-all-0)

0.53.2

Fixes error in object module -> get function (where 0 & '' values trigger the default value) Fixes bc-gray in border.scss (it changes border-color, not border-color-right)

0.53.1

New BoolOrError type - either a boolean or an error. Aliases:

- BoolOrErr
- ErrOrBool
- ErrorOrBool
- ErrorOrBoolean
- BooleanOrError

More in-code docs for util-styles (SCSS)

0.53.0

Fixes arrayN function (array module) - can correctly create arrays filled with falsy values


0.52.2

Adds new defineMethod function to object module

0.52.1

Upgrades errorsmith to v0.3.0

0.52.0

Removed Injection aliases:

- MandatoryInjectionViaDecoratorType
- MandatoryInjectionViaDecorator
- MandatoryInjectionType
- RequiredInjectionType
- OptionalInjectedType
- InjectionType

Removed HTTPRequestType aliases:

- AnyHTTPRequestType
- AnyHttpRequestType
- AnyHttpReqType
- HTTPReqType
- HttpRequestType
- HttpReqType

Remove MainHTTPRequestType aliases:

- MainHTTPReqType
- MainHttpRequestType
- MainHttpReqType

Added MainHTTPRequestType aliases:

- CommonHTTPRequestType
- CommonRequestType

Removed StrOrNum aliases:

- NumOrStr
- NumberOrString

Removed StrOrErr alias: StrOrError

- also, corrected StrOrErr to match on string (rather than String)

Removed StringNumHash alias: StringNumberHash

Renamed StrOrNonexistent to StrOrVoid, and removed alias StringOrNonexistent Renamed isNonexistentOrString to isVoidOrString

Added function 'isFunction' on types-iso module Added function 'omit' on 'object' module

Ran prettier on:

- types-react.ts
- types-iso.ts
- object.spec.ts

0.51.3

Cleaned up code in array module

Upgraded React, React-DOM, moment, lodash, nodemon, prettier, & tslint (+ all tslint plugins)

0.51.2

publish script expanded - added docs, renamed, more functionality

*   Made reinstallation into Javelin & webclient optional

0.51.1

Added basic publish script

0.51.0

Eliminated the following aliases from the string module:

*   toSnakecase (alias of toSnakeCase) 
*   rmSpaces, rmWhitespace, eliminateWhitespace (aliases of removeWhitespace) 
*   getFirstMatch, firstMach (aliases of matchFirst)
*   repeatString, repeatChar (aliases of repeatChars)
*   centeredPad (alias of centerPad)
*   withoutSurroundingQuotes (alias of removeSurroundingQuotes)
*   isRegexStr (alias of isRegexString)
*   getFlagsFromRegexStr (alias of getFlagsFromRegexString)

No longer exporting _cleanCharToPadWith from string module (it's now local-only)

Renamed removeSurroundingRegexSlashes -> removeSlashesFlagsSurroundingRegexString & removed aliases:

*   withoutSurroundingRegexSlashes
*   withoutRegexSlashesAndFlags
*   removeRegexSlashesAndFlags
*   removeSurroundingRegexSlashesAndFlags

Removed matchCharInChars from string module, along with aliases isOneOfChars & matchOneOfChars

toSnakeCase now handles slashes (replaces / or \ with _)


0.50.3

Fixed object module error Exported sortObject

0.50.2

Added sortObject function in object module Object module cleanups (prettier, extracted keys from Object, etc.)

0.50.1

Added new function getRandomInt:

  • gets random integer between given min & max values

Typescript upgraded to 2.7.2

Upgraded modules to latest: tslint, eslint, prettier, ts-node, nodemon

Various styling, linting, transpiling, etc configuration changes

  • made consistent with other projects

0.50.0

Prettier run on: error, decorator, function Cleanups in error module - including more added typings 'wip' directory added, work-in-progress error & function code moved into it


0.49.2

Exporting DecoratorTargetType type from decorator module Fixed getDecoratorType docs Removed test code from decorator module

0.49.1

getDecoratorType function added to decorator.ts

  • determines what type of decorator the arguments represent
  • e.g. if arguments received by placing a decorator above a class, emits "CLASS";
     on a static prop, it emits 'STATIC_PROPERTY', etc.

0.48.0

isInteger (isInt) & isIntegerLike (isIntLike) made saner & more robust:

  • isInteger no longer accepts integer-like strings (e.g. "12", "43.0")
    • (reason: that's what isIntegerLike is for).
  • isInteger tries to use built-in Number.isInteger before using custom solution.
  • isIntegerLike now accepts strings ending in .0, .00, .000, .0000, .00000, etc.
  • More extensive isIntegerLike & isInteger tests.

SCSS utils:

  • More overflow SCSS util types
  • Cleaned up SCSS layout utils & handled more titling edge cases

Unit test for regular expressions given to removeMatchingText function


0.47.3

Number->createChangeArray :: Now handles:

  • negative incrementor
  • equal start val & end val
  • incrementor of '0' (it throws, unless start val === end val)
  • end val lower than start val (it creates a decrementing array)

More createChangeArray unit tests.

0.47.2

Better docs, arg names, generic names, & generic defaults for: Object->defineProp Object->defineImmutableProp Object->defineMutableProp Object->defineGetterProp

Added Object->defineProp to README.md. Fixed CHANGELOG.md formatting.

0.47.1

Object#defineProp: Better docs, wrote unit tests

0.47.0

Validation#isValidString:

  • unit tested (most of it, but not 100% thoroughly)
  • added new 'exact length' condition (len, length, exact_length, length_equals)
  • custom error ourputs on fail, for conditions where no error message given
  • changed 'error' param in 'condition' object (within 'conditions' array) to be 'errMsg'
  • more reusable typings
  • conditions turned into union types with all allowed values provided, rather than being treated as being type 'string'

0.46.1

Object#get: Fixed generic typing.

  • New generic type for function: <O = any, T extends object = {}>
    • Reason: with previous generic signature, it was impossible to define an output type without an input type

Object#define*Prop - minor type fixes (generic can now more easily specify the new property value) Unit tested Object#defineGetterProp

0.46.0

Object#get:

  • handles square braces for grabbing values (not just dots)
  • more robust 'bad input' detection
  • fails with undefined
  • gives undefined rather than throwing under more circumstances
  • allows combination of . and [] for calling
  • unit tested extensively
  • working with arrays (DOES NOT split strings though, which is good)

Array#flatten function created: turns nested arrays into a single flat array

More margin SCSS utils - with negative margins:

  • mt-n75, mb-n75, mr-n75, ml-n75 ...up to:
  • mt-n1000, mb-n1000, mr-n1000, ml-n1000
  • in between:
    • every multiple of 10 up to 100
    • every multiple of 100 or 250, up to 1000

Repaired getFirstUrlPath function in express-routing Unit tested getFirstUrlPath & getLastUrlPath


0.45.2

Aliased overflow util style namespace in SCSS utils - added ovx and ovy prefixes e.g. ovx-hidden ovy-overlay ovx-scroll ovy-visible

0.45.1

More overflow util styles Node -> 8.9.1

0.45.0

MAJOR BREAKING CHANGE :: bug fixed in w-###p size utilities. -all suffix was forgotten, so all w-###p utils acted like w-all-###p utils. This means all w-###p utils contained width, max-width, and mid-width properties, while w-all-###p did not work at all.


0.44.0

Upgraded modules:

  • TS to v2.16.2 (major upgrade)
  • React & React-DOM (both internal) to v16
  • Enzyme to v3 (internal) All tests & functions modified to account for upgraded modules (& prior React upgrade) isTrue & isFalse made fully case-insensitive displayName values added to built-in React components Removed buildNamedSfc/setNamedSfc Rotation SCSS utilities ...etc.

0.43.0

Upgraded typings for React & React-DOM to v16 Fixed peerDependencies to provide a range


0.42.4

Fixed replaceInFile type signature Cleaned file module (shrank size etc)

0.42.3

Using shared mad-logs in node file module Upgraded env-var-helpers & lodash

0.42.0

'prettier' code styling added:

  • module installed
  • configured with .prettierrc config file added
  • styled string.ts, types-iso.ts, types-iso.spec.ts, function.ts, date.ts, array.ts Removed external-location barrel exports from string, array, date, & types-iso Various cleanups in array, string, types-iso, date Types known following type detection methods in types-iso

0.41.0

boolStringToBool: saner behaviour

  • added 2nd param that (if set to false) returns null instead of throwing if invalid input given
  • unit tested boolStringToBool

0.40.0

Removed all re-exports from array included in string module


0.39.12

Added more whitespace utils

0.39.9

Added more align-items, align-self flexbox layout CSS class aliases in SCSS utils

0.39.8

New margin sizes available: 17px, 18px, 17%, 18%, -17px, -18px, -17%, -18% Fixed isNumberLike to handle objects that extend Number Code comment (and autocomplete) fixes/edits in types-iso module New isNumber function - detects if value is any kind of number. Alias:

  • isNum

0.39.5

Number type detection functions can now handle any custom numeric objects with Number as prototype. Applies to:

  • isNumberLike
  • isNumLike
  • isInteger
  • isInt
  • isIntegerLike
  • isIntLike
  • isStringOrNumber This also allows passing of custom numeric objects to castToNum function

0.39.4

Fixed typings & in-code docs in array module

0.39.3

More flexbox SCSS util aliases

0.39.2

Added isInt, isIntLike, isBool aliases Fixed alias export method (partially) in types-iso Set types-iso number detectors to handle Number object instances Updated tests to include new aliases

0.39.1

Added lightened-gray colour to SCSS utils

0.39.0

Removed .bot-* SCSS utils (they took up needless space)


0.38.10

Considerably more position SCSS/CSS utilities

0.38.9

Added more getLangFromUrlPathname aliases:

  • langFromUrl
  • langFromURL
  • getLangFromUrl
  • getLangFromURL

New convenience union type export: StrOrErr, with alias:

  • StrOrError

0.38.2

firstMatch renamed to matchFirst (in string module :: string.ts)

0.38.0

Renamed query module -> url module

  • It's now found in src/url.ts, rather than src/query.ts

Fixed typings of various url (query) module function

Cleaned up url functions to avoid using 'cached' window.location object

  • It now re-retrieves the window.location object on every use, ensuring the value stays fresh.

Added string module function:

  • firstMatch

Added url functions:

  • urlGetQuery, with aliases:

    • getQueryParamString
    • getQueryParamString
    • urlGetQueryString
    • urlGetQueryParamString
  • urlWithoutProtocol, with aliases:

    • urlMinusProtocol
  • urlProtocolString, with aliases:

    • urlGetProtocolString
    • getUrlProtocolString
    • getURLProtocolString
    • getProtocolStringFromUrl
    • getProtocolStringFromURL
  • urlMinusLastPath, with aliases:

    • getURLMinusLastPath
    • getUrlMinusLastPath
  • swapLastURLPath, with aliases:

    • swapLastUrlPath
  • swapMatchingURLPaths, with aliases:

    • swapMatchingUrlPaths
    • swapUrlPaths
    • swapURLPaths
    • urlSwapPathMatches
    • urlSwapMatchingPaths
    • replaceMatchingURLPaths
    • replaceMatchingUrlPaths
    • replaceUrlPaths
    • replaceURLPaths
    • urlReplacePathMatches
    • urlReplaceMatchingPaths

0.37.2

  • Added createRangeArray
    • function to create numeric range arrays with a given start value, end value & value to increment by
  • Added random value generator functions:
    • diceRoll6Sided: randomly outputs 1, 2, 3, 4, 5, or 6
    • coinFlip: randomly outputs 'HEADS' or 'TAILS'

0.37.1

  • More integer ranges added:
    • Now goes all the way to Int1To100, increasing by usual 10 digit increments
    • Int0To[##] series (e.g. Int0To10, Int0To20, Int0To30, ..., Int0To100)
    • Int0To5, Int1To5, Int0To25, Int1To25
    • Int0To1, Int0To2, Int0To3, Int0To7, Int1To2, Int1To3, Int1To7

0.37.0

  • Renamed near-faint-blue -> pale-sky-blue
  • All colours now work with borders (i.e. every colour can be used as a border colour)
    • Borders found at styles with naming convention: 'border-{name-of-colour}'. e.g.: border-blue border-near-light-gray border-pale-sky-blue border-light-purple

0.36.6

  • defineGetterProp method. Aliases:
    • addGetterProp
    • addGetter
    • defineGetter
    • addGetProp
    • defineGetProp

0.36.2

Added functions:

  • removeSurroundingQuotes. Aliases:
    • withoutSurroundingQuotes
  • isRegexString. Aliases:
    • isRegexStr
  • getFlagsFromRegexString. Aliases:
    • getFlagsFromRegexStr
  • removeSurroundingRegexSlashes. Aliases:
    • withoutSurroundingRegexSlashes
    • withoutRegexSlashesAndFlags
    • removeRegexSlashesAndFlags
    • removeRegexLiteralChars

0.36.1

Added function:

  • removeDuplicates. Aliases:
    • uniq, uniqVals, uniqueVals, removeDuplicateVals, removeDuplicateItems
    • uniqChars, uniqueChars, removeDuplicateChars

Made countOccurrences also work for strings (rather than just arrays)

Added numerous aliases for countOccurrences:

*   count, countAll, countItems, countArrayItems
*   countChars, countCharOccurrences, charOccurrences, charCount

0.36.0

Added new 'sample' function - gets a random value from a collection (string, array, or object)

Removed confusing UUID functions from number module and top-level namespace - replaced with props in UUID namespace:

  • noDashes <-- now found at uuid.noDashes
  • genLen6ID, gen6CharID, genLen6Str, gen6CharStr <-- now found at uuid.len6
  • genLen8ID, gen8CharID, genLen8Str, gen8CharStr <-- now found at uuid.len8

More robust isArray check

Added functions:

  • insectKeyTree: Gives detailed information on keys in object's full prototype chain
  • pushIfUniq: Pushes item into array only if array doesn't already have a matching item.
    • alias: pushIfNew
    • alias: pushUniq

Added types:

  • Any: Another alias for any

0.35.0

Upgraded Typescript to 2.5.2

Upgraded Node to 8.6.0

New functions:

  • defineImmutableProp
  • defineMutableProp
  • countOccurences
  • immutablePropConfig
  • isAlphanumericChar
  • isWhitespaceChar
  • isNumericChar
  • isOperatorChar
  • getArgsFromFuncAsString, with aliases:
    • getParamNames
    • getParameterNames
    • getArgNames
    • getArgumentNames

New types:

  • StringHash
  • StringNumHash
  • StringNumberHash

Fixed date tests


0.25.0

Upgraded Typescript version to 2.3.0, from 2.2.1 Set all React packages to install from 15.x


0.24.0

withLeftIndent has breaking changes

  • Behaves more predictably (and usefully).
    • Defaults to indent of 0 (first-line variable thus no longer always required)
    • Removes unpredictable addition of 4 spaces to indent (it now always indents to the expected size)
    • No longer includes the last line in its 'initial indent' calculation.
      • Thus avoiding issues where the last line knocks everything forward or backward based on the text alignment scheme.
  • Essentially anything relying on previous broken withLeftIndent behaviour will have errors.