Socket
Socket
Sign inDemoInstall

jsprim

Package Overview
Dependencies
3
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsprim

utilities for primitive JavaScript types


Version published
Maintainers
1
Install size
2.07 MB
Created

Package description

What is jsprim?

The jsprim package provides utilities for working with primitive JavaScript types. It includes functions for deep copying, testing object types, parsing JSON safely, and more. It's designed to offer a collection of utilities that are commonly needed but not provided by the JavaScript standard library.

What are jsprim's main functionalities?

Deep copying objects

This feature allows you to create a deep copy of an object, ensuring that nested objects are also copied rather than just copying the reference.

var jsprim = require('jsprim');
var obj = { a: 1, b: { c: 2 } };
var copy = jsprim.deepCopy(obj);

Checking if a value is an object

This utility helps in determining whether a given value is an object, which can be particularly useful for validation and type checking.

var jsprim = require('jsprim');
var result = jsprim.isObject({}); // true
result = jsprim.isObject(123); // false

Parsing JSON safely

Safely parse a JSON string, catching any errors that occur during parsing and returning `null` instead of throwing an exception.

var jsprim = require('jsprim');
var str = '{ "key": "value" }';
var obj = jsprim.parseJSON(str);

Other packages similar to jsprim

Readme

Source

jsprim: utilities for primitive JavaScript types

This module provides miscellaneous facilities for working with strings, numbers, dates, and objects and arrays of these basic types.

deepCopy(obj)

Creates a deep copy of a primitive type, object, or array of primitive types.

isEmpty(obj)

Returns true if the given object has no properties and false otherwise. This is O(1) (unlike Object.keys(obj).length === 0, which is O(N)).

forEachKey(obj, callback)

Like Array.forEach, but iterates properties of an object rather than elements of an array. Equivalent to:

for (var key in obj)
        callback(key, obj[key]);

startsWith(str, prefix)

Returns true if the given string starts with the given prefix and false otherwise.

endsWith(str, suffix)

Returns true if the given string ends with the given suffix and false otherwise.

iso8601(date)

Converts a Date object to an ISO8601 date string of the form "YYYY-MM-DDTHH:MM:SS.sssZ". This format is not customizable.

validateJsonObject(schema, object)

Uses JSON validation (via JSV) to validate the given object against the given schema. On success, returns null. On failure, returns (does not throw) a useful Error object.

FAQs

Last updated on 08 Jun 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc