Skip to content

Commit

Permalink
feat: Add isFunction and isPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
Akurganow committed Oct 9, 2023
1 parent ebccef2 commit 8e7e1a3
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 909 deletions.
15 changes: 12 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"env": {
"node": true,
"browser": true,
"esnext": true
"jest": true,
"es2016": true
},
"extends": "standard-with-typescript",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
Expand All @@ -14,6 +21,8 @@
"object-curly-spacing": [2, "always"],
"semi": [2, "never"],
"quotes": [2, "single"],
"indent": [2, "tab"]
"indent": [2, "tab"],
"@typescript-eslint/indent": [2, "tab"],
"@typescript-eslint/ban-types": [0]
}
}
82 changes: 0 additions & 82 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/lib/
.env

# Logs
logs
Expand All @@ -26,28 +25,10 @@ lib-cov
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

Expand All @@ -57,77 +38,14 @@ web_modules/
# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
110 changes: 110 additions & 0 deletions __tests__/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import isFunction from '../src/utils/is-function'
import isPromise from '../src/utils/is-promise'

describe('isFunction', () => { tests('function', isFunction) })
describe('isPromise', () => { tests('promise', isPromise) })

function tests (truthy: string, fn: (value: unknown) => boolean) {
test('function', () => {
expect(fn(() => {})).toBe(truthy === 'function')
})
test('object', () => {
expect(fn({})).toBe(truthy === 'object')
})
test('string', () => {
expect(fn('')).toBe(truthy === 'string')
})
test('number', () => {
expect(fn(0)).toBe(truthy === 'number')
})
test('boolean', () => {
expect(fn(true)).toBe(truthy === 'boolean')
})
test('undefined', () => {
expect(fn(undefined)).toBe(truthy === 'undefined')
})
test('null', () => {
expect(fn(null)).toBe(truthy === 'null')
})
test('array', () => {
expect(fn([])).toBe(truthy === 'array')
})
test('symbol', () => {
expect(fn(Symbol())).toBe(truthy === 'symbol')
})
test('bigint', () => {
expect(fn(1n)).toBe(truthy === 'bigint')
})
test('regexp', () => {
expect(fn(/a/)).toBe(truthy === 'regexp')
})
test('date', () => {
expect(fn(new Date())).toBe(truthy === 'date')
})
test('error', () => {
expect(fn(new Error())).toBe(truthy === 'error')
})
test('map', () => {
expect(fn(new Map())).toBe(truthy === 'map')
})
test('set', () => {
expect(fn(new Set())).toBe(truthy === 'set')
})
test('weakmap', () => {
expect(fn(new WeakMap())).toBe(truthy === 'weakmap')
})
test('weakset', () => {
expect(fn(new WeakSet())).toBe(truthy === 'weakset')
})
test('int8array', () => {
expect(fn(new Int8Array())).toBe(truthy === 'int8array')
})
test('uint8array', () => {
expect(fn(new Uint8Array())).toBe(truthy === 'uint8array')
})
test('uint8clampedarray', () => {
expect(fn(new Uint8ClampedArray())).toBe(truthy === 'uint8clampedarray')
})
test('int16array', () => {
expect(fn(new Int16Array())).toBe(truthy === 'int16array')
})
test('uint16array', () => {
expect(fn(new Uint16Array())).toBe(truthy === 'uint16array')
})
test('int32array', () => {
expect(fn(new Int32Array())).toBe(truthy === 'int32array')
})
test('uint32array', () => {
expect(fn(new Uint32Array())).toBe(truthy === 'uint32array')
})
test('float32array', () => {
expect(fn(new Float32Array())).toBe(truthy === 'float32array')
})
test('float64array', () => {
expect(fn(new Float64Array())).toBe(truthy === 'float64array')
})
test('bigint64array', () => {
expect(fn(new BigInt64Array())).toBe(truthy === 'bigint64array')
})
test('biguint64array', () => {
expect(fn(new BigUint64Array())).toBe(truthy === 'biguint64array')
})
test('arraybuffer', () => {
expect(fn(new ArrayBuffer(2))).toBe(truthy === 'arraybuffer')
})
test('dataview', () => {
expect(fn(new DataView(new ArrayBuffer(2)))).toBe(truthy === 'dataview')
})
test('promise', () => {
expect(fn(Promise.resolve())).toBe(truthy === 'promise')
})
test('generator', () => {
expect(fn(function * () {})).toBe(truthy === 'generator')
})
test('generatorfunction', () => {
expect(fn(function * () {})).toBe(truthy === 'generatorfunction')
})
test('asyncfunction', () => {
expect(fn(async () => {})).toBe(truthy === 'asyncfunction')
})
}
17 changes: 17 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

import type { Config } from 'jest'

const config: Config = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-node',
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
}

export default config
Loading

0 comments on commit 8e7e1a3

Please sign in to comment.