Q:

How to make expanding middle delimitors like in the braket package

The braket package has convenient commands like \Braket and \Set, where | are automatically expanded vertically. This allows to easily typeset expressions like
\documentclass{minimal}
\usepackage{braket}
\begin{document}
$$\Braket{\psi |i\hbar\frac{\partial}{\partial t}|\phi}$$ 
\end{document}

I'd like to do the same thing with other delimiters, for example to typeset conditional probabilities like $P(A=\frac12|B)$.
Edit to clarify the question
I'm interested to cases where I don't know which size of the |-sign is the biggest. An example could be $P(A=\frac12|B=2^{2^2})$.

A:

Use \middle| 
$P\left( A = \frac{1}{2} \middle| B \right)$

