Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coolgk/string

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coolgk/string

string utility functions

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

@coolgk/string

a javascript / typescript module

npm install @coolgk/string

string utility functions

Examples

import { stripTags, escapeHtml, unescapeHtml, prepad0 } from '@coolgk/string';
// OR
// const { stripTags, escapeHtml, unescapeHtml, prepad0 } = require('@coolgk/string');

const str = '<h1>test</h1><script>alert(1)</script>'

console.log(stripTags(str)); //  test alert(1)
console.log(escapeHtml(str)); // &lt;h1&gt;test&lt;/h1&gt;&lt;script&gt;alert(1)&lt;/script&gt;
console.log(unescapeHtml(escapeHtml(str))); // <h1>test</h1><script>alert(1)</script>

console.log(prepad0(7, 2)); // 07
console.log(prepad0(70, 3)); // 070
console.log(prepad0(70, 4)); // 0070
console.log(prepad0(1, 4)); // 0001
console.log(prepad0(1000, 2)); // 1000

Functions

stripTags(a)string

strip html tags e.g. "<h1>header</h1><p>message</p>" becomes "header message"

escapeHtml(value)string

escaping user input e.g. html code in a message box

unescapeHtml(string)string

unescaping strings escaped by escapeHtml()

prepad0(value, length)string

use padStart instead

stripTags(a) ⇒ string

strip html tags e.g. "<h1>header</h1><p>message</p>" becomes "header message"

Kind: global function
Returns: string - - string with tags stripped

ParamTypeDescription
astringstring

escapeHtml(value) ⇒ string

escaping user input e.g. html code in a message box

Kind: global function

ParamTypeDescription
valuestringstring to escape

unescapeHtml(string) ⇒ string

unescaping strings escaped by escapeHtml()

Kind: global function

ParamTypeDescription
stringstringstring to unescape

prepad0(value, length) ⇒ string

use padStart instead

Kind: global function
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

ParamTypeDefaultDescription
valuenumberan integer in string or number format
lengthnumber2length of the output e.g. length = 2, 8 becomes 08. length = 3, 70 = 070.

Keywords

FAQs

Package last updated on 25 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc