npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

detect-quotes

v1.0.0

Published

Detect which type of quotes a string is using.

Downloads

1

Readme

detect-quotes

Detect which type of quotes a string is using. Some times it is very difficult to detect which kind of quotes a string is using especially when you're dealing with source files directly and transforming it in some way. Whether you're just manipulating a source code a little or you're doing full parsing, this problem will definitly surface.

It is a very annoying situation to always try to figure out whether you're dealing with a double or single quote or a tilda each time. Now there are many tools that will try to handle this already however I see a lot of such tools annoying because they usually employ a long chain of dependencies to implement any small amount of functionality. I feel that's unnecessary and I'm not afraid to roll out mine.

If you can detect the string pattern for free, you can easily write a regular expression pattern match against it.

With this tool, you can detect if a raw string is single-quoted or double-quoted or both are combined in one giant urgly string. You can also detect tilda quotes as well. It analizes a string by first dividing it into segments allowing you to see quoted and unquoted parts separately, what quotes are used and the various concatenations involved in the case of source code manipulation.

//Very light-weight quotes detector

const fs = require("fs"); const file = fs.readFileSync("test.test", "utf-8"); const lines = file.split(/[\n\r]+/);

npm install detect-quotes

const Detection = require("detect-quotes"); const detection = new Detection();

//Detect quotes detection.isSingleQuotes(lines[0]) //true or false detection.isDoubleQuotes(lines[0]) //true or false detection.isTildaQuotes(lines[0]) //true or false detection.isMixedQuotes(lines[0]) //true or false

//View into various parts detection.segments; //Shows all created segments of a given line both quoted and unquoted detection.parts[1].isQuoted; //true or false detection.quotedSegments; // Shows all parts that are quoted

//Want to loop? // You can loop through the segments

detection.segments.forEach(function(segment) { segment.quoteToken; //Show the kind of quote the segment uses segment.isSingleQuoted; //true or false segment.isTildaQuoted; //true or false segment.isDoubleQuoted; //true or false segment.isQuoted; //true or false });