Skip to content

Instantly share code, notes, and snippets.

@jamescostian
Last active March 29, 2016 14:30
Show Gist options
  • Save jamescostian/34a1e82d5f23c42a87ce to your computer and use it in GitHub Desktop.
Save jamescostian/34a1e82d5f23c42a87ce to your computer and use it in GitHub Desktop.

Revisions

  1. jamescostian revised this gist Mar 29, 2016. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions htmlentities.js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    const htmlEntities = (str) => String(str)
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')

    const unhtmlEntities = (str) => String(str)
    .replace(/&amp;/g, '&')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&apos;/g, "'")
    .replace(/&amp;/g, '&')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&apos;/g, "'")
  2. jamescostian revised this gist Mar 6, 2015. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions htmlentities.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,13 @@
    export function htmlEntities(str) {
    return String(str)
    const htmlEntities = (str) => String(str)
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')
    }
    export function unhtmlEntities(str) {
    return String(str)

    const unhtmlEntities = (str) => String(str)
    .replace(/&amp;/g, '&')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&apos;/g, "'")
    }
  3. jamescostian revised this gist Sep 11, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions htmlentities.js
    Original file line number Diff line number Diff line change
    @@ -6,3 +6,11 @@ export function htmlEntities(str) {
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')
    }
    export function unhtmlEntities(str) {
    return String(str)
    .replace(/&amp;/g, '&')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&apos;/g, "'")
    }
  4. jamescostian created this gist Jun 1, 2014.
    8 changes: 8 additions & 0 deletions htmlentities.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    export function htmlEntities(str) {
    return String(str)
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')
    }