Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add startsWith and endsWith utility functions #389

Merged
merged 9 commits into from
Dec 1, 2023

Conversation

titouanmathis
Copy link
Contributor

@titouanmathis titouanmathis commented Jul 31, 2023

This PR adds two new utility functions to tests if a string starts or ends with another string. Both new functions are more performant than the native String.prototype.startsWith and String.prototype.endsWith function, tested on Chrome, Firefox, and Safari with the following benchmarks:

import { startsWith, endsWith } from '@studiometa/js-toolkit/utils';

console.log(startsWith('foo', 'f')); // true
console.log(startsWith('foo', 'b')); // false

console.log(endsWith('foo', 'o')); // true
console.log(endsWith('foo', 'a')); // false

To-do

  • Add documentation
  • Update changelog

@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c335cec) 97.68% compared to head (af384e9) 97.69%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #389      +/-   ##
===========================================
+ Coverage    97.68%   97.69%   +0.01%     
===========================================
  Files           97       99       +2     
  Lines         2245     2257      +12     
  Branches       538      542       +4     
===========================================
+ Hits          2193     2205      +12     
  Misses          51       51              
  Partials         1        1              
Flag Coverage Δ
unittests 97.69% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

github-actions bot commented Jul 31, 2023

Export Size

@studiometa/js-toolkit

Name Size Diff
endsWith 88 B +88 B (+100.00%) 🔺
startsWith 87 B +87 B (+100.00%) 🔺
historyPush 499 B +38 B (+8.24%) 🔺
historyReplace 503 B +37 B (+7.94%) 🔺
withBreakpointObserver 1.25 kB +36 B (+2.98%) 🔺
withScrolledInView 1.97 kB +39 B (+2.02%) 🔺
animate 2.37 kB +27 B (+1.15%) 🔺
UTILS 5.91 kB +66 B (+1.13%) 🔺
Base 7.23 kB +50 B (+0.70%) 🔺
DECORATORS 6.52 kB +44 B (+0.68%) 🔺
FRAMEWORK 11.71 kB +48 B (+0.41%) 🔺
ALL 15.78 kB +55 B (+0.35%) 🔺
Unchanged

@studiometa/js-toolkit

Name Size Diff
addClass 219 B -
addStyle 232 B -
boundingRectToCircle 154 B -
clamp 67 B -
clamp01 87 B -
collideCircleCircle 99 B -
collideCircleRect 159 B -
collidePointCircle 112 B -
collidePointRect 103 B -
collideRectRect 99 B -
createApp 292 B -
createEaseInOut 116 B -
createEaseOut 71 B -
damp 78 B -
debounce 92 B -
domScheduler 296 B -
ease 410 B -
easeInCirc 68 B -
easeInCubic 59 B -
easeInExpo 80 B -
easeInOutCirc 141 B -
easeInOutCubic 130 B -
easeInOutExpo 134 B -
easeInOutQuad 128 B -
easeInOutQuart 133 B -
easeInOutQuint 152 B -
easeInOutSine 151 B -
easeInQuad 63 B -
easeInQuart 61 B -
easeInQuint 62 B -
easeInSine 77 B -
easeOutCirc 115 B -
easeOutCubic 103 B -
easeOutExpo 112 B -
easeOutQuad 103 B -
easeOutQuart 100 B -
easeOutQuint 103 B -
easeOutSine 121 B -
focusTrap 496 B -
getAncestorWhere 91 B -
getAncestorWhereUntil 119 B -
getClosestParent 178 B -
getComponentResolver 138 B -
getDirectChildren 183 B -
getInstanceFromElement 90 B -
getOffsetSizes 160 B -
hasWindow 62 B -
HELPERS 1.17 kB -
importOnInteraction 440 B -
importOnMediaQuery 236 B -
importWhenIdle 223 B -
importWhenPrefersMotion 275 B -
importWhenVisible 465 B -
inertiaFinalValue 142 B -
isArray 70 B -
isBoolean 78 B -
isDefined 86 B -
isDev 72 B -
isDirectChild 212 B -
isFunction 72 B -
isNumber 84 B -
isObject 105 B -
isString 86 B -
keyCodes 100 B -
lerp 57 B -
map 71 B -
matrix 106 B -
memoize 189 B -
nextFrame 175 B -
nextMicrotask 111 B -
nextTick 134 B -
noop 39 B -
noopValue 49 B -
objectToURLSearchParams 302 B -
Queue 226 B -
removeClass 217 B -
removeStyle 233 B -
round 56 B -
scrollTo 417 B -
SERVICES 3.12 kB -
SmartQueue 411 B -
throttle 101 B -
toggleClass 220 B -
transform 317 B -
transition 924 B -
tween 1.22 kB -
useDrag 1.65 kB -
useKey 630 B -
useLoad 373 B -
usePointer 837 B -
useRaf 726 B -
useResize 640 B -
useScheduler 290 B -
useScroll 697 B -
useService 254 B -
wait 79 B -
withBreakpointManager 1.05 kB -
withDrag 1.79 kB -
withExtraConfig 135 B -
withFreezedOptions 140 B -
withIntersectionObserver 279 B -
withLeadingCharacters 88 B -
withLeadingSlash 107 B -
withMountOnMediaQuery 338 B -
withMountWhenInView 313 B -
withMountWhenPrefersMotion 390 B -
withoutLeadingCharacters 86 B -
withoutLeadingCharactersRecursive 124 B -
withoutLeadingSlash 93 B -
withoutTrailingCharacters 98 B -
withoutTrailingCharactersRecursive 129 B -
withoutTrailingSlash 103 B -
withRelativePointer 987 B -
withResponsiveOptions 1.86 kB -
withTrailingCharacters 96 B -
withTrailingSlash 120 B -
withVue2 369 B -

@titouanmathis titouanmathis marked this pull request as draft July 31, 2023 14:12
@titouanmathis titouanmathis marked this pull request as ready for review December 1, 2023 10:57
@titouanmathis titouanmathis merged commit c7654a3 into develop Dec 1, 2023
14 checks passed
@titouanmathis titouanmathis deleted the feature/starts-ends-with-utils branch December 1, 2023 11:48
@titouanmathis titouanmathis mentioned this pull request Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant