README
Yamato-Daiwa ES Extensions (YDEE)
Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety without any
type.
Roadmap
Hint: Set the unlabeled slider in the top right corner of the screen to XL
to see the tags and descriptions.
>=1500
reputation
⚠️ Request to Stack Overflow users with 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.
Installation
npm i @yamato-daiwa/es-extensions -E
Documentation
Get functionality
All available functionality could be imported from "@yamato-daiwa/es-extensions"
:
export { isUndefined, isNull } from "@yamato-daiwa/es-extensions";
Functionality reference
RawObjectDataProcessor
The tool for the unknown at advance external data (from HTTP request/response, file, etc.) validation and processing.
Numbers
formatNumberWith4KetaKanji
Formats number with 4-digits Kanji万
,億
,兆
,系
(CJK ideographic characters)isStringifiedNonNegativeIntegerOfRegularNotation
Checks is the value of string contains the number of non-scientific notation.separateEach3DigitsGroupWithComma
Formats the number separating each 3 digits group with commaseparateEach4DigitsGroupWithComma
Formats the number separating each 4 digits group with comma
Strings
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 nativeString.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 nativeString.prototype.trim
acts selectively on specified spaces kinds.
Arrays
getArrayElementMatchingWithPredicateIfSuchElementExactlyOne
Returns the element of specified array matching with the predicate if such element is exactly one, otherwise error will be thrown ornull
will be returned (depending on dedicated option's value).getLastElementOfNonEmptyArray
Return the last element of array. If no such element,UnexpectedEventError
will be thrown.getIndexesOfArrayElementsWhichSatisfiesToPredicate
Returns the array of indexes of elements of array which are satisfies to predicate function.getIndexOfArrayElementByPredicate
Returns the index of array element matching with predicate ofnull
if no such element.twoDimensionalizeArray
Converts flat array to 2-dimensional array with nested arrays of fixed elements count.
Sets
addMultipleElementsToSet
Adds multiple elements to set.
Maps
addMultiplePairsToMap
Adds multiple elements to map.createMapBasedOnOtherMap
Creates map based on other map.filterMap
Filters map by specified predicate.
Date & Time
TimePoint
The alternative to nativeDate
allows to build the formatted date/time strings easily.getDaysCountInSpecificMonth
Return days count in specified year and month.getMonthNameByNumber
Converts the month number (from 0 or 1) to element of MonthsNames enumeration.getMonthNumberByName
Converts the element of MonthsNames enumeration to number of month (from 0 or 1)millisecondsToSeconds
Converts milliseconds amount to amount of seconds.secondsToMilliseconds
Converts seconds amount to amount of milliseconds.
Types
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 isnull
substituteWhenUndefined
Substitutes the second argument's value when first one isundefined
Value transformers
emptyStringToNull
nullToEmptyString
nullToUndefined
nullToZero
undefinedToEmptyArray
undefinedToEmptyString
undefinedToNull
Random values generators
getRandomArrayElement
Returns the random element of specified array.getRandomBoolean
Returnstrue
orfalse
randomly.getRandomInteger
Returns random integer not less than specifiedminimalValue
and more thanmaximalValue
.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
Pagination
computeFirstItemNumberForSpecificPaginationPage
Computes the first item number for specified pagination page.computeLastItemNumberForSpecificPaginationPage
Computes the last item number for specified pagination page.
Logging
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 parameterexampleParameter
of object type one of propertiesexampleParameter.propertyA
andexampleParameter.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 toInvalidConfigError
's message.InvalidExternalDataError
Recommended to throw when the data from the external data source does not match with expected. Append the validation errors messages toInvalidExternalDataError
'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 someelse 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.