npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crisp-base

v0.7.3

Published

Base OpenCrisp JavaScript functions for Web-Clients and Server-Nodes

Downloads

48

Readme

Crisp.BaseJS

Base OpenCrisp JavaScript functions for Web-Clients and Server-Nodes

Build Status NPM Downloads NPM Version

// return namespace objects
Crisp.ns('my.namespace');

// apply a function with arguments optional asyncronous
Crisp.utilTick( this, callback, { args: [] }, async );

// return the small JavaScript object name
Crisp.type.call( {} );                         // 'Object'

// check the JavaScript object type with a smaller name
Crisp.type.call( {}, 'Object' );               // true

Index Table

Getting Started

Server-Nodes

Use Node Package Manager (npm) to install crisp-base for Node.js and io.js

$ npm install crisp-base
// use package
require("crisp-base");

or use the OpenCrisp UtilJS wraper

$ npm install crisp-util
// use package
require("crisp-util");

Web-Clients

Use Bower to install crisp-base for Browsers APP's and other front-end workflows.

$ bower install crisp-base
<!-- use package -->
<script type="text/javascript" src="dist/crisp-base.min.js"></script>

or use the OpenCrisp UtilJS wraper

$ bower install crisp-util
<!-- use package -->
<script type="text/javascript" src="dist/crisp-util.min.js"></script>

Development

Use Git to clone Crisp.BaseJS from GitHub to develop the repository with Grunt

# Clone:
$ git clone https://github.com/OpenCrisp/Crisp.BaseJS.git

# Build: test, concat, test, minify, test
$ grunt

# Test: original sourcecode for developer (included in build)
$ grunt t

# Run all test-scripts on Unix
$ sh grunt-tests.sh

Usage

How to use Crisp.BaseJS function in JavaScript

// global value of Crisp
var $$ = Crisp;

// private function
(function($$) {
  // code
})(Crisp);

Crisp.ns()

How to use Crisp.ns( name [, object ]) namespaces in JavaScript

// GET namespace
Crisp.ns('a'); // return reference of a = {}

// SET and GET namespaces
Crisp.ns('b', { a: 'A' }); // return reference of b = { a: 'A' }

Why namespaces for OpenCrisp?

You can manged youre modules in namespaces an inherit one or more with Crisp.utilCreate(option) in JavaScript. Example: include Crisp.EventJS and Crisp.PathJS with Crisp.CreateJS

var myObject = Crisp.utilCreate({
  ns: ['util.event','util.path']
}).objIni();

// now you can use the functions of Crisp.EventJS on your object
myObject.eventListener( option );
myObject.eventTrigger( option );

// or the functions of Crisp.PathJS
myObject.pathFind( option );
myObject.pathExists( path );

Crisp.utilTick()

How to use Crisp.utilTick( this, callback, options, async=false ) in JavaScript

// synchronous execution of an anonymous function
Crisp.utilTick({ a: 'A' }, function() {
  console.log(this);
});

console.log('END');
// logs:
// { "a": "A" }
// END
// asynchronous exetution of an named function
function test( b ) {
  console.log( b.c );
}

Crisp.utilTick( { a: 'A' }, test, { args: 'C' }, true );

console.log('END');
// logs:
// END
// { "a": "A" }

Why utilTick event loop for OpenCrisp?

You have one interface for apply functions one behind the other (sync) or parallel (async). You must only set the default option of async=false to async=true

Crisp.to

How to use Crisp.to.call( this ) in JavaScript

Crisp.to.call('a');         // '"a"'
Crisp.to.call({ a: 'A' });  // '{"a":"A"}'

use .xTo() on all global JavaScript objects

Crisp.parse

How to use Crisp.parse.call( this ) in JavaScript

Crisp.parse.call('"a"');        // 'a'
Crisp.parse.call('{"a":"A"}');  // { a: 'A' }

use .xParse() on global JavaScript object String

Crisp.type

How to use Crisp.type.call( this [, name ]) in JavaScript

// GET the small type name of JavaScript objects
Crisp.type.call( '' );          // 'String'
Crisp.type.call( 0 );           // 'Number'
Crisp.type.call( true );        // 'Boolean'
Crisp.type.call( new Date() );  // 'Date'
Crisp.type.call( {} );          // 'Object'
Crisp.type.call( [] );          // 'Array'
Crisp.type.call( /a/g );        // 'RegExp'

Crisp.type.call( null );        // 'Undefined'
Crisp.type.call( undefined );   // 'Undefined'

// CHECK the small type name of JavaScript objects
Crisp.type.call( '',         'String' );     // true
Crisp.type.call( 0,          'Number' );     // true
Crisp.type.call( true,       'Boolean' );    // true
Crisp.type.call( new Date(), 'Date' );       // true
Crisp.type.call( {},         'Object' );     // true
Crisp.type.call( [],         'Array' );      // true
Crisp.type.call( /a/g,       'RegExp' );     // true

Crisp.type.call( null,       'Undefined' );  // true
Crisp.type.call( undefined,  'Undefined' );  // true

// CHECK group of object type
Crisp.type.call(         '', 'field' );  // true
Crisp.type.call(          0, 'field' );  // true
Crisp.type.call(       true, 'field' );  // true
Crisp.type.call( new Date(), 'field' );  // true
Crisp.type.call(       /a/g, 'field' );  // true

use .xType() on all global JavaScript objects

Crisp.math()

How to use Crisp.math() in JavaScript

Crisp.math.call( -1, 'abs'); // 1

use .xMath() on global JavaScript objects String and Number

Global object functions

.xType()

How to use .xType([ name ]) prototype functions on JavaScript objects. @implements Crisp.type

