How to use collapse-white-space - 8 common examples

To help you get started, we’ve selected a few collapse-white-space examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github algolia / react-element-to-jsx-string / index.js View on Github external
function stringifyObject(obj, inline, lvl) {
    if (Object.keys(obj).length > 0 || obj.length > 0) {
      // eslint-disable-next-line array-callback-return
      obj = traverse(obj).map(function(value) {
        if (isValidElement(value) || this.isLeaf) {
          this.update(formatValue(value, inline, lvl));
        }
      });

      obj = sortobject(obj);
    }

    const stringified = stringify(obj);

    if (inline) {
      return collapse(stringified)
        .replace(/{ /g, '{')
        .replace(/ }/g, '}')
        .replace(/\[ /g, '[')
        .replace(/ ]/g, ']');
    }

    // Replace tabs with spaces, and add necessary indentation in front of each new line
    return stringified
      .replace(/\\\'/g, "'")
      .replace(/\t/g, spacer(1, tabStop))
      .replace(/\n([^$])/g, `\n${spacer(lvl + 1, tabStop)}$1`);
  }
}
github remarkjs / remark-bookmarks / src / index.js View on Github external
visit(ast, (node, index, parent) => {
      const {type, identifier} = node
      const normal = collapse(identifier).toUpperCase()

      if (type === 'linkReference' || type === 'imageReference') {
        references[normal] = true
      } else if (type === 'definition') {
        if (overwrite && identifiers.indexOf(normal) !== -1) {
          parent.children.splice(index, 1)
          return index
        }

        if (references[normal]) {
          references[normal] = node
        }
      }
    })
github remarkjs / remark-bookmarks / src / index.js View on Github external
identifiers.forEach(identifier => {
      const normal = collapse(identifier).toUpperCase()
      const {url, label} = associations[normal]

      if (references[normal] === true) {
        ast.children.push({
          type: 'definition',
          url,
          identifier: normal.toLowerCase(),
          label
        })
      }
    })
  }
github bkonkle / jsx-chai / src / jsx-chai.js View on Github external
function jsxInclude({expected, actual}) {
    this.assert(
      ~collapse(actual).indexOf(collapse(expected)),
      `expected #{act} to contain ${inspect(expected)}`,
      `expected #{act} to not contain ${inspect(expected)}`,
      expected,
      actual
    )
  }
github algolia / expect-jsx / index.js View on Github external
toIncludeJSX(ReactElement) {
    return expect(
      collapse(reactElementToJSXString(this.actual))
    ).toInclude(
      collapse(reactElementToJSXString(ReactElement))
    );
  },
  toNotIncludeJSX(ReactElement) {
github algolia / expect-jsx / index.js View on Github external
toNotIncludeJSX(ReactElement) {
    return expect(
        collapse(reactElementToJSXString(this.actual))
    ).toExclude(
        collapse(reactElementToJSXString(ReactElement))
    );
  },
};
github bkonkle / jsx-chai / src / jsx-chai.js View on Github external
function jsxEql({expected, actual}) {
    this.assert(
      collapse(actual) === collapse(expected),
      'expected #{act} to equal #{exp}',
      'expected #{act} to not equal #{exp}',
      expected,
      actual,
      true
    )
  }
github remarkjs / remark-bookmarks / src / index.js View on Github external
const associations = Object.keys(bookmarks).reduce((map, label) => {
    map[collapse(label).toUpperCase()] = {label, url: bookmarks[label]}
    return map
  }, {})

collapse-white-space

Collapse white space

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular collapse-white-space functions