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

iced-handler

v1.0.7

Published

handle req very easily

Downloads

9

Readme

iced-handler

handle ( index, create, getEdit, postEdit, delete ) regustes very easily for express apps

install

npm i iced-handler

how to use ?

1- import ICED

const ICED = require('iced-handler')

2- import your Model

const Post = require('./models/post')

or you can sent your models directory. but in models dir must be somthing like this :

/models/index.js:

// you must do this for all of you models
exports.Post = require('./post')

and then insted of using model object in next step you cant just use model Sting name like this :index(req , "Post")

ICED.modelsPath = '/models'

3- use it in controller index(req , <model name , model object>)return the pageinated object of model

app.get('/' ,async (req, res) => {
    res.json(await ICED.index(req , Post))
})

if your requst is somthig that need to gave data you can use this way:

make data structure list it list items can be String or Object

if it was String ICED will put req.body[<your Str>]

if it was Object ICED will use exptions that can create by your self. exptions are functions thay return somthig and that returned thing will put in data that is going to save

Oject must be like this:{<key> : <value> , args: [<exptions argument>]} value can be exptions or can be anonymous function

Define exptions

ICED.exptions.<exptions name> = (req , args) => {
    // do staff
    return data
}
app.post('/posts' ,async (req, res) => {

    const dataStructure = [
        "title", // title : req.body.title
        { 'slug': "slug", args: ["title"] }, // create slug from title
        { 'user': "curent_user" }, // get curent user with exptions
        {'tag' : () => {
            let tag
            // do staff
            return tag
        }} // put tag var in data
    ]

    res.json(await ICED.postCreate(req , Post , dataStructure))
})

full example of using ICED :

project structure:

/app
    /models
        post.js
        product.js
        indes.js
    index.js

/app/indes.js :

const express = require("express");
const app = express();
const mongoose = require("mongoose");
const ICED = require("iced-handler");

// connect to database
mongoose.connect("mongodb://localhost:27017/test").then((result) => {
  app.listen(3000);
});

ICED.modelsPath = "/models";

ICED.exptions.curent_user = (req) => {
    let user
    // get curent user
  return user.id;
};

// data struture of Post that you want to save
app.get("/", async (req, res) => {
  res.send(await ICED.index(req, "Post"));
});

app.get("/create", async (req, res) => {

    const data = [
  "title",
  { 'slug': "slug", args: ["title"] },
  { 'user': "curent_user" },
  {'tag' : () => {
    let tag
    // do staff
    return tag
  }}
];

  res.send(await ICED.postCreate(req, "Post", data));
});

/app/models/index.js:

exports.Post = require('./post')
exports.Product = require('./product')

/app/models/post.js:

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const postSchema = new Schema({
    title: {
        type: String
    },
    slug: {
        type: String
    },
    user:{
        type: String
    },
    tag:{
        type: String
    }
})

module.exports = mongoose.model('Post', postSchema)