0.1.1 first publish

master
David Kebler 2020-01-01 21:09:01 -08:00
parent 8d1b2b6de7
commit f05cf40fd6
8 changed files with 141 additions and 0 deletions

37
.eslintrc.js Normal file
View File

@ -0,0 +1,37 @@
module.exports = {
"ecmaFeatures": {
"modules": true,
"spread" : true,
"restParams" : true
},
// "plugins": [
// "unicorn"
// ],
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
// "unicorn/no-array-instanceof": "error",
"no-console": 0,
"semi": ["error", "never"],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
]
}
}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules/
/coverage/

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
tests/
test/
*.test.js
testing/

17
examples/example.js Normal file
View File

@ -0,0 +1,17 @@
import Ready from '../src/ready'
import { EventEmitter } from 'events'
let emitter = new EventEmitter()
let process = new Ready({emitter: emitter, condition: (ev=> {return ev===true}) })
process.addObserver('one')
process.addObserver('two')
process.addObserver('three')
process.subscribe()
emitter.emit('one',true)
emitter.emit('two',true)
emitter.emit('three',true)
emitter.emit('one',false)

35
package.json Normal file
View File

@ -0,0 +1,35 @@
{
"name": "@uci-utils/to-boolean",
"version": "0.1.1",
"description": "function to return a boolean value from sets of default values",
"main": "src/boolean.js",
"scripts": {
"example": "node --r esm examples/example",
"example:dev": "UCI_ENV=dev ./node_modules/.bin/nodemon -r esm examples/example",
"test": "./node_modules/.bin/mocha -r esm --timeout 30000",
"testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha -r esm --timeout 30000' || exit 0",
"testdd": "UCI_LOG_LEVEL='trace' npm run testd",
"testde": "UCI_LOG_LEVEL='warn' npm run testd",
"testl": "UCI_ENV=pro UCI_LOG_PATH=./test/test.log 0 npm run test || exit 0"
},
"author": "David Kebler",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/uCOMmandIt/.git"
},
"keywords": [
"node.js"
],
"bugs": {
"url": "https://github.com/uCOMmandIt/uci-utils/issues"
},
"homepage": "https://github.com/uCOMmandIt/uci-utils#readme",
"dependencies": {},
"devDependencies": {
"chai": "^4.2.0",
"esm": "^3.2.25",
"mocha": "^6.2.2",
"nodemon": "^1.19.4"
}
}

4
readme.md Normal file
View File

@ -0,0 +1,4 @@
### uCOMmandIt To Boolean
casts a passed value to Boolean
https://repl.it/@dkebler/To-Boolean

22
src/boolean.js Normal file
View File

@ -0,0 +1,22 @@
const rTrue=['t','true','y','yes','on','positive','up','enabled','affirmative','yea','sure']
const rFalse=['f','false','n','no','off','negative','down','disabled','nope']
function createBoolean (opts={}) {
return (value => {
if (value===undefined) return opts.undefined
if (value===null) return opts.null
if (!isNaN(Number(value))) return Number(value) <1 ? false :true
if (typeof value==='string') {
value = value.trim()
value = value.toLowerCase()
if ((opts.rTrue || rTrue).includes(value)) return true
if ((opts.rFalse || rFalse).includes(value)) return false
}
return !!value
})
}
const toBoolean = createBoolean()
export default toBoolean
export { toBoolean, createBoolean, rTrue, rFalse }

20
test/type.test.js Normal file
View File

@ -0,0 +1,20 @@
import { expect } from 'chai'
import u from '../src/type'
describe('Variable Types Library - ', function () {
it('Should include custom types', function () {
expect(u.isBuffer(Buffer.from('this is a test'))).to.equal(true)
expect(u.getType(Buffer.from('this is a test'))).to.equal('buffer')
expect(u.isPromise(Promise.resolve(2))).to.equal(true)
expect(u.getType(Promise.resolve(2))).to.equal('promise')
})
it('Should load typechecker', function () {
expect(u.isPlainObject([1])).to.equal(false)
expect(u.getType(true)).to.equal('boolean')
expect(u.getObjectType('a string')).to.equal('[object String]')
expect(u.getType('this is a test')).to.equal('string')
})
})