Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@chocolatey/box
Advanced tools
Box - put a value in a box
$ npm install @chocolatey/box
import $ from '@chocolatey/box'
$(42) // Box<42>
$(42).value() // 42
$(42).map(it => it + 1) // Box<43>
$(42).tap(console.log) // Box<42>
$(42).then(it => it + 1) // 43
$(42, it => it + 1) // 43
// "*.tar.gz" -> "*.gz"
const untar = name => $(name)
.map(it => it.split('.'))
.tap(it => it.splice(1, 1))
.then(it => it.join('.'))
untar('package.tar.gz') // "package.gz"
Box puts a value in a container which exposes a handful of methods to facilitate piping values through a series of functions.
It provides a lightweight implementation of the box pattern, which allows the right-to-left flow of function composition to be expressed via the left-to-right syntax of method chaining familiar from jQuery, Lodash, promises etc.
import R from 'ramda'
const fn1 = value => baz(bar(foo(value)))
const fn2 = R.compose(baz, bar, foo)
import $ from '@chocolatey/box'
const fn = value => $(value).map(foo).map(bar).then(baz)
Because:
composition and dot chaining are the same, and dot chaining is more ergonomic in JavaScript
If you're using Babel, pipelines can be written natively with features such as the (smart) pipeline operator, do expressions and partial application, e.g.:
import { tap } from 'lodash'
const untar = name =>
name.split('.')
|> tap(#, it => it.splice(1, 1))
|> #.join('.')
If you're already using Lodash/Underscore or similar, you can use their built-in methods to implement pipelines, e.g.:
import _ from 'lodash'
const untar = name =>
_(name)
.split('.')
.tap(it => it.splice(1, 1))
.join('.')
<T, R>(value: T, fn: (value: T) => R): R
<T>(value: T): Box<T>
import $ from '@chocolatey/box'
$(42) // Box<42>
$(42, it => it + 1) // 43
The default export is a function which either takes a value and puts it in a
box (via Box.of
) or takes a value and a function and applies the
function to the value.
The latter provides a convenient shorthand for passing an argument to an IIFE, e.g.:
const counter = (function () {
let count = 0
return () => ++count
})()
counter() // 1
counter() // 2
counter() // 3
const counter = (function (count) { return () => ++count })(0)
const counter = $(0, count => () => ++count)
new <T>(value: T) => Box<T>
import { Box } from '@chocolatey/box'
const box = new Box(42) // Box<42>
Creates a new Box instance containing the supplied value.
<T>(value: T) => Box<T>
import { Box } from '@chocolatey/box'
const box = Box.of(42) // Box<42>
const boxes = [1, 2, 3].map(Box.of) // [Box<1>, Box<2>, Box<3>]
Returns a new Box
instance containing the supplied value.
Note that of
is a function which returns a Box instance rather than a method
which returns an instance of its invocant, so the following are equivalent:
class MyBox extends Box {} // XXX missing `of` override
const array = [1, 2]
array.map(it => Box.of(it)) // [Box<1>, Box<2>]
array.map(it => MyBox.of(it)) // [Box<1>, Box<2>]
array.map(Box.of) // [Box<1>, Box<2>]
array.map(MyBox.of) // [Box<1>, Box<2>]
<U>(fn: (value: T) => U): Box<U>
import $ from '@chocolatey/box'
$(42).map(it => it + 1) // Box<43>
Applies the supplied function to the value and returns a new box containing the result.
<U>(fn: (value: T) => U): this
import $ from '@chocolatey/box'
$(42).tap(console.log) // Box<42>
Applies the supplied function to the value and returns the original box (the invocant). Useful to insert side effects, logging etc. into a pipeline without changing the value.
<U>(fn: (value: T) => U): U
import $ from '@chocolatey/box'
$(42).then(it => it + 1) // 43
Returns the result of applying the supplied function to the value.
(fn?: (value: T) => void): T
import $ from '@chocolatey/box'
$(42).value() // 42
$(42).value(console.log) // 42
Returns the value. If an optional function is supplied, it is applied to the
value before the value is returned. This is similar to tap
, except
the value is returned rather than the box.
The following NPM scripts are available:
if
, switch
and while
1.2.0
Copyright © 2021 by chocolateboy.
This is free software; you can redistribute it and/or modify it under the terms of the MIT license.
FAQs
Put a value in a box
The npm package @chocolatey/box receives a total of 2 weekly downloads. As such, @chocolatey/box popularity was classified as not popular.
We found that @chocolatey/box demonstrated a not healthy version release cadence and project activity because the last version was released 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.