DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
  • Infrastructure
    • can-construct
    • can-control
    • can-event
    • can-event/async/async
    • can-event/batch/batch
    • can-observation
    • can-simple-map
    • can-util
      • can-util/dom
      • can-util/js
        • ./assign/
        • ./base-url/
        • ./cid/
        • ./deep-assign/
        • ./defaults/
        • ./deparam/
        • ./diff/
        • ./diff-object/
        • ./each/
        • ./global/
        • ./import/
        • ./is-array-like/
        • ./is-browser-window/
        • ./is-empty-object/
        • ./is-function
        • ./is-node/
        • ./is-plain-object/
        • ./is-promise/
        • ./is-promise-like/
        • ./is-string/
        • ./is-web-worker/
        • ./join-uris/
        • ./make-array/
        • ./make-promise/
        • ./param/
        • ./set-immediate/
        • ./string/
          • string.camelize
          • string.capitalize
          • string.esc
          • string.getObject
          • string.hyphenate
          • string.strReplacer
          • string.strUndHash
          • string.sub
          • string.underscore
        • ./string-to-any/
        • ./types/
    • can-view-callbacks
    • can-view-live
    • can-view-model
    • can-view-nodelist
    • can-view-parser
    • can-view-scope
    • can-view-target
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Infrastructure
  • /
  • can-util
  • /
  • can-util/js
  • /
  • ./string/
  • /
  • string.sub
  • / On this page
    • string.sub

      function
      • source

      string.sub(str, data, remove)

      Parameters

      1. str {String}:

        a string with {curly brace} delimited property names

      2. data {Object}:

        an object from which to read properties

      Returns

      {String|null}:

      the supplied string with delimited properties replaced with their values if all properties exist on the object, null otherwise

      If remove is true, the properties found in delimiters in str are removed from data.

      var string = require("can-util/js/string/string");
      
      console.log(string.sub("foo_{bar}", {bar: "baz"}})); // -> "foo_baz"
      console.log(string.sub("foo_{bar}", {})); // -> null
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.