![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@cio/transformer
Advanced tools
Easily use a Transform pipeline to handle communication.
npm install @cio/transformer --save
Uses specified transforms in a pipeline from socket input back to socket output.
Accepts a single transform or an array of transforms.
Accepts the actual transform instance, a function to build the transform, or a string it can provide to require()
to get an instance or builder function.
Note: A server should (very likely) use builder functions to make a new transform for each connection.
// get the module's builder function
var buildCio = require('cio');
// pass this module's name to the core module: `cio` as a plugin
var cio = buildCio({
// can specify many plugins in this array
plugins: [ '@cio/transformer' ]
});
// OR: provide options for a plugin too:
var cio = buildCio({
plugins: [
{ plugin: '@cio/transformer', options: {some: 'options'} }
]
});
// could alternatively do any of the following:
// pass the plugin info to the `cio.use()` function
cio.use('@cio/transformer');
// OR: and with some plugin options
cio.use('@cio/transformer', { some: 'options' });
// OR: provide the function to use()
var fn = require('@cio/transformer');
cio.use(fn);
// OR: provide the function with options
cio.use(fn, { some: 'options' });
// now make a client
// get an instance of our transform (or a function which builds the transform)
var someTransform = getSomeTransform();
// specify the transform in the options (or specify an array of them)
var options = { transform: someTransform };
// OR: use an array for multiple transforms
var options = { transform: [ someTransform ] };
// then create a client
client = cio.client(options);
// the result is a client socket created by `net.connect()`
// when it connects it will do:
// client.pipe(theTransform).pipe(client)
// Note: specify multiple transforms and they will be piped in the order given.
// Note: see module `cio` for more on its options
// Do the same with cio.server(...) for server side connection setup
Each transform specified may be an instance of a transform or a function which returns a transform.
Also, they may be a string which can be passed to require()
to get a function or a transform.
Note, they may be mixed.
// assume we've already created the `cio` instance as above.
// some different ways to specify it
var transformFromRequire = 'some-module' // string
, transformFromFunction = someBuilderFunction // function
, transformInstance = getSomeTransform(); // transform
// create options with the transforms
var options = {
transform: [
// note, they will be piped in the order specified here
transformFromRequire
, transformFromFunction
, transformInstance
]
};
// create the connection
var client = cio.client(options);
// OR, for a server:
var server = cio.server(options);
// the `transformFromRequire` string will be passed to a require() call
// expecting to receive a builder function which will accept the `options`
// passed to client()/server() and return a transform instance.
// the `transformFromFunction` should be a function which accepts the `options`
// provided to client()/server() and builds a transform.
// the `transformInstance` is used as is.
// when the client connects, or when a new server connection is made, it will
// pipe the connection into the first transform, then each transform in order,
// then back to the connection.
// for a client() connection this is done once.
// for a server() it will be done for *each* new connection. This means using
// a builder function is important so it builds a new transform instance for
// each new connection.
// Note: a transform specified by a string will be require()'d only once. its
// result will be reused.
There are multiple ways to build a Transform.
stream
documentation (Note, this link is for the latest Node, be sure to check for the version you're using).// standard Node way (newer versions):
// Note: this way requires splitting incoming string on newlines via another
// transform piped to this one, or, done manually in your function.
var Transform = require('stream').Transform;
function builder1(options) {
return new Transform({
transform: function (data, encoding, next) {
var string = data.toString('utf8')
, object = null;
try {
object = JSON.parse(string);
this.push(object);
next();
} catch(error) {
next({
error: 'Unable to parse string with JSON.parse()'
Error: error
});
}
}
});
}
// the through2 way:
// Note: this way requires splitting incoming string on newlines via another
// transform piped to this one, or, done manually in your function.
var thru = require('through2')
function builder2(options) {
return thru(function (data, encoding, next) {
// same processing as above in builder1.
});
}
// the transforming way:
// Note: (module is a function which accepts build options)
var transform = require('transforming')()
var builder3 = function(options) {
// simple case of transforming a newline delimited string into an object
return transform.splitStringToObject(JSON.parse);
// OR: long form without making use of defaults or convenience functions:
return transform.split('\n').string('utf8').toObject(JSON.parse);
}
FAQs
Easily use a Transform pipeline to handle communication.
The npm package @cio/transformer receives a total of 0 weekly downloads. As such, @cio/transformer popularity was classified as not popular.
We found that @cio/transformer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.