
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Deal with a set of objects in one go!
The module is implemented as a way of prototyping faster by abstracting away looping over collections. But this is done at the expence of execution speed, as objects are looped over again and again.
OneGo is a factory that given a class Class returns a function List whose prototype shares the same API as Class and does the same object by object in the collection.
import OneGo, {ogArgs} from 'one-go';
class Name {
constructor(name) {this.name = name;}
getName() {return this.name;}
setName(name) {this.name = name;}
setFullName(firstName, lastName) {this.name = firstName + lastName;}
print() {console.log(this.name);}
}
const List = OneGo(Name);
const list = new List('Aaa', 'Bbb', 'Ccc');
list.getName(); // Returns ['Aaa', 'Bbb', 'Ccc']
list.print(); // Prints 'Aaa\nBbb\nCcc\n'
list.setName('Ddd'); // Sets every name to 'Ddd'
list.setName(ogArgs('Eee', 'Fff', 'Ggg')); // Sets names respectively to 'Eee', 'Fff', 'Ggg'
list.setFullName(ogArgs(
['Eee', 'Ee'],
['Fff', 'Ff'],
['Ggg', 'Gg']
)); // Sets names respectively to 'EeeEe', 'FffFf', 'GggGg'
const List = OneGo(Class)List and Class have the same API. Each method of List wraps a loop over the same method in Class. Their results (if any) are returned as an array of all results.
const list = new List(...args)Arguments passed to the constructor can be as many as necessary. Their initial number determines once and for all the size of each generated loops.
If the original class constructor takes a single argument, then [] can be omitted around it when passed to the List constructor. But if the original class takes more arguments, then [] are necessary to distinguish which object should be initialized with what.
Some valid constructions:
const list1 = new List('Aaa', 'Bbb', 'Ccc');
const list2 = new List(['Aaa'], ['Bbb'], ['Ccc']);
const list3 = new List(
['Aaa', 1, {id: 'id1'}],
['Bbb', 21, {id: 'id2'}],
['Ccc', 12, {id: 'id3'}]
);
list.methodName(...args)By default, a call to a method with some arguments passes those arguments to each and every wrapped object associated method.
If you have a method adding an argument to a property, then that argument will be added to each and every same property of the underlying objects.
If you desire a more vector like behavior, for a one-to-one addition for example, you need a special construct with ogArgs function as a helper. See below.
list.methodName(ogArgs(...args))When you want to pass distinct arguments to every underlying object methods, you need to use the wrapping function ogArgs. It will take care of distributing your arguments to their respective targets.
import OneGo, {ogArgs} from 'one-go';
class Float {
constructor(number) {this.value = number;}
add(number) {this.value += number;}
get() {return this.value;}
}
const List = OneGo(Float);
const list = new List(1, 34, Math.PI, 99.9);
list.add(ogArgs(1, 2, 3, 4);
list.get(); // Returns [2, 36, 6.1415926..., 103.9]
Sometimes it's just easier to pass an array of arguments rather than arguments directly. By setting this option to true, the generated function List will expect an array instead of a sequence of arguments.
import OneGo from 'one-go';
class Float {
constructor(number) {this.value = number;}
add(number) {this.value += number;}
get() {return this.value;}
}
const List1 = OneGo(Float); // option 'arrayInit' not set
const list1 = new List1(1, 34, Math.PI, 99.9); // sequence of arguments
const List2 = OneGo(Float, {arrayInit: true}); // option 'arrayInit' set
const list2 = new List2([1, 34, Math.PI, 99.9]); // array of arguments
By default, the generated List shares its API with the underlying Type, simply looping over the list elements and applying the method of the same name. If you want a different behavior for a specific method, override it using the 'override' option.
import OneGo from 'one-go';
class Float {
constructor(number) {this.value = number;}
add(number) {this.value += number;}
get() {return this.value;}
}
const List = OneGo(Float, {
override: {
get() {
return this.elements.reduce((el1, el2) => {
if (el1.value) {
el1 = el1.value;
}
return el1 + el2.value;
});
}
}
});
const list = new List(1, 34, 99.9);
list.get(); // Returns 134.9... and not [1, 34, 99.9]
You may not want to override a generated List method, but the underlying Type original method. Use the 'parallel' option for that.
import OneGo from 'one-go';
class Float {
constructor(number) {this.value = number;}
add(number) {this.value += number;}
get() {return this.value;}
}
const List = OneGo(Float, {
parallel: {
get() {
return 'value: ' + this.value;
}
}
});
const list= new List(1, 34, 99.9);
list.get(); // Returns ['value: 1', 'value: 34', 'value: 99.9']
// and not [1, 34, 99.9]
## License
one-go is [MIT licensed](./LICENSE).
© 2016 [Jason Lenoble](mailto:jason.lenoble@gmail.com)
FAQs
Deal with a set of objects in one go!
The npm package one-go receives a total of 10 weekly downloads. As such, one-go popularity was classified as not popular.
We found that one-go 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.