diff --git a/SecretSanta.js b/SecretSanta.js index 08427a4..524d94a 100644 --- a/SecretSanta.js +++ b/SecretSanta.js @@ -2,6 +2,7 @@ var SecretSanta = function () { this.names = []; + this.enforced = Object.create( null ); this.blacklists = Object.create( null ); }; @@ -15,6 +16,14 @@ SecretSanta.prototype.add = function ( name ) { var subapi = { }; + subapi.enforce = function ( other ) { + + this.enforced[ name ] = other; + + return subapi; + + }.bind( this ); + subapi.blacklist = function ( other ) { if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) @@ -38,12 +47,33 @@ SecretSanta.prototype.generate = function () { this.names.forEach( function ( name ) { - var candidates = _.difference( this.names, [ name ] ); + if ( Object.prototype.hasOwnProperty.call( this.enforced, name ) ) { - if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) - candidates = _.difference( candidates, this.blacklists[ name ] ); + var enforced = this.enforced[ name ]; - candidatePairings[ name ] = candidates; + if ( this.names.indexOf( enforced ) === -1 ) + throw new Error( name + ' is paired with ' + enforced + ', which hasn\'t been declared as a possible pairing' ); + + Object.keys( pairings ).forEach( function ( name ) { + + if ( pairings[ name ] === enforced ) { + throw new Error( 'Per your rules, multiple persons are paired with ' + enforced ); + } + + } ); + + pairings[ name ] = this.enforced[ name ]; + + } else { + + var candidates = _.difference( this.names, [ name ] ); + + if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) ) + candidates = _.difference( candidates, this.blacklists[ name ] ); + + candidatePairings[ name ] = candidates; + + } }, this ); diff --git a/assets/snow.png b/assets/snow.png new file mode 100644 index 0000000..7097c4c Binary files /dev/null and b/assets/snow.png differ diff --git a/index.html b/index.html index 427ba07..2ea15db 100755 --- a/index.html +++ b/index.html @@ -152,16 +152,13 @@
-
+

Secret Santa Generator

-

No signup, no email, no bullshit. Just a straightforward open-source tool to help you generate your secret santa pairings. Static page only.

-

The DSL that is used to set the pairing rules is dead simple: in the most common use case (no special rule, pair each guest to another), you just have to enter the name of your guests, one line at a time. Once done, press "generate" and voilà, you will get a set of links that you will just have to give to each one of them (by mail, chat, whatever float your boat). Once they access the link, their pairing will be revealed (to them and only them).

-

Should you have more complex needs (for example if you want to prevent a couple from being paired together, or want to prevent someone to be paired with someone else they don't know), just append !<name> after a guest name, and he will never be paired with <name> (check on the right for an example).

+

No signup, no email, no bullshit. Just a straightforward open-source tool to help you generate your secret santa pairings. One static page, and that's it.

+

In the most common case (no exclusion rules, pair each guest with another at random), enter the name of your guests one line at a time. Once done, press "generate" and you're all set: send the generated links to your guests (by mail, chat, whatever floats your boat) and their pairing will be revealed to them (and only them) once they open the link.

Where does this tool come from?

-

I just wanted to make a Secret Santa over Facebook without giving up my guests email addresses to do so (so nothing that requires a backend). I also wanted to ignore who was paired with me, so I had to find a way to obfuscate it. And since I'm a developer, well, I just thought "Let's AES it, for fun and profits!". Classic.

- +

I wanted to make a Secret Santa over Facebook without having to reveal to anyone my guests email addresses (so nothing that would require a backend). I also wanted not to know who was paired with me, so I had to find a way to somehow obfuscate the information. And being a developer, well, my first thought was "Let's AES it, for fun and profits!". Classic.

@@ -181,6 +178,13 @@ Maël !Aurélie Aurélie !Maël + # You can also exclude someone from being paired with multiple people + # Careful: too many exclusion rules can make your secret santa less interesting! + Rudolph !Maël !Santa + + # You can also cheat a bit and force someone to be paired with another + Aurélie =Santa + ... @@ -188,13 +192,23 @@ +
+
-

- - -

Good luck!

- - +
Hi ! You've been paired with
+ + +
+ + +
Good luck!
+ + + +
+ + Want to start your own Secret Santa with your friends? Click here to get started! + +