Socket
Socket
Sign inDemoInstall

null

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

null - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

172

index.js

@@ -7,146 +7,40 @@ /*/////////////////////////////////////////////////////////////////////////////

const mr = Math.random,
mf = Math.floor,
tl='toLowerCase',
tu='toUpperCase',
isa=Array.isArray,
sfc=String.fromCharCode,
log=console.log;
const NULL = Symbol.for('NULL_SYMBOL');
/*/////////////////////////////////////////////////////////////////////////////
// GX Lib
/////////////////////////////////////////////////////////////////////////////*/
const lib = {
get: ()=>{
return Symbol.for('NULL_SYMBOL');
},
is : (ref)=>{
return (typeof ref!=='undefined' && ref===null || ref === NULL );
},
to : (ref)=>{
if( lib.is(ref) ) return lib.get()
return ref;
},
isRef: (ref)=>{
return (ref===NULL);
},
isEmpty: (ref)=>{
return (lib.isNullRef(ref) || ref==='');
},
emptyType : (ref)=>{
if (typeof ref==='undefined') return 'IS_UNDEFINED';
if (ref==='') return 'IS_EMPTY';
if (ref===NULL) return 'IS_NULLREF';
if (ref===null) return 'IS_NULL';
return 'NOT_EMPTY';
}
}
const timestamp = () => { return +new Date(); }
const stringify = (s) => { return JSON.stringify(s) + ""; }
const keyParse = (u) => { let q=Object.keys(u); return(q.length ? q : '--'); }
const quickRand = (m,n)=> { n=n||0;m=(isa(m)?m.length:m); return mf(mr()*m)+n; }
const hexGen = (n) => { function b(a){ return a?(a^mr()*16>>a/4).toString(16):([1e7]+1e3+4e3+'').replace(/[018]/g,b); } return b(n); }
const clockGen = (m,c)=> { c=c||1;return (x)=>{ if(m!==null && c<=m){ if(x) c=0;return c++;} return null;}};
const counter = clockGen(true);
const alnumGen = (l,a)=>{
a=a&&a[tl](),s="",i=0,m=a=="a"?10:0,n=a=="n"?10:62;
for(;i++<l;){let r=mr()*(n-m)+m<<0; s+=sfc(r+=r>9?r<36?55:61:48);}
return s;
}
const kvGen = (f,i=0) =>{
let len = f||quickRand(5,1);
let s = alnumGen(len,'a')[tl]();
s = s.split('');
clk = clockGen(s.length);
dd = usDateRangeGen( toDate([3,22,1905]), toDate([3,22,2015]) );
let o = { row : i, id : alnumGen(len,'n'), name : nameGen(), bday : dd() };
while(s.length >= 1) o[`key_${clk()}`] = `val_${s.pop()}`;
return o;
}
const dataGen = (x,f) => {
var res=[],i=0,c=clockGen(x),f = f||quickRand(5,1);
while(i!==null){ i = c(); if(i==null) continue; res.push(kvGen(f,i)); }
return res;
}
const nameGen = (dict) => {
i=0, j=0, fl='', nl='', dict = dict || {
pre:[ 'tom', 'ark', 'far', 'shi', 'zag', 'mar', 'dav', 'jen', 'rob', 'bren', 'sam' ],
suf:[ 'is', 'malo', 'zak', 'ben', 'wonk', 'quez', 'ender', 'ali', 'son', 'kor' ]
}
fnl = clockGen(1);
lnl = clockGen(quickRand(3));
while(i!==null){ i = fnl(); fl +=dict.pre[quickRand(dict.pre)] + dict.suf[quickRand(dict.suf)]; }
while(j!==null){ j = lnl(); nl +=dict.suf[quickRand(dict.suf)]; }
function tcase(a){ return a.charAt(0)[tu]() + a.substr(1)[tl]();}
var name = tcase(fl)+" "+tcase(nl);
return (name);
}
const dateRangeGen = (s,e,cb) => {
return ()=>{ d=new Date(s.getTime() + Math.random() * (e.getTime() - s.getTime())); if(cb) return cb(d); return d; }
}
const toDate = (d) => {
if(isa(d)) return new Date(d[2],d[1],d[0]);
return new Date();
}
const usDate = (d) => { d = new Date(d); return d.toLocaleDateString('en-US'); }
const usDateRangeGen = (s,e, cb) => {
return dateRangeGen(s,e,usDate);
}
//usDateGenerator => var dd = fx.dg( fx.td([3,22,1900]), fx.td(), locale );
//dateGen(new Date(2012, 0, 1), new Date())
//SuperGenerator => generator => data
const superGenerator = ( api, conf, input, dx ) =>{
}
const sseGenerator = ( ms, mod, srl, generator) => {
function intervalGenerator(o){
to = setInterval(function(){
console.log('writing ' + testdata);
o.write('data: ' + JSON.stringify({ msg : testdata }) + '\n\n');
}, ms);
return to;
}
mod.get( srl, ( i,o,n )=> {
i.socket.setKeepAlive(true);
i.socket.setTimeout(0);
o.writeHead(200, {
'Connection' : 'keep-alive',
'Content-Type' : 'text/event-stream',
'Cache-Control': 'no-cache'
});
to = intervalGenerator(o);
mod.get('/api/timeout', ( i,o,n )=> {
clearInterval(to);
o.send('Killing Timer');
});
o.on('close', ()=> {
clearInterval(to);
});
});
}
/*/////////////////////////////////////////////////////////////////////////////
// GX Driver
// Exports
/////////////////////////////////////////////////////////////////////////////*/
module.exports = {
t : timestamp,
j : stringify,
k : keyParse,
c : counter,
r : quickRand,
h : hexGen,
a : alnumGen,
d : dataGen,
cg : clockGen,
dg : dateRangeGen,
td : toDate,
ud : usDate,
udg: usDateRangeGen,
ng : nameGen,
kv : kvGen,
sse: sseGenerator
};
module.exports = ()=>{ return NULL; }
module.exports.lib = lib;
module.exports.isNull = lib.is;
module.exports.isNullRef = lib.isRef;
module.exports.toNull = lib.to;
module.exports.NULL = NULL;

2

package.json
{
"name": "null",
"version": "1.0.1",
"version": "2.0.0",
"description": "Null generator library",

@@ -5,0 +5,0 @@ "main": "index.js",

# null
Null all of the things!
Null all of the things! This package was originally created as a joke, but hey now it actually does something non-trivial.
If you ever use `null` for logic tests, you can try using a `Symbol` instead via the NullRef library provided by this package.
This package provides for a `NULL` constant that is a Symbol from the Global Symbol Registry, as well as convenience methods for testing, casting, and comparing values.
## Usage
Require and reference what you need:
```javascript
const nullref = require('null'); // note that the variable name should not be null, here we use nullref
const nulltest = nullref.lib; // load the full library of convenience features
const isNull = nullref.isNull // or just load the main ones you want (checks for null or NULL)
const isNullRef = nullref.isNullRef // checks for NULL only
const NULL = nullref(); // NULL symbol instance (singleton);
```
Consume and use as needed.
```javascript
let x = null;
//returns true if x is null or NULL
if( nulltest.is(x) ) //do something
if( isNull(x) ) // same as above
//cast a variable to NULL if it is null or NULL, otherwise it returns itself
if( NULL === nulltest.to(x) ) // do something
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc