Socket
Socket
Sign inDemoInstall

difference-engine

Package Overview
Dependencies
10
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    difference-engine

Difference Engine


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

difference-engine

npm i -P difference-engine

DifferenceEngine

const { DifferenceEngine } = require('./lib')

inclusive

Accepts two arrays. Returns an array containing items which appear in both arrays.

const alpha = ['A', 'B', 'C']
const omega = ['C', 'D', 'E']

const array = DifferenceEngine.inclusive(alpha, omega) // returns ['C']

exclusive

Accepts two arrays. Returns an array containing items which appear in the first array but not the second.

const alpha = ['A', 'B', 'C']
const omega = ['C', 'D', 'E']

const array = DifferenceEngine.exclusive(alpha, omega) // returns ['A', 'B']

ArrayEngine

const { ArrayEngine } = require('./lib')

indexOf

const array = ['A', 'B', 'C', 'D', 'E']

const index = ArrayEngine.indexOf(array, 'E') // returns 4

bite

Accepts an array and two indexes. Returns a slice from the array.

Positive
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 0, 0) // returns ['A']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 0, 4) // returns ['A', 'B', 'C', 'D', 'E']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 4, 0) // returns ['E', 'D', 'C', 'B', 'A']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 4, 4) // returns ['E']
Negative
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, -4, 0) // returns ['A']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, -4, 4) // returns ['A', 'B', 'C', 'D', 'E']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, -4, -4) // returns ['E', 'D', 'C', 'B', 'A']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 4, -4) // returns ['E', 'D', 'C', 'B', 'A']
const alpha = ['A', 'B', 'C', 'D', 'E']

const omega = ArrayEngine.bite(alpha, 0, -4) // returns ['A']

iterateForward

Accepts an array and a function. Iterates from start to end.

const array = ['A', 'B', 'C', 'D', 'E']

ArrayEngine.iterateForward(array, () => {})

iterateReverse

Accepts an array and a function. Iterates from end to start.

const array = ['A', 'B', 'C', 'D', 'E']

ArrayEngine.iterateReverse(array, () => {})

iterateBetween

Accepts an array, a start index, an end index, and a function.

If the first index is less than the second index, it behaves as iterateForward.

If the first index is greater than the second index, it behaves as iterateReverse.

const array = ['A', 'B', 'C', 'D', 'E']

ArrayEngine.iterateBetween(array, 1, 3, () => {})

max

Accepts an array. Returns the largest item (when compared as a number).

const array = ['A', 'B', 'C', 'D', 'E']

const value = ArrayEngine.max(array) // returns 'E'
const array = [1, 2, 3, 4, 5]

const value = ArrayEngine.max(array) // returns 5

min

Accepts an array. Returns the smallest item (when compared as a number).

const array = ['A', 'B', 'C', 'D', 'E']

const value = ArrayEngine.min(array) // returns 'A'
const array = [1, 2, 3, 4, 5]

const value = ArrayEngine.min(array) // returns 1

NumberEngine

const { NumberEngine } = require('./lib')

fibonacci

Accepts an index. Returns the number in a Fibonacci sequence corresponding to the index.

const fibonacci = NumberEngine.fibonacci(0) // returns 0
const fibonacci = NumberEngine.fibonacci(1) // returns 1
const fibonacci = NumberEngine.fibonacci(2) // returns 1
const fibonacci = NumberEngine.fibonacci(3) // returns 2

haversine

Accepts an object with fields describing latitude and longitude points from and to.

Returns a value in kilometres or miles.

const points = { from: { lat: 51.4934, lng: 0.0098 }, to: { lat: 40.7128, lng: 74.0060 } }

const km = NumberEngine.haversine(points).km() // returns the distance in kilometres
const mi = NumberEngine.haversine(points).mi() // returns the distance in miles

fromOctToDec

Accepts a string representing an octal. Returns a decimal.

const dec = NumberEngine.fromOctToDec('20') // returns 16

fromHexToDec

Accepts a string representing a hexadecimal. Returns a decimal.

const dec = NumberEngine.fromHexToDec('10') // returns 16

Weight

Convert a number from one unit to another.

const { NumberEngine: { Weight } } = require('./lib')
Kilogram
  • fromKgToGr
  • fromKgToMg
  • fromKgToOz
  • fromKgToLb
  • fromKgToSt
const gr = Weight.fromKgToGr(10)
const mg = Weight.fromKgToMg(10)
const oz = Weight.fromKgToOz(10)
const lb = Weight.fromKgToLb(10)
const st = Weight.fromKgToSt(10)

