JSPM

  • Created
  • Published
  • Downloads 268369
  • Score
    100M100P100Q194182F
  • License MIT

Collapse the leading and trailing whitespace of a string

Package Exports

  • string-collapse-leading-whitespace

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-collapse-leading-whitespace) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

string-collapse-leading-whitespace

Collapse the leading and trailing whitespace of a string

Minimum Node version required Repository is on BitBucket Coverage View dependencies as 2D chart Downloads/Month Test in browser Code style: prettier MIT License

Table of Contents

Install

npm i string-collapse-leading-whitespace
// consume via a CommonJS require:
const collapseLeadingWhitespace = require("string-collapse-leading-whitespace");
// or as an ES Module:
import collapseLeadingWhitespace from "string-collapse-leading-whitespace";

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/string-collapse-leading-whitespace.cjs.js 1 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/string-collapse-leading-whitespace.esm.js 1 KB
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/string-collapse-leading-whitespace.umd.js 603 B

⬆ back to top

Idea

// does nothing to trimmed strings:
'aaa' => 'aaa'
// if leading or trailing whitespace doesn't contain \n, collapse to a single space
'  aaa   ' => ' aaa '
// otherwise, collapse to a single \n
'     \n\n   aaa  \n\n\n    ' => '\naaa\n'

⬆ back to top

API

API is simple: string in, string out.

If input is not a string, it will be just returned back, untouched.

Purpose

I'm going to use it in string-slices-array-push.

Contributing

  • If you want a new feature in this package or you would like us to change some of its functionality, raise an issue on this repo.

  • If you tried to use this library but it misbehaves, or you need advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. We'll do our best to merge it quickly. Prettier is enabled, so you don't need to worry about the code style.

⬆ back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt