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

node-jawn

v2.0.1

Published

A collection of tiny, specialized javascript utilities. Use that jawn.

Downloads

37

Readme

jawn.js

A collection of tiny, specialized javascript utilities. Use that jawn.

Parse and manipulate filepaths and URIs, inspect and extrude objects, alter letter casing, and lots more. by Austin, for free.


jawn.parseQuery(queryString)

Interprets a standard URL queryString into a usable, typed object.

jawn.parseQuery('?name=Alfred%20Bootin&height=6.05&tickets=false&style=');

//--> { name: 'Alfred Bootin', height: 6.05, tickets: false, style: null }

jawn.textToHtml(text)

Converts plaintext text to HTML-- quite basic at the moment. Only converts newlines to <br> tags.

jawn.textToHtml('My first paragraph. \nSecond Paragraph!');
//--> 'My first paragraph. <br />Seconds Paragraph!'

jawn.filenameFromPath(path)

uses .pathify() to extract the last element from a given path

jawn.filenameFromPath('/images/wine/merlot/fancy_shit.png');
//--> 'fancy_shit.png'

jawn.pathWithoutFilename(path[, force])

Returns path, minus the filename, if one exists (i.e. one with a period), always returning with a trailing slash. If force is a truthy value, it will remove the final path part, regardless of whether or not a period exists.

jawn.pathWithoutFilename('/photos/grandma/scary.jpg')
//--> '/photos/grandma/'
jawn.pathWithoutFilename('/dir/certainlyAnotherDir/', false)
//--> '/dir/possiblyAnotherDir/'
jawn.pathWithoutFilename('/dir/possiblyAnotherDir/', true)
//--> '/dir/'

jawn.containsPeriod(input)

If input string contains a period, return true.

jawn.containsPeriod('file.xml')
//--> true
jawn.containsPeriod('i stole the guitar, though')
//--> false

jawn.getFileExtension(input[, hard])

returns just the file extension, unless there is none, in which case the input is returned, unless hard is a truthy value, in which case false is.

jawn.getFileExtension('seasonsChange.svg')
//--> 'svg'
jawn.getFileExtension('WTF_broooooo?')
//--> 'WTF_broooooo?'
jawn.getFileExtension('stoic', true)
//--> false

jawn.removeFileExtension(input[, hard])

Returns all of input, up to the final file extension. If no file extension is found and hard is truthy, false is returned. Otherwise input is returned.

jawn.removeFileExtension('InedibleNachos.png')
//-->	'InedibleNachos'

jawn.appendToFilename(filename, addendum)

Insert addendum onto filename, before the file extension.

jawn.appendToFilename('photos/mom/gotNOteeth.jpg', '-edited')
//-->	'photos/mom/gotNOteeth-edited.jpg'

jawn.autopath([...args...])

Pass various values/dirnames as arguments to automatically build a path/url from them. Intelligently handles URLs, and dotpath prefixes. Never returns with a trailing slash.

jawn.autopath('http://sick-site.com', 'vids', 'category/ZAP', '/vid.swf')
//--> 'http://sick-site.com/vids/category/ZAP/vid.swf'

jawn.pathify(path)

Deconstructs a path (URLs okay) into an array of segments.

jawn.pathify('C://Windows/System32/Frameworks/Crap/WindowsBlows.lol')
//--> ['C:', 'Windows', 'System32', 'Frameworks', 'Crap', 'WindowsBlows.lol']
jawn.pathify('/assets/photos/MIKHAIL_prom/GoMishaGo!.jpg')
//--> ['assets', 'photos', 'MIKHAIL_prom', 'GoMishaGo!.jpg']

jawn.fa(icon)

Generate the classes for a FontAwesome icon, useful in ng-class.

jawn.fa('home')
//--> 'fa fa-home'

jawn.bgi(image[, objMode[, camelCase]])

Generates background-image CSS image URL string. Use objMode to generate as object with either (if camelCase is truthy) or hyphen-style property name. Useful in .