Or, using convert.

  • fromKg.toGr
  • fromKg.toMg
  • fromKg.toOz
  • fromKg.toLb
  • fromKg.toSt
const gr = Weight.convert(10).fromKg.toGr()
const mg = Weight.convert(10).fromKg.toMg()
const oz = Weight.convert(10).fromKg.toOz()
const lb = Weight.convert(10).fromKg.toLb()
const st = Weight.convert(10).fromKg.toSt()
Gram
  • fromGrToKg
  • fromGrToMg
  • fromGrToOz
  • fromGrToLb
  • fromGrToSt
const kg = Weight.fromGrToKg(10)
const mg = Weight.fromGrToMg(10)
const oz = Weight.fromGrToOz(10)
const lb = Weight.fromGrToLb(10)
const st = Weight.fromGrToSt(10)

Or, using convert.

  • fromGr.toKg
  • fromGr.toMg
  • fromGr.toOz
  • fromGr.toLb
  • fromGr.toSt
const kg = Weight.convert(10).fromGr.toKg()
const mg = Weight.convert(10).fromGr.toMg()
const oz = Weight.convert(10).fromGr.toOz()
const lb = Weight.convert(10).fromGr.toLb()
const st = Weight.convert(10).fromGr.toSt()
Miligram
  • fromMgToKg
  • fromMgToGr
  • fromMgToOz
  • fromMgToLb
  • fromMgToSt
const kg = Weight.fromMgToKg(10)
const gr = Weight.fromMgToGr(10)
const oz = Weight.fromMgToOz(10)
const lb = Weight.fromMgToLb(10)
const st = Weight.fromMgToSt(10)

Or, using convert.

  • fromMg.toKg
  • fromMg.toGr
  • fromMg.toOz
  • fromMg.toLb
  • fromMg.toSt
const kg = Weight.convert(10).fromMg.toKg()
const gr = Weight.convert(10).fromMg.toGr()
const oz = Weight.convert(10).fromMg.toOz()
const lb = Weight.convert(10).fromMg.toLb()
const st = Weight.convert(10).fromMg.toSt()
Ounce
  • fromOzToKg
  • fromOzToGr
  • fromOzToMg
  • fromOzToLb
  • fromOzToSt
const kg = Weight.fromOzToKg(10)
const gr = Weight.fromOzToGr(10)
const mg = Weight.fromOzToMg(10)
const lb = Weight.fromOzToLb(10)
const st = Weight.fromOzToSt(10)

Or, using convert.

  • fromOz.toKg
  • fromOz.toGr
  • fromOz.toMg
  • fromOz.toLb
  • fromOz.toSt
const kg = Weight.convert(10).fromOz.toKg()
const gr = Weight.convert(10).fromOz.toGr()
const mg = Weight.convert(10).fromOz.toMg()
const lb = Weight.convert(10).fromOz.toLb()
const st = Weight.convert(10).fromOz.toSt()
Pound
  • fromLbToKg
  • fromLbToGr
  • fromLbToMg
  • fromLbToOz
  • fromLbToSt
const kg = Weight.fromLbToKg(10)
const gr = Weight.fromLbToGr(10)
const mg = Weight.fromLbToMg(10)
const oz = Weight.fromLbToOz(10)
const st = Weight.fromLbToSt(10)

Or, using convert.

  • fromLb.toKg
  • fromLb.toGr
  • fromLb.toMg
  • fromLb.toOz
  • fromLb.toSt
const kg = Weight.convert(10).fromLb.toKg()
const gr = Weight.convert(10).fromLb.toGr()
const mg = Weight.convert(10).fromLb.toMg()
const oz = Weight.convert(10).fromLb.toOz()
const st = Weight.convert(10).fromLb.toSt()
Stone
  • fromStToKg
  • fromStToGr
  • fromStToMg
  • fromStToLb
  • fromStToOz
const kg = Weight.fromStToKg(10)
const gr = Weight.fromStToGr(10)
const mg = Weight.fromStToMg(10)
const lb = Weight.fromStToLb(10)
const oz = Weight.fromStToOz(10)

Or, using convert.

  • fromSt.toKg
  • fromSt.toGr
  • fromSt.toMg
  • fromSt.toLb
  • fromSt.toOz
const kg = Weight.convert(10).fromSt.toKg()
const gr = Weight.convert(10).fromSt.toGr()
const mg = Weight.convert(10).fromSt.toMg()
const lb = Weight.convert(10).fromSt.toLb()
const oz = Weight.convert(10).fromSt.toOz()

Temperature

Convert a number from one unit to another.

