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

wcom

v0.1.1

Published

Module which support waw project on basic level, elements and scripts which is needed on all projects.

Downloads

5

Readme

wcom waw AngularJS common

Module which support waw project on basic level, elements and scripts which is needed on all projects.

Mongo service provide connection between waw crud and everything that will be needed for mongo documents management.

SD service provide collection of functions for general use.

Modal service handling everything that has to be added into modal or alert.

Popup service handling everything that has to be managed as popup on something else.

Spinner service take care of all loading pieces.

File service managing file process, from load any type from user to sent it to server.

Socket service handling the sockets management with server and other clients.

Image service take care of everything around pictures on the client side.

Hash service with use of href hash, provide memo sharable points for modals or popups.

Installation:

$ npm i --save wcom

Mongo Service

Mongo Service is an suportive service for combinating AngularJS client with waw CRUD back-end. Example of injecting mongo service:

services.user = function(mongo){}
angular.service('user', function(mongo){});

create function

connecting with waw CRUD create. As parameters accepting name of mongo collection, object with values for document and optionally callback function which will return the document. Document will be filled inside read callbacks. Example:

mongo.create('colName', {
	    name: doc.name
}, function(created) {
	    console.log('document has been created');
});

read function

connecting with waw CRUD read. As parameters accepting name of mongo collection, optionally options, optionally callback which will return all documents in array as first parameter and in object with doc._id placeholder for doc as second parameter. Function returning directing array which will host the documents. Example:

mongo.get('colName',{
	replace: {
		name: function(val, cb, doc){
			cb(val+'_modified')
		}
	},
	name: 'me',
	next: {
		name: 'friends',
		next: {
			name: 'near',
			next: {
				name: 'city',
				next: {
					name: 'country'
				}
			}
		}
	},
	populate: [{
		field: 'author',
		part: 'user'
	}],
	groups: 'city name' || ['city', 'name'] || {
		first_name: {
			field: function(doc, cb){
				if(doc.name.split(' ').length>1) cb(doc.name.split(' ')[1]);
				retun doc.name.split(' ')[0];
			},
			allow: function(doc){
				return !!doc.name;
			},
			ignore: function(){
				return false;
			},
			sort: function(){

			}
		}
	},
	query: {
		male: function(doc){
			return doc.gender;
		},
		female: {
			allow: function(doc){
				return !doc.gender;
			},
			ignore: function(){
				return typeof doc.gender != 'boolean';
			},
			sort: function(a, b){
				if(a.order > b.order) return -1;
				return 1;
			}
		}
	}
}, (arr, obj, name, resp) => {
/*
*	arr will be array with total docs from that part
*	obj will be object with total docs from that part binded by _id
*	groups will be saved into obj in the way: obj.name['Denys'] or obj.city['Kiev']
*	name is the name of current pull from server
*	resp is the array of responsinse with documents queried
*/
})

replace options

work as filler of each doc for cases when we can calculate things to use in website. Good example can be currencies which change each moment, we have product in one currency and we want to show it in different currrencies. Other good example can be date fields, which is saved as string and we need them in new Date() format.

populate options

works in the same way as populate of mongodb but in the client side. This works great when you need documents inside other documents and put on them sorting or other things.

groups options

makings arrays which show different documents inside specific placeholders. As example we can have list of users in specific town or country, so we don't have to create pipes for that.

next options

works as level of pulling different documents from the server. This is mostly made for performance, so user can have the info he needs directly.

updateAll function

connecting with waw CRUD updateAll. As parameters accepting name of mongo collection, document object, optionally options and optionally callback function which will return the document. Example:

mongo.updateAll('colName', {
		name: doc.name,
		_id: doc._id
}, {
		fields: 'name'
}, function() {
		console.log('document is updated');
});

updateUnique function

connecting with waw CRUD updateUnique. As parameters accepting name of mongo collection, object with document _id and field value, optionally options and optionally callback function which will return if field has been updated. Example:

mongo.updateUnique('colName', {
	name: doc.name,
	_id: doc._id
}, {
	name: 'name'
}, function(resp) {
	    if(resp){
	   		console.log('field updated');
		} else {
	   		console.log("field not updated");
		}
});

delete function

connecting with waw CRUD delete. As parameters accepting name of mongo collection, document object, optionally options and optionally callback function which will return the document. Example:

mongo.delete('colName', {
		_id: doc._id
}, {
		name: 'admin'
}, function() {
		console.log('document is updated');
});

_id function

provide new mongo _id. As parameters accepting callback function which will return the _id. Example:

mongo._id(function(_id){
    	console.log(_id);
});

to_id function

convert array of documents, object with documents, mixed documents or _id and converting it to array of _id. Example:

mongo.to_id([{
		_id: '1'
}, '2'
//['1','2']
mongo.to_id({
	'1': true
	'2': false
});
// ['1']

afterWhile function

provide delay on any action, usefull with input and model change. As parameters accepting document, callback and optionally time. Example:

mongo.afterWhile(doc, function() {
    	console.log('text was writen');
}, 2000)

populate function

making population on specific field with specific collection. Example with doc which will have field as document of part provided:

mongo.populate(doc, 'field', 'colName');

on function

accepting array or string of parts and callback which will be called when all parts will be loaded.

mongo.on('user post', function(){
	console.log('user and post part has been loaded');
});

beArr function

checking value if it's array then we keep it and in other case, we replace it with new array. Example where each doc will have data as array:

mongo.get('colName', {
	replace: {
	   	'data': mongo.beArr
    }
});

beObj function

checking value if it's object then we keep it and in other case, we replace it with new object. Example where each doc will have data as array:

mongo.get('colName', {
	replace: {
	   'data': mongo.beObj
    }
});

forceArr function

convert any value to array within replace options. Example where each doc will have data as empty array:

mongo.get('colName', {
	replace: {
	   'data': mongo.forceArr
    }
});

forceObj function

convert any value to object within replace options. Example where each doc will have data as empty object:

mongo.get('colName', {
	replace: {
	   	'data': mongo.forceObj
    }
});

SD Service

Modal Service

The basic service for adding and closing modals. Example where we opening modal from file:

modal.open({
	templateUrl: '/html/modal/file.html',
	name: 'John'
});

Example where we opening modal from HTML code:

modal.open({
	template: '<div>{{name}}</div>',
	name: 'John'
});

Example how to use the object we are passing:

<div>{{name}}</div>

Example where we closing modal inside modal html cope:

<button ng-click="close();">Cancel</button>

Popup Service

Spinner Service

service for adding and closing spinners. Example where we creating spinner:

spinner.open({
	name: 'John'
});

Example where we closing spinner:

spinner.close();

File Service

service can do three functions. Such as, take files from User, load dataUrl of images, and upload file to server. Example where we taking image, loading its dataUrl and uploading to server:

file.add({
	id:'idForLabel',
	width: 500,
	height: 500
}, function(dataUrl) {
	console.log('DataUrl length:', dataUrl.length);
});

Example where we taking any file:

file.add({
	id:'idForLabel'
}, function(file) {
	console.log(file);
});

Socket Service

Image Service

Hash Service

License

MIT