UNPKG

regstr

Version:

JSON.stringify objects with RegExp properties and then JSON.parse json string resulted back into original objects. Converts RegExp object to be serializable - into pair of strings (key,value). Could be used for RegExp being bilaterally stringified and ge

38 lines (27 loc) 642 B
# regStr Usage options ``` var h = require('./regstr').regStr; // or h = require('regstr').regStr; ``` Suppose the o is variable of some entity containing RegExp element. ## usage in codes ### option 1 ``` var jsonStr, clone, oj; jsonStr = JSON.stringify(h.streger(o)); clone = h.reger(JSON.parse(jsonStr)); // Or h.streger(o); jsonStr = JSON.stringify(o); oj = JSON.parse(jsonStr); clone = h.reger(oj); ``` ### option 2 ``` var jsonStr, clone; var replacer = h.replacer.bind(h); var reviver = h.reviver.bind(h); jsonStr = JSON.stringify(o, replacer); clone = JSON.parse(jsonStr, reviver); ```