const { NumberEngine: { Temperature } } = require('./lib')
  • fromCToF
  • fromFToC
const value = Temperature.fromCToF(10)
const value = Temperature.fromFToC(10)

Distance

Convert a number from one unit to another.

const { NumberEngine: { Distance } } = require('./lib')
Kilometre
  • fromKmToMt
  • fromKmToCm
  • fromKmToMm
  • fromKmToIn
  • fromKmToFt
  • fromKmToYd
  • fromKmToMi
const mt = Distance.fromKmToMt(10)
const cm = Distance.fromKmToCm(10)
const mm = Distance.fromKmToMm(10)
const in = Distance.fromKmToIn(10)
const ft = Distance.fromKmToFt(10)
const yd = Distance.fromKmToYd(10)
const mi = Distance.fromKmToMi(10)

Or, using convert.

  • fromKm.toMt
  • fromKm.toCm
  • fromKm.toMm
  • fromKm.toIn
  • fromKm.toFt
  • fromKm.toYd
  • fromKm.toMi
const mt = Distance.convert(10).fromKm.toMt()
const cm = Distance.convert(10).fromKm.toCm()
const mm = Distance.convert(10).fromKm.toMm()
const in = Distance.convert(10).fromKm.toIn()
const ft = Distance.convert(10).fromKm.toFt()
const yd = Distance.convert(10).fromKm.toYd()
const mi = Distance.convert(10).fromKm.toMi()
Metre
  • fromMtToKm
  • fromMtToCm
  • fromMtToMm
  • fromMtToIn
  • fromMtToFt
  • fromMtToYd
  • fromMtToMi
const km = Distance.fromMtToKm(10)
const cm = Distance.fromMtToCm(10)
const mm = Distance.fromMtToMm(10)
const in = Distance.fromMtToIn(10)
const ft = Distance.fromMtToFt(10)
const yd = Distance.fromMtToYd(10)
const mi = Distance.fromMtToMi(10)

Or, using convert.

  • fromMt.toKm
  • fromMt.toCm
  • fromMt.toMm
  • fromMt.toIn
  • fromMt.toFt
  • fromMt.toYd
  • fromMt.toMi
const km = Distance.convert(10).fromMt.toKm()
const cm = Distance.convert(10).fromMt.toCm()
const mm = Distance.convert(10).fromMt.toMm()
const in = Distance.convert(10).fromMt.toIn()
const ft = Distance.convert(10).fromMt.toFt()
const yd = Distance.convert(10).fromMt.toYd()
const mi = Distance.convert(10).fromMt.toMi()
Centimetre
  • fromCmToKm
  • fromCmToMt
  • fromCmToMm
  • fromCmToIn
  • fromCmToFt
  • fromCmToYd
  • fromCmToMi
const km = Distance.fromCmToKm(10)
const mt = Distance.fromCmToMt(10)
const mm = Distance.fromCmToMm(10)
const in = Distance.fromCmToIn(10)
const ft = Distance.fromCmToFt(10)
const yd = Distance.fromCmToYd(10)
const mi = Distance.fromCmToMi(10)

Or, using convert.

  • fromCm.toKm
  • fromCm.toMt
  • fromCm.toMm
  • fromCm.toIn
  • fromCm.toFt
  • fromCm.toYd
  • fromCm.toMi
const km = Distance.convert(10).fromCm.toKm()
const mt = Distance.convert(10).fromCm.toMt()
const mm = Distance.convert(10).fromCm.toMm()
const in = Distance.convert(10).fromCm.toIn()
const ft = Distance.convert(10).fromCm.toFt()
const yd = Distance.convert(10).fromCm.toYd()
const mi = Distance.convert(10).fromCm.toMi()
Milimetre
  • fromMmToKm
  • fromMmToMt
  • fromMmToCm
  • fromMmToIn
  • fromMmToFt
  • fromMmToYd
  • fromMmToMi
const km = Distance.fromMmToKm(10)
const mt = Distance.fromMmToMt(10)
const cm = Distance.fromMmToCm(10)
const in = Distance.fromMmToIn(10)
const ft = Distance.fromMmToFt(10)
const yd = Distance.fromMmToYd(10)
const mi = Distance.fromMmToMi(10)

Or, using convert.

  • fromMm.toKm
  • fromMm.toMt
  • fromMm.toCm
  • fromMm.toIn
  • fromMm.toFt
  • fromMm.toYd
  • fromMm.toMi
