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

native-calendar-api

v0.5.1

Published

A javascript wrapper with a promise api for using the cordova native calendar plugin

Downloads

2

Readme

#Native Calendar A promise wrapper for Cordova Calendar Plugin

Overall goal is to add an easier workflow to the calendar plugin and add some error checking that doesn't exist in the current plugin.

#Install

npm install --save native-calendar-api

#Example use:

The original api was callbacks and you couldn't call an operation before the last operation had finished. This made handling a large array of events difficult to manage. Using this api you can now do something like:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

function sampleCreateFromArray(events) {
  return events.reduce((curr, next) => {
    return curr.then(() => {
      return CalendarApi.newEvent(next);
    });
  }, P.resolve());
}

sampleCreateFromArray(eventArray)
  .then(() => {
    // execute some cleanup of the events after they have been added
  })
  .catch((err) => {
    YourLogger.log(err);
  });

#Class NativeCalendar

##Properties

  • calendar: a reference to the native plugin
  • errors: a collection of errors from the last execution

##Methods

###setup(titlePrefix, errorPrefix) (should be called after plugin is loaded)

  • args: titlePrefix - A title prefix specific to your application for searching and deleting only events you own. ex 'MyApp-' errorPrefix - An error prefix for logging errors giving you a simple search string to find all errors in the calendar from your logs.

Initiates the calendar and error properties. Will console.warn if window.plugin.calendar doesn't exist

###clearErrors()

Resets the error object. This should be called after the errors have been consumed.

###validDate(date)

  • args date: expected to be a JavaScript date object

  • returns: true or false

###isValid(event) Used internally but can be called direction to valide your event objects

  • args event: expected to be a valid event object with the properties title: String location: String notes: String startDate: Date endDate: Date

  • returns: true or false

When this method is called it will return true if all fields are valid on the event object. If false is returned it will append the errors to the errors property. When used internally the promise will be rejected with the error messages.

###newEvent(event)

  • args event: a valid event object

  • returns: promise

In the case that the event is invalid this will be rejected and return an error object with all the errors. You can then log this output to your production logger such as:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

const invalidEvent = {};
CalendarApi.newEvent(invalidEvent).catch((err) => {
  YourLogger.log(err);
});

###deleteEvent(event)

  • args event: a valid event object

  • returns: promise

In the case that the event is invalid this will be rejected and return an error object with all the errors. You can then log this output to your production logger such as:

import CalendarApi from 'native-calendar-api';
import YourLogger from 'some-lib';

CalendarApi.setup('MyApp-', 'Custom Error Prefix:');

const invalidEvent = {};
CalendarApi.deleteEvent(invalidEvent).catch((err) => {
  YourLogger.log(err);
});

###convertFindEventToDeleteEvent() Meant for internal use but can be used to convert an object returned from a find in the NativeCalendar to a valid event for deletion. This is an issue due to the fact that the plugin returns a string rather than a date object. Be careful using this as it will always return a valid object meaning if you pass it nothing you will get a valid Event back initiated to now with a duration of 0

###convertFindDateToJavaScriptDate(date) Converts a date string returned by the plugin into a valid JavaScript date.

  • args: a date string returned by native calendar find method
  • returns: a JavaScript Date object

###getDefaultBlankObject()

  • returns: an object with all required Event Properties

###asyncCreateEvent(event)

  • args event object
  • returns a promise with the same error pattern mentioned above

###asyncCreateEventWithOptions(event, options)

  • args event object options: optional options object explained in cordova plugin docs
  • returns a promise with the same error pattern mentioned above

###asyncCreateEventInteractively(event)

  • args event object
  • returns a promise with the same error pattern mentioned above

###asyncCreateEventInteractivelyWithOptions(event, options)

  • args event object options: optional options object explained in cordova plugin docs
  • returns a promise with the same error pattern mentioned above

###asyncFindEvent(event)

  • args event object
  • returns a promise with the find result or the same error pattern mentioned above

###asyncDeleteEventById(id)

  • args id: the ID of the event to delete
  • returns a promise with the same error pattern mentioned above

###asyncFindEventWithOptions(event, options)

  • args event object options: optional options object explained in cordova plugin docs
  • returns a promise with the same error pattern mentioned above

###asyncDeleteEvent(event)

  • args event object
  • returns a promise with the same error pattern mentioned above

###asyncListCalendars()

  • returns a promise with the results or erors

###asyncDeleteEventFromNamedCalendar(event, calendarName)

  • args event object calendarName: a string of the calendar's name
  • returns a promise with the same error pattern mentioned above