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

nucleotides

v0.4.0

Published

The building blocks of JavaScript programs

Downloads

11

Readme

Nucleotides are the building blocks of JavaScript programs. They are simple, useful functions with well-understood semantics.

Nucleotides fix two aspects of JavaScript which hinder functional programming: operators and methods.

The problem with operators

In functional programming it's common to pass one function to another function. This is possible in JavaScript because functions are values. Operators, on the other hand, are not values so cannot be passed as arguments. The workaround is to use anonymous functions:

var sum = nums.reduce(function(sum, num) {
  return sum + num;
}, 0);

There is a nucleotide for each operator. nucleotides.operator.binary['+'], in this case:

var sum = nums.reduce(nucleotides.operator.binary['+'], 0);

The problem with methods

The semantics of JavaScript methods are incompatible with most higher-order functions. Methods must be wrapped so as to behave like regular functions:

var tags = str.split(',').map(function(word) {
  return word.trim();
});

There is a nucleotide for each built-in method. nucleotides.string.trim, in this case:

var tags = str.split(',').map(nucleotides.string.trim);

Nucleotides

The name of each mutator function is suffixed with !. This prevents unintentional mutation, draws attention to places where mutation does occur, and reserves the unsuffixed names for future use.

The following nucleotides are available:

- nucleotides.operator.new
- nucleotides.operator.unary.typeof
- nucleotides.operator.unary['+']
- nucleotides.operator.unary['-']
- nucleotides.operator.unary['~']
- nucleotides.operator.unary['!']
- nucleotides.operator.binary['*']
- nucleotides.operator.binary['/']
- nucleotides.operator.binary['%']
- nucleotides.operator.binary['+']
- nucleotides.operator.binary['-']
- nucleotides.operator.binary['<<']
- nucleotides.operator.binary['>>']
- nucleotides.operator.binary['>>>']
- nucleotides.operator.binary['<']
- nucleotides.operator.binary['>']
- nucleotides.operator.binary['<=']
- nucleotides.operator.binary['>=']
- nucleotides.operator.binary.instanceof
- nucleotides.operator.binary.in
- nucleotides.operator.binary['==']
- nucleotides.operator.binary['!=']
- nucleotides.operator.binary['===']
- nucleotides.operator.binary['!==']
- nucleotides.operator.binary['&']
- nucleotides.operator.binary['^']
- nucleotides.operator.binary['|']
- nucleotides.operator.binary['&&']
- nucleotides.operator.binary['||']
- nucleotides.array.toString
- nucleotides.array.toLocaleString
- nucleotides.array.join
- nucleotides.array['pop!']
- nucleotides.array['push!']
- nucleotides.array.concat
- nucleotides.array['reverse!']
- nucleotides.array['shift!']
- nucleotides.array['unshift!']
- nucleotides.array.slice
- nucleotides.array['splice!']
- nucleotides.array['sort!']
- nucleotides.array.filter
- nucleotides.array.forEach
- nucleotides.array.some
- nucleotides.array.every
- nucleotides.array.map
- nucleotides.array.indexOf
- nucleotides.array.lastIndexOf
- nucleotides.array.reduce
- nucleotides.array.reduceRight
- nucleotides.boolean.toString
- nucleotides.boolean.valueOf
- nucleotides.date.toString
- nucleotides.date.toDateString
- nucleotides.date.toTimeString
- nucleotides.date.toLocaleString
- nucleotides.date.toLocaleDateString
- nucleotides.date.toLocaleTimeString
- nucleotides.date.valueOf
- nucleotides.date.getTime
- nucleotides.date.getFullYear
- nucleotides.date.getUTCFullYear
- nucleotides.date.getMonth
- nucleotides.date.getUTCMonth
- nucleotides.date.getDate
- nucleotides.date.getUTCDate
- nucleotides.date.getDay
- nucleotides.date.getUTCDay
- nucleotides.date.getHours
- nucleotides.date.getUTCHours
- nucleotides.date.getMinutes
- nucleotides.date.getUTCMinutes
- nucleotides.date.getSeconds
- nucleotides.date.getUTCSeconds
- nucleotides.date.getMilliseconds
- nucleotides.date.getUTCMilliseconds
- nucleotides.date.getTimezoneOffset
- nucleotides.date['setTime!']
- nucleotides.date['setMilliseconds!']
- nucleotides.date['setUTCMilliseconds!']
- nucleotides.date['setSeconds!']
- nucleotides.date['setUTCSeconds!']
- nucleotides.date['setMinutes!']
- nucleotides.date['setUTCMinutes!']
- nucleotides.date['setHours!']
- nucleotides.date['setUTCHours!']
- nucleotides.date['setDate!']
- nucleotides.date['setUTCDate!']
- nucleotides.date['setMonth!']
- nucleotides.date['setUTCMonth!']
- nucleotides.date['setFullYear!']
- nucleotides.date['setUTCFullYear!']
- nucleotides.date.toGMTString
- nucleotides.date.toUTCString
- nucleotides.date.getYear
- nucleotides.date['setYear!']
- nucleotides.date.toISOString
- nucleotides.date.toJSON
- nucleotides.function.bind
- nucleotides.function.toString
- nucleotides.function.call
- nucleotides.function.apply
- nucleotides.number.toString
- nucleotides.number.toLocaleString
- nucleotides.number.valueOf
- nucleotides.number.toFixed
- nucleotides.number.toExponential
- nucleotides.number.toPrecision
- nucleotides.object.toString
- nucleotides.object.toLocaleString
- nucleotides.object.valueOf
- nucleotides.object.hasOwnProperty
- nucleotides.object.isPrototypeOf
- nucleotides.object.propertyIsEnumerable
- nucleotides.object.__defineGetter__
- nucleotides.object.__lookupGetter__
- nucleotides.object.__defineSetter__
- nucleotides.object.__lookupSetter__
- nucleotides.regexp.exec
- nucleotides.regexp.test
- nucleotides.regexp.toString
- nucleotides.regexp.compile
- nucleotides.string.valueOf
- nucleotides.string.toString
- nucleotides.string.charAt
- nucleotides.string.charCodeAt
- nucleotides.string.concat
- nucleotides.string.indexOf
- nucleotides.string.lastIndexOf
- nucleotides.string.localeCompare
- nucleotides.string.match
- nucleotides.string.replace
- nucleotides.string.search
- nucleotides.string.slice
- nucleotides.string.split
- nucleotides.string.substring
- nucleotides.string.substr
- nucleotides.string.toLowerCase
- nucleotides.string.toLocaleLowerCase
- nucleotides.string.toUpperCase
- nucleotides.string.toLocaleUpperCase
- nucleotides.string.trim
- nucleotides.string.trimLeft
- nucleotides.string.trimRight
- nucleotides.string.link
- nucleotides.string.anchor
- nucleotides.string.fontcolor
- nucleotides.string.fontsize
- nucleotides.string.big
- nucleotides.string.blink
- nucleotides.string.bold
- nucleotides.string.fixed
- nucleotides.string.italics
- nucleotides.string.small
- nucleotides.string.strike
- nucleotides.string.sub
- nucleotides.string.sup

Each of the "method" functions above will be defined only if the environment provides the method. For example, nucleotides.string.trim will be defined only if String.prototype.trim is defined.