@ntdalbec/type-scale

A Node.js library for dealing with CSS/HTML typographic scales

Usage no npm install needed!

<script type="module">
  import ntdalbecTypeScale from 'https://cdn.skypack.dev/@ntdalbec/type-scale';
</script>

README

type-scale

A Node.js library for dealing with HTML/CSS typographic scales

Installation

npm install @ntdalbec/type-scale

Usage

const { TypeScale, Scale } = require("type-scale");

const scale = new TypeScale({ scale: Scale.MajorThird });

console.log(`\
h1: ${scale.h1}
h2: ${scale.h2}
h3: ${scale.h3}
h4: ${scale.h4}
h5: ${scale.h5}
h6: ${scale.h6}
`)

// expected:
// h1:   3.052em
// h2:   2.441em
// h3:   1.953em
// h4:   1.563em
// h5:   1.25em
// h6:   1em
// body: 1em

Classes

TypeScale

Represents a Typographic scale in terms of HTML elements

TypeScale

Represents a Typographic scale in terms of HTML elements

new TypeScale(options)

Param Type Description
options Object
options.scale number The ratio to be used as the scale

typeScale.body : string

typeScale.h6 : string

typeScale.h5 : string

typeScale.h4 : string

typeScale.h3 : string

typeScale.h2 : string

typeScale.h1 : string

typeScale.asCSS() ⇒ string

Get the typographic scale as a CSS string

Returns: string - - A string representing a group of CSS rulesets

Scale : enum

A collection of scales in terms of intervals.

See: https://wikipedia.org/wiki/Interval_(music) for more information
Properties

Name Type Default Description
Unison string 1 1
MinorSecond string "" 1.067
MajorSecond string "" 1.125
MinorThird string "" 1.2
MajorThird string "" 1.25
PerfectFourth string "" 1.333
DiminishedFifth string "" 1.4
PerfectFifth string "" 1.5
MinorSixth string "" 1.6
MajorSixth string "" 1.667
MinorSeventh string "" 1.75
MajorSeventh string "" 1.875
Octave string 2 2

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT