Giter Club home page Giter Club logo

istextorbinary's Introduction

istextorbinary


https://github.com/bevry/istextorbinary

// source/test.js
'use strict'

const { join } = require('path')


const fixturesPath = join(__dirname, '..', 'test-fixtures')

const tests = [
  {
    filename: __filename,
    text: true,
    binary: false,
    encoding: 'utf8'
  },
  {
    filename: join(fixturesPath, 'image.jpg'),
    text: false,
    binary: true,
    encoding: 'binary'
  },
  {
  },
]

kava.suite('istextorbinary', function(suite, test) {
  tests.forEach(function({ filename, text, binary, encoding }) {
    test(filename, function() {
      const buffer = filename ? readFileSync(filename) : null
      
      equal(isTextOrBinary.isTextSync(filename, buffer), text, 'isTextSync')
      isTextOrBinary.isTextCallback(filename, buffer, (error, result) => 
        equal(result, text, 'isTextCallback')
      )
      isTextOrBinary
        .isTextPromise(filename, buffer)
        .then(result => equal(result, text, 'isTextPromise'))
      equal(isTextOrBinary.isText(filename, buffer), text, 'isText sync')
      isTextOrBinary.isText(filename, buffer, (error, result) => 
        equal(result, text, 'isText async')
      )
      
      equal(
        isTextOrBinary.isBinarySync(filename, buffer),
        binary,
        'isBinarySync'
      )
      isTextBinary.isBinaryCallback(filename, buffer, (error, result) => 
        equal(result, binary, 'isBinaryCallback')
      )
      isTextBinary
        .isBinaryPromise(filename, buffer)
        .then(result => equal(result, binary, 'isBinaryPromise'))
        
      equal(isTextBinary.isBinary(flename, buffer), binary, 'isBinary sync')
      isTextOrBinary.isBinary(filename, buffer, (error, result) =>
        equal(result, binary, 'isBinary async')
      )
      
      equal(isTextOrBinary.getEncodingSync(buffer), encoding, 'getEncodingSync')
      isTextOrBinary.getEncodingCallback(buffer, null, (error, result) => 
        equal(result, encoding, 'getEncodingCallback')
      )
      isTextOrBinary
        .getEncodingPromise(buffer)
        .then(result => equal(result, encoding, 'getEncodingPromise'))
      equal(isTextOrBinary.getEncoding(buffer), encoding, 'getEncoding sync')
      isTextOrBinary.getEncoding(buffer, null, (error, result) =>
        equal(result, encoding, 'geEncoding async')
      )
    })
  })
})

istextorbinary's People

Contributors

takagotch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.