jawn.bgi('assets/bg.jpg')
//--> 'url("assets/bg.jpg")'
jawn.bgi('img/wall.png', true, true)
//--> { backgroundImage: 'url("img/wall.png")' }

jawn.slug(input[, separator])

generates a URL-friendly slug for input, retaining alphanumeric characters and replacing spaces with separator, '-' by default.

jawn.slug('My SUPER cool new WEBSITE!!! Yay~')
//--> 'my-super-cool-new-website-yay'
jawn.slug("this one's different", '~')
//--> 'this~ones~different'

jawn.hasImageExt(fileName)

Checks if fileName has a common image file extension (case-insensitive).

jawn.hasImageExt('files/deep/folder/test.jpg')
//--> true

The following extensions are checked by default:

  • jpg or jpeg
  • png
  • svg
  • gif
  • bmp
  • tif

If you need to add to this list, it can be accessed as jawn.imageTypes:

  jawn.imageTypes.push('xyz')

This adds 'xyz' as an image type, for example.

jawn.wrapDoubleBreaks(x)

Wraps x in two escaped newlines. Useful for spacing out console.log() statements.

jawn.wrapDoubleBreaks('WTF BRO')
//--> "\n\n WTF BRO \n\n"

jawn.ucFirst(s)

Uppercase the first letter of a string.

jawn.ucFirst('lowercase')
//--> 'Lowercase'

jawn.lcFirst(s)

Lowercase the first letter of a string.

jawn.lcFirst('Uppercase')
//--> 'uppercase'

jawn.isNumeric(x)

Simple check for number-ness.

jawn.isNumeric('15.4')
//--> true
jawn.isNumeric('Unoriginal Antiques')
//--> false, man y'all triflin that ain't even close to a number dawg

jawn.isUppercase(str)

Simple check for ALL CAPS-NESS (actually for lack of lowercase-ness).

jawn.isUppercase('Suh dude?')
//--> false
jawn.isUppercase('LOL JERK')
//--> true
jawn.isUppercase('$#$%&#$&')
//--> true (is this a defect or non-issue? Need a second opinion yall)

jawn.toCamelCase(input[, overrideAllCaps])

Converts a value to camelCase, splitting by spaces, commas, and underscores Leaves ALLCAPS untouched unless overrideAllCaps is truthy. Retains initial underscore ( _ ) if present, and lowercases the first letter.

jawn.toCamelCase('My_Cool_Var_Name')
//--> 'myCoolVarName'
jawn.toCamelCase('leave-me-alone, bob')
//--> 'leaveMeAloneBob'

jawn.castNumberTypes(x)

If a value is numeric, turn it into a number of the appropriate type.

jawn.castNumberTypes('4')
//--> 4 (int)
jawn.castNumberTypes('103434.4040')
//--> 103434.4040 (float)

jawn.hath(obj, props)

Deep checks if nested period-separated properties (props) exist on obj like Underscore's _.has(obj, propertyName) but can go many levels deep. Accepts integer values to search for array indices as well.

var deep = { firstLevel: { secondLevel: { thirdLevel: ["Limbo"] } } }
jawn.hath(deep, 'firstLevel.secondLevel.thirdLevel')
//--> true
jawn.hath(deep, 'firstLevel.secondLevel.thirdLevel.Limbo')
//--> false (it's an array item of thirdLevel)
jawn.hath(deep, 'firstLevel.secondLevel.thirdLevel.0')
//--> true (it's the 0 index)

jawn.extrude(obj, targetProp)

Returns the value of targetProp (a period-separated property path) from deep within obj, if it exists. Otherwise, false.

var deepAF = { firstLevel: { secondLevel: { thirdLevel: { treasure: true } } } }
jawn.extrude(deepAF, 'firstLevel.secondLevel.thirdLevel')
//--> { treasure: true }
jawn.extrude(deepAF, 'firstLevel.secondLevel.secretPathway')
//--> false