@yamato-daiwa/es-extensions v1.6.11
@yamato-daiwa/es-extensions
Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety without any
type.
Installation
npm i @yamato-daiwa/es-extensions -E
Temporary simple documentation
Please refer to this documentation during the official documentation is under development.
Get functionality
Most of the functionality is available for both Browser JavaScript and Node.js.
export { isUndefined, isNull } from "@yamato-daiwa/es-extensions";
BrowserJS functionality
export { delegateClickEventHandling } from "@yamato-daiwa/es-extensions/BrowserJS";
NodeJS functionality
export { NodeJS_Timer } from "@yamato-daiwa/es-extensions/NodeJS";
Functionality reference
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 supports 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.capitalizeFirstSymbol
Capitalizes first symbol of target string value.getLastSymbol
Returns the last symbol of target string value.getPositionsOfAllSubstringOccurrences
Returns the positions of each occurrence of specified substring.removeAllSpecifiedCharacters
Removes specified characters from the string value.removeNonDigitsCharacters
Removes all characters from the string excepts digits.removeNthSymbol
Removes the symbol in specified position from the string. Supports the surrogate pairs.replace2OrMoreSpacesTo1
eplaces 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 symbols sequence in string value.splitString
Alternative of nativeString.prototype.split()
supporting surrogate pairs.stringifyAndFormatUnknownAtAdvanceEntity
Converts to readable string any type of data.
Arrays
getArrayElementWhichMustExistByPredicate
Returns the first satisfies to predicate array element. If no such element,UnexpectedEventError
will be thrown.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.
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
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.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
.getRandomLatinSymbol
Returns random latin symbol.getRandomObjectPropertyValue
Returns random object property value.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.BasicFrontEndLogger
The implementation ofILogger
interface for theLogger
facade which could be used as the base of the custom implementation for the frontend side of the websites / web application.- 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 symbols 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.
1 day ago
1 month ago
1 month ago
22 days ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
5 months ago
5 months ago
6 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago