
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
@productive-codebases/toolbox
Advanced tools
Some useful functions and types.
Set of functions and types used across the different projects of Productive Codebases.
Typescript is not mandatory but highly recommended.
npm install @productive-codebases/toolbox
isDefined
Return true if the value is neither null nor undefined.
Usage:
if (isDefined(x)) {
//...
}
Return true if the value is truthy.
Usage:
if (isTruthy(x)) {
//...
}
Ensure that a value is an array.
Usage:
ensureArray(x).map(...)
Ensure that a value is a set.
Usage:
ensureSet(x).forEach(...)
Merge deeply multiple objects.
Usage:
const mergedObjects = deepMerge([object1, object2], optionalOptions)
Index / Append entities (objects) to a map.
Usage:
const entities = indexEntitiesToMap(entitiesAsArray, 'id')
const entityId1 = entities.get('1')
Add or remove a value to a set, indexed by a key.
Usage:
const map = new Map()
addSetValueToMap(map, '1', 'value')
const set = map.get('1')
Allow to ensure that all cases of a switch
are implemented by returning a never
type in the default case.
Usage:
switch (unionOfValues) {
case 'value1': {
// ...
}
case 'value2': {
// ...
}
default: {
assertUnreachableCase(unionOfValues)
}
}
Container allowing to store typed metadata.
Usage:
interface IMetaData {
data: string
}
const metadata = new MetaData<IMetaData>()
metadata.set({ data: 'foo' })
const value = metadata.get('data')
Return a composite function allowing to log message from a defined logger mapping.
const loggerMapping = {
server: {
express: 'express',
middleware: 'middleware'
},
client: {
react: 'react',
store: 'store'
}
}
const { newLogger } = setupLogger(loggerMapping)
const logger = newLogger('server')('middleware')
logger('info')('Send request')
logger('error')('Error 500')
You can enable / disable logger messages by adding a debug
property in local storage. Example:
// Will show only log messages for the server middleware:
localStorage.set('debug', 'server:middleware:*')
Define a value that can be null.
Usage:
type Value = Maybe<string>
Define a value that can be undefined.
Usage:
type Value = MaybeUndef<string>
Define a value that can be null or undefined.
Usage:
type Value = Perhaps<string>
Define an object with all properties as nullable values.
Usage:
interface IUser = {
id: number
name: string
}
const user: PropertiesNullable<IUser> = {
id: null,
name: null
}
Define an object with all properties as non-nullable values.
Usage:
interface INullableUser = {
id: Maybe<number>
name: Maybe<string>
}
const user: PropertiesNonNullable<INullableUser> = {
id: 1,
name: null // Error
}
FAQs
Tooling for productive codebases.
The npm package @productive-codebases/toolbox receives a total of 28 weekly downloads. As such, @productive-codebases/toolbox popularity was classified as not popular.
We found that @productive-codebases/toolbox 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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.