mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9da10ac66e
commit
4b0a26e6f7
103
test.js
103
test.js
@ -66,43 +66,6 @@ module.VERBOSE = process ?
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// helpers...
|
// helpers...
|
||||||
|
|
||||||
/*/ Add colors to String...
|
|
||||||
var colors =
|
|
||||||
String.colors = {
|
|
||||||
reset: '\x1b[0m',
|
|
||||||
bold: '\x1b[1m',
|
|
||||||
dim: '\x1b[2m',
|
|
||||||
underscore: '\x1b[4m',
|
|
||||||
blink: '\x1b[5m',
|
|
||||||
reverse: '\x1b[7m',
|
|
||||||
hidden: '\x1b[8m',
|
|
||||||
|
|
||||||
black: '\x1b[30m',
|
|
||||||
red: '\x1b[31m',
|
|
||||||
green: '\x1b[32m',
|
|
||||||
yellow: '\x1b[33m',
|
|
||||||
blue: '\x1b[34m',
|
|
||||||
magenta: '\x1b[35m',
|
|
||||||
cyan: '\x1b[36m',
|
|
||||||
white: '\x1b[37m',
|
|
||||||
|
|
||||||
bgblack: '\x1b[40m',
|
|
||||||
bgred: '\x1b[41m',
|
|
||||||
bggreen: '\x1b[42m',
|
|
||||||
bgyellow: '\x1b[43m',
|
|
||||||
bgblue: '\x1b[44m',
|
|
||||||
bgmagenta: '\x1b[45m',
|
|
||||||
bgcyan: '\x1b[46m',
|
|
||||||
bgwhite: '\x1b[47m',
|
|
||||||
}
|
|
||||||
Object.entries(colors)
|
|
||||||
.forEach(function([color, seq]){
|
|
||||||
Object.defineProperty(String.prototype, color, {
|
|
||||||
get: function(){
|
|
||||||
return seq + (this.endsWith(colors.reset) ?
|
|
||||||
this
|
|
||||||
: this + String.colors.reset) } }) })
|
|
||||||
//*/
|
|
||||||
Object.defineProperty(String.prototype, 'raw', {
|
Object.defineProperty(String.prototype, 'raw', {
|
||||||
get: function(){
|
get: function(){
|
||||||
return this.replace(/\x1b\[..?m/g, '') }, })
|
return this.replace(/\x1b\[..?m/g, '') }, })
|
||||||
@ -116,6 +79,7 @@ var deepKeys = function(obj, stop){
|
|||||||
obj = obj.__proto__ }
|
obj = obj.__proto__ }
|
||||||
return [...(new Set(res.flat()))] }
|
return [...(new Set(res.flat()))] }
|
||||||
|
|
||||||
|
|
||||||
// compare two arrays by items...
|
// compare two arrays by items...
|
||||||
var arrayCmp = function(a, b){
|
var arrayCmp = function(a, b){
|
||||||
var ka = Object.keys(a)
|
var ka = Object.keys(a)
|
||||||
@ -131,6 +95,38 @@ var arrayCmp = function(a, b){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
// a constructor is a thing that starts with a capital and has a .prototype
|
||||||
|
var constructors = function(obj){
|
||||||
|
return Object.entries(obj)
|
||||||
|
.filter(function([k, o]){
|
||||||
|
return k[0] == k[0].toUpperCase()
|
||||||
|
&& o.prototype }) }
|
||||||
|
|
||||||
|
// an instance is a thing that starts with a lowercase and has a .constructor
|
||||||
|
var instances = function(obj){
|
||||||
|
return Object.entries(obj)
|
||||||
|
.filter(function([k, o]){
|
||||||
|
return k[0] == k[0].toLowerCase()
|
||||||
|
&& o.constructor }) }
|
||||||
|
|
||||||
|
|
||||||
|
var makeAssert = function(pre, stats){
|
||||||
|
return function(e, msg, ...args){
|
||||||
|
stats
|
||||||
|
&& (stats.assertions += 1)
|
||||||
|
&& !e
|
||||||
|
&& (stats.failures += 1)
|
||||||
|
module.VERBOSE
|
||||||
|
&& console.log(pre +': '+ msg.bold, ...args)
|
||||||
|
console.assert(e, pre.bold +': '+ msg.bold.yellow, ...args)
|
||||||
|
return e } }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// basic argv parser...
|
// basic argv parser...
|
||||||
//
|
//
|
||||||
// Format:
|
// Format:
|
||||||
@ -316,37 +312,8 @@ var ArgvParser = function(spec){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
|
|
||||||
// a constructor is a thing that starts with a capital and has a .prototype
|
|
||||||
var constructors = function(obj){
|
|
||||||
return Object.entries(obj)
|
|
||||||
.filter(function([k, o]){
|
|
||||||
return k[0] == k[0].toUpperCase()
|
|
||||||
&& o.prototype }) }
|
|
||||||
|
|
||||||
// an instance is a thing that starts with a lowercase and has a .constructor
|
|
||||||
var instances = function(obj){
|
|
||||||
return Object.entries(obj)
|
|
||||||
.filter(function([k, o]){
|
|
||||||
return k[0] == k[0].toLowerCase()
|
|
||||||
&& o.constructor }) }
|
|
||||||
|
|
||||||
|
|
||||||
var makeAssert = function(pre, stats){
|
|
||||||
return function(e, msg, ...args){
|
|
||||||
stats
|
|
||||||
&& (stats.assertions += 1)
|
|
||||||
&& !e
|
|
||||||
&& (stats.failures += 1)
|
|
||||||
module.VERBOSE
|
|
||||||
&& console.log(pre +': '+ msg.bold, ...args)
|
|
||||||
console.assert(e, pre.bold +': '+ msg.bold.yellow, ...args)
|
|
||||||
return e } }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
// Tests...
|
||||||
|
|
||||||
var setups =
|
var setups =
|
||||||
module.setups = {
|
module.setups = {
|
||||||
@ -617,7 +584,6 @@ module.modifiers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var tests =
|
var tests =
|
||||||
module.tests = {
|
module.tests = {
|
||||||
// instance creation...
|
// instance creation...
|
||||||
@ -681,7 +647,6 @@ module.cases = {
|
|||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
// Test runner...
|
// Test runner...
|
||||||
//
|
//
|
||||||
// runner()
|
// runner()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user