const km = Distance.convert(10).fromMm.toKm()
const mt = Distance.convert(10).fromMm.toMt()
const cm = Distance.convert(10).fromMm.toCm()
const in = Distance.convert(10).fromMm.toIn()
const ft = Distance.convert(10).fromMm.toFt()
const yd = Distance.convert(10).fromMm.toYd()
const mi = Distance.convert(10).fromMm.toMi()
Inch
  • fromInToKm
  • fromInToMt
  • fromInToCm
  • fromInToMm
  • fromInToFt
  • fromInToYd
  • fromInToMi
const km = Distance.fromInToKm(10)
const mt = Distance.fromInToMt(10)
const cm = Distance.fromInToCm(10)
const mm = Distance.fromInToMm(10)
const ft = Distance.fromInToFt(10)
const yd = Distance.fromInToYd(10)
const mi = Distance.fromInToMi(10)

Or, using convert.

  • fromIn.toKm
  • fromIn.toMt
  • fromIn.toCm
  • fromIn.toMm
  • fromIn.toFt
  • fromIn.toYd
  • fromIn.toMi
const km = Distance.convert(10).fromIn.toKm()
const mt = Distance.convert(10).fromIn.toMt()
const cm = Distance.convert(10).fromIn.toCm()
const mm = Distance.convert(10).fromIn.toMm()
const ft = Distance.convert(10).fromIn.toFt()
const yd = Distance.convert(10).fromIn.toYd()
const mi = Distance.convert(10).fromIn.toMi()
Feet
  • fromFtToKm
  • fromFtToMt
  • fromFtToCm
  • fromFtToMm
  • fromFtToIn
  • fromFtToYd
  • fromFtToMi
const km = Distance.fromFtToKm(10)
const mt = Distance.fromFtToMt(10)
const cm = Distance.fromFtToCm(10)
const mm = Distance.fromFtToMm(10)
const in = Distance.fromFtToIn(10)
const yd = Distance.fromFtToYd(10)
const mi = Distance.fromFtToMi(10)

Or, using convert.

  • fromFt.toKm
  • fromFt.toMt
  • fromFt.toCm
  • fromFt.toMm
  • fromFt.toIn
  • fromFt.toYd
  • fromFt.toMi
const km = Distance.convert(10).fromFt.toKm()
const mt = Distance.convert(10).fromFt.toMt()
const cm = Distance.convert(10).fromFt.toCm()
const mm = Distance.convert(10).fromFt.toMm()
const in = Distance.convert(10).fromFt.toIn()
const yd = Distance.convert(10).fromFt.toYd()
const mi = Distance.convert(10).fromFt.toMi()
Yard
  • fromYdToKm
  • fromYdToMt
  • fromYdToCm
  • fromYdToMm
  • fromYdToIn
  • fromYdToFt
  • fromYdToMi
const km = Distance.fromYdToKm(10)
const mt = Distance.fromYdToMt(10)
const cm = Distance.fromYdToCm(10)
const mm = Distance.fromYdToMm(10)
const in = Distance.fromYdToIn(10)
const ft = Distance.fromYdToFt(10)
const mi = Distance.fromYdToMi(10)

Or, using convert.

  • fromYd.toKm
  • fromYd.toMt
  • fromYd.toCm
  • fromYd.toMm
  • fromYd.toIn
  • fromYd.toFt
  • fromYd.toMi
const km = Distance.convert(10).fromYd.toKm()
const mt = Distance.convert(10).fromYd.toMt()
const cm = Distance.convert(10).fromYd.toCm()
const mm = Distance.convert(10).fromYd.toMm()
const in = Distance.convert(10).fromYd.toIn()
const ft = Distance.convert(10).fromYd.toFt()
const mi = Distance.convert(10).fromYd.toMi()
Mile
  • fromMiToKm
  • fromMiToMt
  • fromMiToCm
  • fromMiToMm
  • fromMiToIn
  • fromMiToFt
  • fromMiToYd
const km = Distance.fromMiToKm(10)
const mt = Distance.fromMiToMt(10)
const cm = Distance.fromMiToCm(10)
const mm = Distance.fromMiToMm(10)
const in = Distance.fromMiToIn(10)
const ft = Distance.fromMiToFt(10)
const yd = Distance.fromMiToYd(10)

Or, using convert.

  • fromMi.toKm
  • fromMi.toMt
  • fromMi.toCm
  • fromMi.toMm
  • fromMi.toIn
  • fromMi.toFt
  • fromMi.toYd
const km = Distance.convert(10).fromMi.toKm()
const mt = Distance.convert(10).fromMi.toMt()
const cm = Distance.convert(10).fromMi.toCm()
const mm = Distance.convert(10).fromMi.toMm()
const in = Distance.convert(10).fromMi.toIn()
const ft = Distance.convert(10).fromMi.toFt()
const yd = Distance.convert(10).fromMi.toYd()

