
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@slimr/util
Advanced tools
A set of slim JS polyfills with tree-shaking support
@slimr is a set of slim React (hence '@slimr') libs. Check them all out on github!
Append a link, script, style, or ANY element to the head of the document if not already added
Deep compare methods
./src/equality-deep.ts, npm:fast-deep-equalShallow compare methods
./src/equality-deep.ts, npm:fast-shallow-equalDeeply copy two objects
const obj1 = [
{foo: 'bar', arr: [2]},
{foo: 'bar2', arr: [3]},
]
const obj2 = copy(obj1)
Generate a random string of 12 characters, provided by npm:nanoid.
const id = createUid()
Don't call a function until a certain amount of time has passed without it being called.
In other words, we intentionally delay invoking fnc until after delay milliseconds have elapsed since the last time the debounced. If it gets called again, we cancel the previous call and start a new timer.
./src/debounce.tsconst fnc = async () => 2
const debounced = debounce(fnc, 250)
debounced()
debounced()
debounced()
await sleep(250)
debounced()
debounced()
debounced()
await sleep(250)
// fnc would only be called twice
Deep compare methods provided by npm:deep-object-diff, which return an object describing the differencees between two objs.
Highlight code elements using highlight.js
./src/code-highlight-lazy.ts, npm:highlight.jsExtracts form values from a form element, such as e.target from form.onSubmit
./src/form-to-values.tsWhy not FormData?
Quickly converts any plain object, string, number, and more to a 32bit/64bit hash number or string
./src/hash.tshash32('hello world') // 1047750623
hash32('hello world', true) // 'hbsxjz'
hash32({hello: 'world'}) // 141133545
hash64('hello world') // 927946135
hash64('hello world', true) // 'fch3tj'
hash64({hello: 'world'}) // 1139059049
NOTE hash64 is not a true 64 bit hash and has higher collision odds than a true 64 bit hash.
Collisions are possible and likelyhood increases with the number of hashes.
Ideal collision odds:
References
A set of is-type methods to easily check if a value is a type.
isPositiveNumber(-2) // false
isFullArray([]) // false
isEmptyArray([]) // true
Limit the size of a map by evicting the least-recently-used (aka LRU) items. Works by monkey-patching the get and set of a map instance
./src/map-apply-max-size.ts, ./src/stringify.tsconst t = mapApplyMaxSize(new Map(), 2)
t.set('a', 1)
t.set('b', 2)
t.set('a', 3) // refreshes 'a'
t.set('c', 3) // should evict 'b'
expect(t.get('b')).toBeUndefined()
t.set('d', 4) // should evict 'a'
expect(t.get('a')).toBeUndefined()
t.get('c')
t.set('e', 5) // should evict 'd'
expect(t.get('d')).toBeUndefined()
A memoization wrapper with ttl expiration for cache hits.
./src/memoize.tsDeeply merge objects or arrays in a familiar pattern to Object.assign
merge({foo: 'bar', arr: [2]}, {foo: 'bar2', arr: [3]}) // {foo: bar2, arr: [3]}
mergeAndConcat({foo: 'bar', arr: [2]}, {foo: 'bar2', arr: [3]}) // {foo: bar2, arr: [2, 3]}
mergeAndCompare(concatStrings, {name: 'John'}, {name: 'Simth'})
// returns { name: 'JohnSmith' }
function concatStrings(originVal, newVal, key) {
if (typeof originVal === 'string' && typeof newVal === 'string') {
// concat logic
return `${originVal}${newVal}`
}
// always return newVal as fallback!!
return newVal
}
Applies a mask to a string of numbers, helpful for phone numbers
Grabs all of the numbers out of str into an array, then assembles the mask and replaces the '#' with the numbers in order
numericStringMask('1234567890', '(###) ### - ####') // (123) 456 - 7890
numericStringMask('1234567890', '(###) ### - ####') // (123) 456 - 7890
numericStringMask('(123)abc45678-90', '(###) ### - ####') // (123) 456 - 7890
numericStringMask('1234567890', '(###) ###-####') // (123) 456-7890
numericStringMask('11900567890', '(##) #####-####') // (11) 90056-7890
// react input usage
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
e.currentTarget.value = numericStringMask(e.target.value, '(###) ###-####')
// Replaces so we don't add characters past the end of the string,
// and so the user can delete characters
.replace(/-$/, '') // changes '(123) 456-' to '(123) 456'
.replace(/\) $/, '') // changes '(11)' to '(11'
.replace(/\($/, '') // changes '(' to ''
}
Allows setting common page attrs.
Note: Set
window.setPageMetaSkip=trueto disable setPageMeta for testing
Parameters:
title - Sets title, meta:og:title. Is postfixed by ' - {siteName}'siteName - Sets meta:og:site_namedescription - Sets meta:descriptionimage - Sets meta:og:imagelocale - Sets meta:og:localAssumption: The page should already have the following meta tags, to be used as defaults:
<title>React Template</title>
<meta property="og:title" content="React template" />
<meta property="og:site_name" content="React Template" />
<meta property="og:locale" content="en_US" />
<link rel="canonical" href="https://react-template.com" />
<meta name="description" content="A template to build tiny Preact applications" />
<meta property="og:description" content="A template to build tiny React applications" />
<meta property="og:url" content="https://github.com/bdombro/react-template" />
<meta property="og:image" content="https://preact-template.com/apple-touch-icon.png" />
Usage:
const {description} = setPageMeta({
title: `Hello World`,
description: 'This page is awesome',
})
A safe JSON.stringify wrapper that limits recursion
./src/stringify.tsConvert a string to camelCase
toCamelCase('hello_world') // helloWorld
Convert a string to kebab-case
toCamelCase('hello_world') // hello-world
FAQs
A set of slim JS polyfills with tree-shaking support
We found that @slimr/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.