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

camlpiler

v1.0.2

Published

A simple library for converting CamlQuery XML syntax into a JS/TS filter function

Downloads

2

Readme

Camlpiler

Overview

Collaborative Application Markup Language (CAML) is an XML-based language used in SharePoint for querying lists, defining views, defining list fields, and other tasks.

Camlpiler is a JavaScript library that will take a CAML query and convert it to a filter function that can be applied to JavaScript objects.

Use Cases

Building a dev API

The primary motivation for creating this library was to make it easier to create a development API that could mimic requests to a SharePoint server. Basically, in a React app deployed to SharePoint, I was using a local store of JavaScript objects to mimic the production store in SharePoint. This was easy to implement for basic operations such as get/save/delete, but ran into a problem when searching/filtering because that required dealing with CAML.

Validating CamlQuery syntax (not ready yet)

SharePoint in general does not give helpful error messages when presented with incorrect Syntax in a CAML query, whether it's malformed XML, a misspelled element name, or any other sort of error. While this is a secondary use case, and not the reason I wrote this library, I do hope that as this library becomes more feature complete that this will become a potential use for it, especially for the case of generated CAML queries.

Getting Started

Installation

Install via npm or yarn using one of the following commands:

npm

npm install camlpiler

yarn

yarn add camlpiler

Usage

Camlpiler is intended to be used when running your project in development mode, for example if you're running an App created with create-react-app using the local development server via the command npm start. In this scenario, camlpiler is intended to replicate the SharePoint CAML parsing functionality.

As a somewhat simplified example, here is a somewhat contrived sample usage in a SharePoint-hosted JavaScript application:

const search = (term: string): Promise<ItemType[]> => {
    const query =
        `<View>
            <Query>
                <Where>
                    <Contains>
                        <FieldRef Name='Title' />
                        <Value Type='Text'>${term}</Value>
                    </Contains>
                </Where>
            </Query>
        </View>`;
    if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
        const camlTester = new CamlTester({});
        return camlTester.testQueryXml(testItems, query);
    } else {
        return promiseBasedSharePointWrapper.search(term);
    }
}