// GET the small type name of JavaScript objects
    ''.xType();  // 'String'
   (0).xType();  // 'Number'
(true).xType();  // 'Boolean'
Date().xType();  // 'Date'
    {}.xType();  // 'Object'
    [].xType();  // 'Array'
(/a/g).xType();  // 'RegExp'

// CHECK the small type name of JavaScript objects
    ''.xType( 'String' );   // true
   (0).xType( 'Number' );   // true
(true).xType( 'Boolean' );  // true
Date().xType( 'Date' );     // true
    {}.xType( 'Object' );   // true
    [].xType( 'Array' );    // true
(/a/g).xType( 'RegExp' );   // true

.xTo()

How to use .xTo() prototype function on JavaScript objects. @implements Crisp.to << JSON.stringify

// GET the JSON string of JavaScript objects
               'a'.xTo();  // '"a"'
               (0).xTo();  // '0'
            (true).xTo();  // 'true'
Date('2015-07-13').xTo();  // '"2015-07-13T00:00:00.000Z"'
        { a: "a" }.xTo();  // '{"a":"a"}'
          [ 1, 0 ].xTo();  // '[1,2]'
            (/a/g).xTo();  // '"/a/g"'

.xParse()

How to use String().xParse() prototype function on JavaScript. @implements Crisp.parse << JSON.parse

Parse the given JSON typed string

                       '"a"'.xParse();  // 'a'          String
                   '"b\\"c"'.xParse();  // 'b"c'        String
                       '1.5'.xParse();  // 1.5          Number
                      'true'.xParse();  // true         Boolean
'"2015-07-13T00:00:00.000Z"'.xParse();  // Date()       Date
                 '{"a":"A"}'.xParse();  // { a: 'A' }   Object
                     '["a"]'.xParse();  // ['a']        Array

.xAdd()

How to use Array().xAdd( list [, list ]) prototype functions on JavaScript.

// standard
[].xAdd('a');           // ['a']
[].xAdd( 'a', 'b' );    // ['a','b']
[].xAdd([ 'a', 'b' ]);  // ['a','b']
[].xAdd(['a'], ['b']);  // ['a','b']

// empty items
[].xAdd();           // []
[].xAdd([]);         // []
[].xAdd(['a'], []);  // ['a']

// undefined items
[].xAdd( undefined );           // []
[].xAdd( undefined, 'b' );      // ['b']
[].xAdd([ 'a', undefined ]);    // ['a']
[].xAdd(['a'], [ undefined ]);  // ['a']    

Why xAdd concatenation for OpenCrisp?

.xAdd() combines the given arguments of an Array and includes all items. The difference to [].concat() is to ignore undefined items of lists.

.xEach()

How to use .xEach( option ) prototype functions on JavaScript objects.

// use `throw new Break()` to stop xEach and go to callback.complete
var Break = Crisp.ns('util.control.Break');
// synchronus Object.xEach()
{a:'A',b:'B'}.xEach({
  success: function( item, index ) {
    // return; go to the next item 
    // throw new Break(); stop xEach of items
    console.log('Success:', index, item );
  },
  complete: function() {
    console.log('Complete');
  }
});
console.log('End');

// logs:
// Success: a A
// Success: b B
// Complete
// End
// asynchronus Object.xEach()
{a:'A',b:'B'}.xEach({
  async: true,
  success: function( item, index ) {
    // return; go to the next item 
    // throw new Break(); stop each of items
    console.log('Success:', index, item );
  },
  complete: function() {
    console.log('Complete');
  }
});
console.log('End');

// logs:
// End
// Success: a A
// Success: b B
// Complete
// syncronus Array.xEach()
['A','B'].xEach({
  success: function( item, index ) {
    // return; go to the next item 
    // throw new Break(); stop each of items
    console.log('Success:', index, item );
  },
  complete: function() {
    console.log('Complete');
  }
});
console.log('End');

// logs:
// Success: 0 A
// Success: 1 B
// Complete
// End
// asynchronus Array.xEach()
['A','B'].xEach({
  async: true,
  success: function( item, index ) {
    // return; go to the next item 
    // throw new Break(); stop each of items
    console.log('Success:', index, item );
  },
  complete: function() {
    console.log('Complete');
  }
});
console.log('End');

// logs:
// End
// Success: 0 A
// Success: 1 B
// Complete

.xMath()

How to use .xMath( name ) prototype function on JavaScript objects. @implements Crisp.math << Math[function name]( args )

// GET the return of `Math[name].call(this)` function
   (1).xMath('abs');  // 1
  (-1).xMath('abs');  // 1
(-0.1).xMath('abs');  // 0.1

   '1'.xMath('abs');  // 1
  '-1'.xMath('abs');  // 1
'-0.1'.xMath('abs');  // 0.1

Why xMath on global object of String and Number for OpenCrisp?

You can use the function directly in Crisp.PathJS without external coding.

// example with Crisp.PathJS
var myObject = [ 20.49, 20.5, 20, 21 ];
Crisp.definePath( myObject );

myObject.pathFind({
  path: '*( :xMath("round") >= 21 )',
  success: function( item ) {
    console.log('Success:', item );
  },
  complete: function( e ) {
    console.log('Complete');
  }
});
console.log('End');

// logs:
// Success: 20.5
// Success: 21
// Complete
// End

Number.isInteger()

How to use ES6 Number.isInteger( number ) function on JavaScript.

Number.isInteger(1);   // true
Number.isInteger(0.5); // false

RegExp.escape()

How to use RegExp.escape( string ) function on JavaScript.

RegExp.escape('a.b'); // 'a\\.b'

Links