Skip to content

add any.strip for objects and arrays#572

Merged
Marsup merged 1 commit intomasterfrom
strip
Feb 28, 2015
Merged

add any.strip for objects and arrays#572
Marsup merged 1 commit intomasterfrom
strip

Conversation

@nlf
Copy link
Member

@nlf nlf commented Feb 26, 2015

This is ready

  • can remove keys from objects
  • can remove items from arrays
  • figure out behavior of root objects flagged as strip (return undefined? do nothing?)
  • test for edge cases
  • documentation

@Marsup Marsup added the feature New functionality or improvement label Feb 26, 2015
@Marsup Marsup self-assigned this Feb 26, 2015
@Marsup Marsup added this to the 6.0.0 milestone Feb 27, 2015
@nlf
Copy link
Member Author

nlf commented Feb 27, 2015

I think for root behavior it makes the most sense to just leave the object alone.. If my schema looks like Joi.string().strip() it wouldn't make much sense to return undefined in my mind. Thoughts?

@nlf
Copy link
Member Author

nlf commented Feb 28, 2015

@Marsup what do you think about allowing to pass an array of keys to be removed from an object as well? something like

Joi.object({
  id: Joi.string(),
  password: Joi.string(),
  private: Joi.string()
}).strip(['password', 'private'])

This would be useful in when clauses, like:

Joi.object({
  id: Joi.string(),
  password: Joi.string(),
  private: Joi.string()
}).when('some condition', { is: true, then: Joi.strip(['password, 'private']) });

@Marsup
Copy link
Collaborator

Marsup commented Feb 28, 2015

Why should the behavior be different just because it's root ? It seems inconsistent.
The syntax with parameters is tempting but isn't it weird that one applies to self and the other to children ?

@nlf
Copy link
Member Author

nlf commented Feb 28, 2015

Yeah, it does seem weird, it was a thought that would make stripping multiple keys under the same condition possible without having to repeat the condition. I started trying to implement that behavior though, and it becomes problematic quickly so I think it's probably not worth it.

@nlf nlf force-pushed the strip branch 2 times, most recently from 502280c to 7a9e5d4 Compare February 28, 2015 17:26
Marsup added a commit that referenced this pull request Feb 28, 2015
add any.strip for objects and arrays
@Marsup Marsup merged commit d10c79c into master Feb 28, 2015
@Marsup Marsup deleted the strip branch March 12, 2015 10:15
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants