
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
transformed
Advanced tools
A lightweight, low-level, performant, customizable object transformer utility.
npm i transformed
import transformed from 'transformed'
const myTransformer = transformed()
myTransformer({ foo: 'bar' })
By default transformed
won't do anything with your data, you need to define your rules:
props
: definitions of how to process which propoutputTransformer
: how to process your outputautoCamelCase
(default: false): automatically adds support for camelCase versions of the passed prop names.hasOwnPropertyCheck
(default: false): for a slight performance improvement we're not doing hasOwnProperty
checks
by default, but you can enable for cases when not using simple objects as input.(InputObject): Whatever registry: Map<string, Definition> outputTransformer: OutputTransformer options: Partial setOptions(options: Partial): TransformedFn setOutputTransformer(outputTransformer: OutputTransformer): TransformedFn setProps(props: Props): TransformedFn toValue(prop: string, value: unknown)
transformed()
(default export)A constructor method to create your transformer instance.
setOptions()
Set options for your instance.
const myTransformer = transformed()
myTransformer.setOptions({
autoCamelCase: true,
foo: 'bar'
})
You may add custom config keys/values. You can access these options inside your property parsers and output transformer.
setOutputTransformer()
Set outputTransformer
for your instance.
const myOutputTransformer = ...
const myTransformer = transformed()
myTransformer.setOutputTransformer(myOutputTransformer)
Output transformers always should be set before calling
setProps
because they have the capability to alter prop names when registering them.
setProps()
Set supported properties for your instance.
Properties defined in "Babel config fashion". Arrays of property descriptors.
// All props
;[
// Property
[
// Property names
['p', 'pad', 'padding'],
// Value map for this property. Use `null` or leave emoty if not needed.
{ large: '30px' },
// Value parsers
[input => output]
]
]
const props = [
[['p', 'pad', 'padding'], { large: '30px' }],
[['bg', 'background'], { cars: 'cars.png' }, [(input, prop) => ({ [prop]: `http://mysite.com/images/${input}` })]]
]
const transform = transformed().setProps(props)
transform({
padding: 'large',
background: 'cars'
})
// Output: { padding: '30px', background: 'http://mysite.com/images/cars.png' }
toValue()
Sometimes you just want to get a value for a prop/value pair.
myTransformer.toValue('padding', 'large')
Object transformer is just a single function with static properties that loops through each property and values using the following API:
myOutputTransformer()
: returns your transformed output, receives the following arguments:
output
: currently generated output in current iteration (on first iteration it's defaultOutput)value
: the generated value in the current iterationprop
: the prop name for the current iterationinputObject
: the original object passed to transformedtransformedFn
: current transformed instance used for this iterationdefaultOutput()
: mandatory function returning the default outputunsupportedHandler()
: optional you may specify a handler for unsupported (not registered) properties; receives
same arguments as your outputTransformer functioncamelCaseReducer
: optional reducer function to alter how generated camelCase keys stored; parameters are the
same as for a normal array.reduce
callback (accumulator, currentValue, index)
transformed
will simply push it into the existing key listSee Complete Example for details on usage.
Parsers are telling how to process values for a certain property. You can apply as many parser functions as you want, during generation the next function will get the previous function's output value (pipe).
The parser function receives the following arguments:
const alwaysBar = (input, prop) => ({ [prop]: 'bar' })
const myTransformer = transformed().setProps([[['foo'], null, [alwaysBar]]])
myTransformer({ foo: 'baz' })
// Output: { foo: 'bar' }
See Complete Example for more advanced details on usage.
unsupported
(un-registered) valuesKeys that don't have registered handler ignored by default. However, you can tell which key's you want to proceed with.
This can be useful for example when dealing with CSS, and you need to pass some ancient or browser specific style property.
You have tu use the prop key: unsupported
which can be:
true
: all props allowedstring[]
: list of props to allowstring
: a single prop to allow// `-moz-*` will be ignored
{
padding: '10px',
'-moz-border-radius': '10px',
'-moz-foo-bar': 12
}
// only `-moz-foo-bar` will be ignored
{
padding: '10px',
'-moz-border-radius': '10px',
'-moz-foo-bar': 12
unsupported: '-moz-foo-bar'
}
// allow all
{
padding: '10px',
'-moz-border-radius': '10px',
'-moz-foo-bar': 12
unsupported: true
}
// specify what's allowed
{
padding: '10px',
'-moz-border-radius': '10px',
'-moz-foo-bar': 12
unsupported: ['-moz-foo-bar', '-moz-border-radius']
}
Let's see a simple example to build string based CSS output for a Style Object:
const toCSSParser = (value, prop, transformedFn, inputObject, definition) => {
// Let's always use the last key as CSS key
const cssProperty = definition.keys[definition.keys.length - 1]
return `${cssProperty}: ${value};\n`
}
// It'll just simply concat
const cssTransformer = (output, value) => `${output}${value}`
// Default output is just a string we will concat into
cssTransformer.defaultOutput = () => ''
const props = [
[['p', 'pad', 'padding'], { large: '30px' }, [toCSSParser]],
[['bg', 'background'], null, [toCSSParser]]
]
const myTransformer = transformed().setOutputTransformer(cssTransformer).setProps(props)
myTransformer({ p: 'large', bg: './cars.png' })
/**
* Output:
*
* padding: 30px;
* background: './cars.png'
*/
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
FAQs
A lightweight, low-level, performant, customizable object transformer utility.
The npm package transformed receives a total of 8 weekly downloads. As such, transformed popularity was classified as not popular.
We found that transformed 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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.