StringEngine

const { StringEngine } = require('./lib')

charAt

Accepts a string and a number which is an index. Returns the character for the entity at the index.

const string = StringEngine.charAt('Hello, World', 5) // returns ','
const string = StringEngine.charAt('Hello, World', 5) // returns ','

charCodeAt

Accepts a string and a number which is an index. Returns the character code for the entity at the index.

const number = StringEngine.charCodeAt('Hello, World', 5) // returns 44
const number = StringEngine.charCodeAt('Hello, World', 5) // returns 44

charOf

Accepts a string which is an HTML entity. Returns the character for the entity.

const string = StringEngine.charOf(',') // returns ','
const string = StringEngine.charOf(',') // returns ','

charCodeOf

Accepts a string which is an HTML entity. Returns the character code for the entity.

const number = StringEngine.charCodeOf(',') // returns 44
const number = StringEngine.charCodeOf(',') // returns 44

entityAt

Accepts a string and a number which is an index.

Where the character at the index is an entity, it returns the entity.

const string = StringEngine.entityAt('Hello, World', 5) // returns ','
const string = StringEngine.entityAt('Hello, World', 6) // returns ' '

Where the character at the index has an entity name, it returns the entity name.

const string = StringEngine.entityAt('Hello, World', 5) // returns ','

Where the character at the index has an entity code, it returns the entity code.

const string = StringEngine.entityAt('Hello, World', 6) // returns ' '

entityCodeAt

Accepts a string and a number which is an index.

Where the character at the index has an entity code, it returns the entity code.

const string = StringEngine.entityCodeAt('Hello, World', 5) // returns ','

Where the character at the index is an entity code, it returns the entity code.

const string = StringEngine.entityCodeAt('Hello, World', 5) // returns ','

Where the character at the index is an entity name, it returns the entity code for the char at the index.

const string = StringEngine.entityCodeAt('Hello, World', 5) // returns '&'

entityNameAt

Accepts a string and a number which is an index.

Where the character at the index has an entity name, it returns the entity name.

const string = StringEngine.entityNameAt('Hello, World', 5) // returns ','

Where the character at the index is an entity name, it returns the entity name.

const string = StringEngine.entityNameAt('Hello, World', 5) // returns ','

Where the character at the index is an entity code, it returns the entity name for the char at the index.

const string = StringEngine.entityNameAt('Hello, World', 5) // returns '&'

entityOf

Accepts a string and a number which is an index.

Where the character at the index is an entity, it returns the entity.

const string = StringEngine.entityOf(',') // returns ','
const string = StringEngine.entityOf(' ') // returns ' '

fromCharCode

Accepts a number which is a character code. Returns the character for that code.

const string = StringEngine.charFromEntityCode('+') // returns '+'

charFromEntityCode

Accepts a string which is an HTML entity code. Returns the character for that entity.

const string = StringEngine.charFromEntityCode('+') // returns '+'

charFromEntityName

Accepts a string which is an HTML entity name. Returns the character for that entity.

const string = StringEngine.charFromEntityCode('+') // returns '+'

toEntityCode

Accepts a string. Returns a string replaced with the HTML entity code for each character.

const string = StringEngine.toEntityCode('Hello, World') // returns 'Hello, World'

toEntityName

Accepts a string. Returns a string replaced with the HTML entity name for each character where it is known, otherwise the character is not replaced.

const string = StringEngine.toEntityName('Hello, World') // returns 'Hello, World'

entityCodeFromChar

Accepts a single-character string. Returns a string representing the HTML entity code for that character.

const entityCode = StringEngine.entityCodeFromChar('+') // returns '+'

The entity is computed from the character code point.

entityNameFromChar

Accepts a single-character string. Returns a string representing the HTML entity code for that character.

const entityName = StringEngine.entityNameFromChar('+') // returns '+'

Where the character has no entity or the entity is not known it returns the character.

entityCodeOf

See entityCodeFromChar.

entityNameOf

See entityNameFromChar.

fromDecToOct

Accepts number. Returns a string representing an octal.

const oct = StringEngine.fromDecToOct(16) // returns '20'

fromDecToHex

Accepts number. Returns a string representing a hexadecimal.

const hex = StringEngine.fromDecToHex(16) // returns '10'

reverse

Accepts a string. Returns the string with characters in reverse order.

const string = StringEngine.reverse('ABCDE') // returns 'EDCBA'

FAQs

Last updated on 28 Mar 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc