2.1.41 • Published 6 months ago

extra-string v2.1.41

Weekly downloads
2
License
MIT
Repository
github
Last release
6 months ago

A collection of common string functions. 📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs.

A string is a sequence of characters. In JavaScript, strings are not mutable. Any transfomation of a string, such as slice or concat generates a new string. The JavaScript runtime however may optimize this behavior by mutating strings behind the scenes, when it can be guarenteed that the previous string is not accessible to the programmer. The runtime may also avoid copying slices of a string, or even concatenation of slices of strings, by implementing it as a series of lookups into existing strings. Food for thought.

This package provides functions for generating spaces; querying about a string such as is, isEmpty, isCharacter, index, indexRange, codePointRange; comparing strings such as compare, isEqual; getting parts of a string such as get, getAll, set, begin, middle, end; searching a string such as longestCommonInfix, longestCommonPrefix, longestCommonSuffix, longestUncommonInfixes; transforming a string such as toBaseline, toSuperscript, toSubscript; transforming case of a string such as toKebabCase, toSnakeCase, toCamelCase, toPascalCase; finding ngrams in strings such as ngrams, uniqueNgrams, countNgrams, countUniqueNgrams, countEachNgram, matchingNgrams, uniqueMatchingNgrams, countMatchingNgrams, countEachMatchingNgram, countUniqueMatchingNgrams; and finding similarity/distance between strings such as euclideanDistance, hammingDistance, jaccardIndex, jaccardDistance, sorensenDiceIndex, sorensenDiceDistance, tverskyIndex, tverskyDistance, jaroSimilarity, jaroDistance, jaroWinklerSimilarity, jaroWinklerDistance, levenshteinDistance, damerauLevenshteinDistance.

This package also provides Array-like functions for strings. These includes functions for generating a string such as of, from; transforming a string such as splice, reverse, sort; and functional behavior such as filter. All built-in string functions are also included. Finally, constants for ASCII characters, and minimum/maximum code point are included.

This package is available in both Node.js and Web formats. The web format is exposed as extra_string standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.

const string = require('extra-string');
// import * as string from "extra-string";
// import * as string from "https://unpkg.com/extra-string/index.mjs"; (deno)

string.longestCommonInfix('dismiss', 'mississipi');
// → 'miss'

string.longestUncommonInfixes('chocolatier', 'engineer');
// → ['chocolati', 'engine']

string.toKebabCase('Malwa Plateau');
// → 'malwa-plateau'

'6.626 x 10' + string.toSuperscript('-34');
// → '6.626 x 10⁻³⁴' (Planck's constant)

string.tverskyDistance('pikachu', 'raichu', 3, 0.2, 0.4);
// → 0.6666666666666667

Index

PropertyDescription
DIGITSDecimal digits 0-9.
OCT_DIGITSOctal digits 0-7.
HEX_DIGITSHexadecimal digits 0-9, A-F, a-f.
UPPERCASEEnglish letters A-Z.
LOWERCASEEnglish letters a-z.
LETTERSCombination of uppercase, lowercase english letters.
PUNCTUATIONPunctuation symbols (ASCII).
WHITESPACEThe string "\t\n\x0b\x0c\r ".
PRINTABLECombination of digits, letters, punctuation, and whitespace (ASCII).
MIN_CODE_POINTMinimum unicode code point.
MAX_CODE_POINTMaximum unicode code point.
fromCharCodeGet characters whose UTF-16 code units are given.
fromCodePointGet characters whose unicode code points are given.
concatCombine multiple strings into one.
repeatRepeat string given number of times.
valueOfGet primitive value of string object.
lengthGet length of string.
charAtGet character at given index in string.
charCodeAtGet UTF-16 code unit of a character in string.
codePointAtGet unicode code point of a character in string.
localeCompareCompare two strings in the current or given locale.
includesCheck if string has a given infix.
startsWithCheck if string has a given prefix.
endsWithCheck if string has a given suffix.
indexOfGet first index of a given infix in string.
lastIndexOfGet last index of a given infix in string.
searchGet first index of regular expression match in string.
matchGet results of matching string with regular expression.
matchAllGet detailed results of matching string with regular expression.
toStringGet string representation of string.
sliceExtract section of string.
substringExtract section of string.
splitSplit string by a given separator into substrings.
trimStartRemove whitespace from begining of string.
trimEndRemove whitespace from end of string.
trimRemove whitespace from begining and end of string.
padStartPad start of string to fit a desired length.
padEndPad end of string to fit a desired length.
toUpperCaseConvert string to upper case.
toLocaleUpperCaseConvert string to upper case, as per locale-specific case mappings.
toLowerCaseConvert string to lower case.
toLocaleLowerCaseConvert string to lower case, as per locale-specific case mappings.
replaceReplace first match of given pattern by replacement.
normalizeNormalize string by given form, as per Unicode Standard Annex #15.
ofCreate string from arguments, like Array.of().
fromCreate string from iterable, like Array.from().
spliceRemove/replace characters in a string.
reverseReverse a string.
sortArrange characters in an order.
filterFilter characters which pass a test.
spacesGet a string of spaces.
isCheck if value is a string.
isEmptyCheck if string is empty.
isCharacterCheck if string is a character.
indexGet non-negative index within string.
indexRangeGet non-negative index range within string.
codePointRangeGet unicode code point range of string.
compareCompare two strings.
isEqualCheck if two strings are equal.
getGet character at a given index in string.
getAllGet characters at indices.
setWrite a substring at specified index in string.
beginGet leftmost part of string.
middleGet a portion of string from middle.
endGet rightmost part of string.
longestCommonInfixGet the longest common infix between strings.
longestCommonPrefixGet the longest common prefix of strings.
longestCommonSuffixGet the longest common suffix of strings.
longestUncommonInfixesGet the longest uncommon infixes of strings.
toBaselineConvert a string to baseline characters (limited support).
toSuperscriptConvert a string to superscript characters (limited support).
toSubscriptConvert a string to superscript characters (limited support).
toKebabCaseConvert a string to kebab-case.
toSnakeCaseConvert a string to snake-case.
toCamelCaseConvert a string to camel-case.
toPascalCaseConvert a string to pascal-case.
ngramsGet n-grams of a string.
uniqueNgramsFind unique n-grams of a string.
countNgramsCount the total number of n-grams of a string.
countUniqueNgramsCount the total number of unique n-grams of a string.
countEachNgramCount each n-gram of a string.
matchingNgramsGet matching n-grams between strings.
uniqueMatchingNgramsGet unique matching n-grams between strings.
countMatchingNgramsCount the total number of matching n-grams between strings.
countEachMatchingNgramCount each matching n-gram between strings.
countUniqueMatchingNgramsCount the total number of unique matching n-grams between strings.
euclideanDistanceGet euclidean distance between strings.
hammingDistanceGet hamming distance between strings.
jaccardIndexGet jaccard index between strings.
jaccardDistanceGet jaccard distance between strings.
sorensenDiceIndexGet Sørensen-Dice index between strings.
sorensenDiceDistanceGet Sørensen-Dice distance between strings.
tverskyIndexGet Tversky index between strings.
tverskyDistanceGet Tversky distance between strings.
jaroSimilarityGet Jaro similarity between strings.
jaroDistanceGet Jaro distance between strings.
jaroWinklerSimilarityGet Jaro-Winkler similarity between strings.
jaroWinklerDistanceGet Jaro-Winkler distance between strings.
levenshteinDistanceGet Levenshtein distance between strings.
damerauLevenshteinDistanceGet Damerau–Levenshtein distance between strings.

References

npm.io ORG DOI Coverage Status Test Coverage Maintainability

2.1.41

6 months ago

2.1.39

1 year ago

2.1.40

1 year ago

2.1.9

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.14

2 years ago

2.1.15

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.18

2 years ago

2.1.19

2 years ago

2.1.27

2 years ago

2.0.59

2 years ago

2.1.28

2 years ago

2.1.25

2 years ago

2.0.57

2 years ago

2.1.26

2 years ago

2.0.58

2 years ago

2.1.23

2 years ago

2.1.24

2 years ago

2.0.56

2 years ago

2.1.21

2 years ago

2.1.22

2 years ago

2.1.20

2 years ago

2.1.29

2 years ago

2.1.38

2 years ago

2.1.36

2 years ago

2.0.68

2 years ago

2.1.37

2 years ago

2.0.69

2 years ago

2.1.34

2 years ago

2.0.66

2 years ago

2.1.35

2 years ago

2.0.67

2 years ago

2.1.32

2 years ago

2.0.64

2 years ago

2.1.33

2 years ago

2.0.65

2 years ago

2.1.30

2 years ago

2.0.62

2 years ago

2.1.31

2 years ago

2.0.63

2 years ago

2.0.60

2 years ago

2.0.61

2 years ago

2.0.79

2 years ago

2.0.77

2 years ago

2.0.78

2 years ago

2.0.75

2 years ago

2.0.76

2 years ago

2.0.73

2 years ago

2.0.74

2 years ago

2.0.71

2 years ago

2.0.72

2 years ago

2.0.70

2 years ago

2.0.88

2 years ago

2.0.89

2 years ago

2.0.86

2 years ago

2.0.87

2 years ago

2.0.84

2 years ago

2.0.85

2 years ago

2.0.82

2 years ago

2.0.83

2 years ago

2.0.80

2 years ago

2.0.81

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.0

2 years ago

2.0.90

2 years ago

2.0.29

2 years ago

2.0.37

2 years ago

2.0.38

2 years ago

2.0.35

2 years ago

2.0.36

2 years ago

2.0.33

2 years ago

2.0.34

2 years ago

2.0.31

2 years ago

2.0.32

2 years ago

2.0.30

2 years ago

2.0.39

2 years ago

2.0.48

2 years ago

2.0.49

2 years ago

2.0.46

2 years ago

2.0.47

2 years ago

2.0.44

2 years ago

2.0.45

2 years ago

2.0.42

2 years ago

2.0.43

2 years ago

2.0.40

2 years ago

2.0.41

2 years ago

2.0.55

2 years ago

2.0.53

2 years ago

2.0.54

2 years ago

2.0.51

2 years ago

2.0.52

2 years ago

2.0.50

2 years ago

2.0.27

2 years ago

2.0.22

3 years ago

2.0.21

4 years ago

2.0.20

4 years ago

2.0.19

4 years ago

2.0.18

4 years ago

2.0.17

4 years ago

2.0.15

4 years ago

2.0.16

4 years ago

2.0.13

4 years ago

2.0.14

4 years ago

2.0.11

4 years ago

2.0.12

4 years ago

2.0.10

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago