项目原始demo,不改动
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Pode ver ficheiros e cloná-lo, mas não pode fazer envios ou lançar questões ou pedidos de integração.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # preserve [![NPM version](https://badge.fury.io/js/preserve.svg)](http://badge.fury.io/js/preserve)
  2. > Temporarily substitute tokens in the given `string` with placeholders, then put them back after transforming the string.
  3. Useful for protecting tokens, like templates in HTML, from being mutated when the string is transformed in some way, like from a formatter/beautifier.
  4. **Example without `preserve`**
  5. Let's say you want to use [js-beautify] on a string of html with Lo-Dash/Underscore templates, such as: `<ul><li><%= name %></li></ul>`:
  6. js-beautify will render the template unusable (and apply incorrect formatting because of the unfamiliar syntax from the Lo-Dash template):
  7. ```html
  8. <ul>
  9. <li>
  10. <%=n ame %>
  11. </li>
  12. </ul>
  13. ```
  14. **Example with `preserve`**
  15. Correct.
  16. ```html
  17. <ul>
  18. <li><%= name %></li>
  19. </ul>
  20. ```
  21. For the record, this is just a random example, I've had very few issues with js-beautify in general. But with or without js-beautify, this kind of token mangling does happen sometimes when you use formatters, beautifiers or similar tools.
  22. ## Install
  23. ## Install with [npm](npmjs.org)
  24. ```bash
  25. npm i preserve --save
  26. ```
  27. ## Run tests
  28. ```bash
  29. npm test
  30. ```
  31. ## API
  32. ### [.before](index.js#L23)
  33. Replace tokens in `str` with a temporary, heuristic placeholder.
  34. * `str` **{String}**
  35. * `returns` **{String}**: String with placeholders.
  36. ```js
  37. tokens.before('{a\\,b}');
  38. //=> '{__ID1__}'
  39. ```
  40. ### [.after](index.js#L44)
  41. Replace placeholders in `str` with original tokens.
  42. * `str` **{String}**: String with placeholders
  43. * `returns` **{String}** `str`: String with original tokens.
  44. ```js
  45. tokens.after('{__ID1__}');
  46. //=> '{a\\,b}'
  47. ```
  48. ## Contributing
  49. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/preserve/issues)
  50. ## Author
  51. **Jon Schlinkert**
  52. + [github/jonschlinkert](https://github.com/jonschlinkert)
  53. + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
  54. ## License
  55. Copyright (c) 2015-2015, Jon Schlinkert.
  56. Released under the MIT license
  57. ***
  58. _This file was generated by [verb](https://github.com/assemble/verb) on January 10, 2015._
  59. [js-beautify]: https://github.com/beautify-web/js-beautify