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

moldy-file-adapter

v1.1.1

Published

A file adapter for `Moldy`

Downloads

8

Readme

TOC

moldy-file-adapter

Tell Moldy to use the file adapter.

// Moldy.use( require('moldy-file-adapter') );

create

should create by a property.

var personMoldy = Moldy.extend('person', {
	properties: {
		name: '',
		age: ''
	}
}).create();
personMoldy.name = 'David';
personMoldy.$save(function (_error) {
	personMoldy.name.should.eql('David');
	_done(_error);
});

get

define a JSON schema.

schema = {
	properties: {
		name: 'string',
		friends: [{
			keyless: true,
			properties: {
				name: {
					type: 'string',
					default: ''
				},
				age: {
					type: 'number',
					default: 0
				}
			}
		}]
	}
};

should create a new person so we can get it next.

var personMoldy = Moldy.extend('person', schema).create();
personMoldy.name = 'Mr David';
personMoldy.friends.push({
	name: 'leonie'
});
personMoldy.friends[0].age = ' 33';
personMoldy.friends.push({
	name: 'max'
});
personMoldy.$save(function (_error) {
	newPersonId = personMoldy.id;
	_done(_error);
});

should get by a id from the previous example.

var personMoldy = Moldy.extend('person', schema);
personMoldy.$findOne({
	id: newPersonId
}, function (_error, _david) {
	if (_error) {
		return _done(_error);
	}
	var david = _david;
	david.name.should.eql('Mr David');
	david.friends.should.be.an.Array.and.have.a.lengthOf(2);
	david.friends[0].name.should.equal('leonie');
	david.friends[0].age.should.equal(33);
	david.friends[1].name.should.equal('max');
	david.friends[1].age.should.equal(0);
	david.$destroy(_done);
});

find

should get an array of models.

var personMoldy = Moldy.extend('person', {
	properties: {
		name: 'string',
		age: 'number'
	}
});
personMoldy.$find(function (_error, _people) {
	if (_error) {
		return _done(_error);
	}
	_people.should.be.an.Array;
	_people.length.should.greaterThan(0);
	_people.forEach(function (_person) {
		_person.should.be.a.Moldy;
		_person.should.have.a.property('id');
		_person.should.have.a.property('name');
		_person.should.have.a.property('age');
		Object.keys(_person.$json()).should.have.a.lengthOf(3);
	});
	_done();
});

save

create a schema.

schema = {
	properties: {
		name: 'string',
		age: {
			type: 'number',
			default: 0
		},
		friends: [{
			keyless: true,
			properties: {
				name: {
					type: 'string',
					default: ''
				},
				age: {
					type: 'number',
					default: ''
				}
			}
		}]
	}
};

should save a model.

var personMoldy = Moldy.extend('person', schema);
personMoldy.$findOne(function (_error, _person) {
	if (_error) {
		return _done(_error);
	}
	var person = _person;
	key = person.id;
	person.name = 'Mr David';
	person.friends.push({
		name: 'leonie'
	});
	person.friends.push({
		name: 'max'
	});
	person.friends.push({
		name: 'david'
	});
	person.$save(function (_error) {
		if (_error) {
			return _done(_error);
		}
		var newPersonMoldy = Moldy.extend('person', schema);
		newPersonMoldy.$findOne({
			id: key
		}, function (_error, newPerson) {
			newPerson.id.should.equal(key);
			newPerson.friends.splice(1, 1);
			newPerson.$save(function (_error) {
				if (_error) {
					return _done(_error);
				}
				var newNewPersonMoldy = Moldy.extend('person', schema);
				newNewPersonMoldy.$findOne({
					id: key
				}, function (_error, _newNewPersonMoldy) {
					_newNewPersonMoldy.friends.should.have.a.lengthOf(2);
					_newNewPersonMoldy.friends[1].name.should.equal('david');
					_done();
				});
			});
		});
	});
});

destroy

define a JSON schema.

schema = {
	properties: {
		name: 'string'
	}
};

should destroy all the models.

var personMoldy = Moldy.extend('person', schema);
personMoldy.$find(function (_error, _guys) {
	_guys.length.should.be.greaterThan(0);
	var deleteGuy = function (_guy) {
		personMoldy.$find(function (_error, _guys) {
			if (_guys.length === 0) {
				return _done();
			}
			var guy = Moldy.extend('person', schema);
			guy.$findOne({
				id: _guys[0].id
			}, function (_error, _guy) {
				if (_error) {
					return _done(_error);
				}
				_guy.$destroy(function (_error) {
					if (_error) {
						return _done(_error);
					}
					deleteGuy();
				});
			});
		});
	};
	deleteGuy();
});