From 0b213ff62431fce6b791f34f9fce0cbe7d94680e Mon Sep 17 00:00:00 2001 From: Smartin Date: Wed, 17 Feb 2021 20:51:06 +0100 Subject: [PATCH] Add moment-immutable plugin --- docs/moment/10-plugins/23-immutable.md | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docs/moment/10-plugins/23-immutable.md diff --git a/docs/moment/10-plugins/23-immutable.md b/docs/moment/10-plugins/23-immutable.md new file mode 100644 index 00000000..cef1a49c --- /dev/null +++ b/docs/moment/10-plugins/23-immutable.md @@ -0,0 +1,28 @@ +--- +title: Immutable Moment.js +signature: | + npm install moment-immutable --save +--- + + +This plugin makes moment.js immutable by auto cloning the `Moment` during all mutable actions. + +Made by [Smartin85](https://github.com/smartin85). + +```js +// Without moment-immutable +var january1st = moment("2017-01-01"); +var february1st = january1st.add(1, "month"); + +january1st.format(); // "2017-02-01T00:00:00+01:00" - oh no +february1st.format(); // "2017-02-01T00:00:00+01:00" + +// With moment-immutable +var january1st = moment("2017-01-01"); +var february1st = january1st.add(1, "month"); + +january1st.format(); // "2017-01-01T00:00:00+01:00" - yeah +february1st.format(); // "2017-02-01T00:00:00+01:00" +``` + +The repository is located at [github.com/smartin85/moment-immutable](https://github.com/smartin85/moment-immutable).