Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety.

Usage no npm install needed!

<script type="module">
  import yamatoDaiwaEsExtensions from 'https://cdn.skypack.dev/@yamato-daiwa/es-extensions';


Yamato-Daiwa ES Extensions (YDEE)

No any type No dependencies NPM Version IntelliJ IDEA plugin

Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety without any type.

Hero image of @yamato-daiwa/es-extensions


Hint: Set the unlabeled slider in the top right corner of the screen to XL to see the tags and descriptions.


⚠️ Request to Stack Overflow users with >=1500 reputation

My account has not enough reputation to create the tag for @yamato-daiwa/es-extensions and start to answer the related questions. Please create it instead of me and notify me to tokugawa.takesi@gmail.com.

  • Tag name: @yamato-daiwa/es-extensions
  • Description: Helper functions and classes aimed to reduce the routine code. Oriented to TypeScript users investing the time to type-safety.


npm i @yamato-daiwa/es-extensions -E


Get functionality

All available functionality could be imported from "@yamato-daiwa/es-extensions":

export { isUndefined, isNull } from "@yamato-daiwa/es-extensions";

Functionality reference


The tool for the unknown at advance external data (from HTTP request/response, file, etc.) validation and processing.



All functions working with strings are supporting the surrogate pairs. If some function works incorrectly with surrogate pairs, it means the bug; please feel free to open issue in this case.

  • areStringifiedDigitsOnly Checks is string value consists exclusively from the digits.
  • capitalizeFirstCharacter Capitalizes first character of target string value.
  • EmailAddress Class working with email addresses. Currently, consists from validating function and regular expression of valid emails.
  • getLastCharacter Returns the last character of target string value.
  • getPositionsOfAllSubstringOccurrences Returns the positions of each occurrence of specified substring.
  • removeAllSpecifiedCharacters Removes specified characters from the string value.
  • removeLastCharacter Removes last character.
  • removeNonDigitsCharacters Removes all characters from the string excepts digits.
  • removeNthCharacter Removes the symbol in specified position from the string. Supports the surrogate pairs.
  • replace2OrMoreSpacesTo1 replaces 2 or more spaces to 1.
  • replaceBrHTML_TagToNewLineEscapeSequence Replaces the "br" HTML tag to new line (line feed) escape sequence.
  • insertSubstring Insets nullable substring with optional condition and transformations.
  • insertSubstringIf Insets substring conditionally.
  • reverseString Reverses the characters sequence in string value.
  • splitString Alternative of native String.prototype.split() supporting surrogate pairs.
  • stringifyAndFormatArbitraryValue Converts to readable string any type of data.
  • replaceDoubleBackslashesWithForwardSlashes Replaces double backslashes with forward slashes.
  • trimSpaces Trim prepended and/or appended space characters; unlike native String.prototype.trim acts selectively on specified spaces kinds.




Date & Time


  • ParsedJSON and related The native object including the Array case which could be the result of JSON parsing.
  • InheritEnumerationKeys Allows to create the object with same key as reference enumeration.
  • PartialBy Makes specified properties of base type optional.

Type guards

Default value subsituters

  • substituteWhenNull Substitutes the second argument's value when first one is null
  • substituteWhenUndefined Substitutes the second argument's value when first one is undefined

Value transformers

  • emptyStringToNull
  • nullToEmptyString
  • nullToUndefined
  • nullToZero
  • undefinedToEmptyArray
  • undefinedToEmptyString
  • undefinedToNull

Random values generators

  • getRandomArrayElement Returns the random element of specified array.
  • getRandomBoolean Returns true or false randomly.
  • getRandomInteger Returns random integer not less than specified minimalValue and more than maximalValue.
  • getRandomLatinCharacter Returns random latin character.
  • getRandomObjectPropertyValue Returns random object property value.
  • getRandomSubarray Returns the selection of elements of specified array; minimal and maximal elements count could be specified.
  • getSpecificBooleanValueWithProbability Returns specific boolean value with specified probability.

Constants and enumerations



  • Logger facade Basic facade for providing of the high-quality logging with customizable output destinations, formatting and limitations.
  • Pre-made errors
    • AlgorithmMismatchError Recommended to throw in general cases when real behaviour of the program is not corresponding to desired.
    • ClassRedundantSubsequentInitializationError Recommended to throw when the class intended to be a singleton has been attempted to initialize twice.
    • ClassRequiredInitializationHasNotBeenExecutedError Recommended to throw when the class besides the construction requires the initialization, but the initialization has not been executed.
    • ConfigFileNotFoundError Recommended to throw when some utility requires the config file bit it has not been found.
    • CrossBrowserIssueError Recommended to throw when some processing could not be executed because of certain browsers's limitations.
    • DataRetrievingFailedError Recommended to throw when the data retrieving from any external resource (server, database, etc.) was failed.
    • DataSubmittingFailed Recommended to throw when the data submitting to any external resource (server, database, etc.) was failed.
    • DOM_ElementRetrievingFailedError Recommended to throw when some requiring element retrieving from the DOM has been failed.
    • FileReadingFailedError Recommended to throw when the file reading was not go as expected.
    • FileWritingFailed Recommended to throw when the file writing was not go as expected.
    • ImproperUsageError Recommended to throw when the cass/function has been attempted to use improperly. However, try to name the function/methods such as it will be obvious how to use it and also limit the usage by TypeScript typing.
    • IncompatiblePropertiesInObjectTypeParameterError Recommended to throw when in parameter exampleParameter of object type one of properties exampleParameter.propertyA and exampleParameter.propertyB must be omitted but both has been specified.
    • InterProcessInteractionFailedError Recommended to throw when the interaction between NodeJS processed is not going as expected. Could be actual for the Electron.js where the main process and render process exchanging by data.
    • InvalidConfigError Recommended to throw when config validation was not passed. Append the validation errors messages to InvalidConfigError's message.
    • InvalidExternalDataError Recommended to throw when the data from the external data source does not match with expected. Append the validation errors messages to InvalidExternalDataError's message.
    • InvalidParameterValueError Recommended to throw when the parameter's does not fit to some limitations. Although the TypeScript allows to define and check the parameter's type, this functionality will not be available if the library will be used by JavaScript users. Also, is the parameter has limitations like smallest numerical value or maximal characters count, InvalidParameterValueError has been developed for such cases.
    • ModuleDynamicLoadingFailedError Recommended to throw when the module dynamical loading failed.
    • UnexpectedEventError Recommended to throw when the probability of the occurrence of some else if branch is very small and impossible for normal operation of the program.
    • UnsupportedScenarioError Recommended to throw when occurred some scenario which the does not supports yet.