@dfinity/utils
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
"use strict";var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of T(e))!d.call(t,n)&&n!==o&&i(t,n,{get:()=>e[n],enumerable:!(p=f(e,n))||p.enumerable});return t};var x=t=>l(i({},"__esModule",{value:!0}),t);var y={};m(y,{NullishError:()=>s,assertNonNullish:()=>a,defaultAgent:()=>g,fromNullable:()=>u,toNullable:()=>c});module.exports=x(y);var r=require("@dfinity/agent"),g=()=>new r.HttpAgent({host:"https://ic0.app",identity:new r.AnonymousIdentity});var s=class extends Error{},a=(t,e)=>{if(t==null)throw new s(e)};var c=t=>t?[t]:[],u=t=>t==null?void 0:t[0];0&&(module.exports={NullishError,assertNonNullish,defaultAgent,fromNullable,toNullable}); | ||
"use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of A(e))!g.call(t,r)&&r!==o&&p(t,r,{get:()=>e[r],enumerable:!(n=y(e,r))||n.enumerable});return t};var I=t=>b(p({},"__esModule",{value:!0}),t);var C={};x(C,{NullishError:()=>s,assertNonNullish:()=>m,createServices:()=>N,defaultAgent:()=>a,fromDefinedNullable:()=>O,fromNullable:()=>d,toNullable:()=>S});module.exports=I(C);var f=require("@dfinity/agent");var i=require("@dfinity/agent"),a=()=>new i.HttpAgent({host:"https://ic0.app",identity:new i.AnonymousIdentity});var N=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:o,agent:n},idlFactory:r,certifiedIdlFactory:l})=>{let c=n??a(),T=e??f.Actor.createActor(r,{agent:c,canisterId:t}),u=o??f.Actor.createActor(l,{agent:c,canisterId:t});return{service:T,certifiedService:u,agent:c,canisterId:t}};var s=class extends Error{},m=(t,e)=>{if(t==null)throw new s(e)};var S=t=>t?[t]:[],d=t=>t==null?void 0:t[0],O=t=>{let e=d(t);return m(e),e};0&&(module.exports={NullishError,assertNonNullish,createServices,defaultAgent,fromDefinedNullable,fromNullable,toNullable}); | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import{AnonymousIdentity as o,HttpAgent as r}from"@dfinity/agent";var i=()=>new r({host:"https://ic0.app",identity:new o});var e=class extends Error{},l=(t,n)=>{if(t==null)throw new e(n)};var T=t=>t?[t]:[],a=t=>t?.[0];export{e as NullishError,l as assertNonNullish,i as defaultAgent,a as fromNullable,T as toNullable}; | ||
import{Actor as i}from"@dfinity/agent";import{AnonymousIdentity as d,HttpAgent as T}from"@dfinity/agent";var n=()=>new T({host:"https://ic0.app",identity:new d});var b=({options:{canisterId:t,serviceOverride:e,certifiedServiceOverride:c,agent:p},idlFactory:a,certifiedIdlFactory:f})=>{let r=p??n(),l=e??i.createActor(a,{agent:r,canisterId:t}),m=c??i.createActor(f,{agent:r,canisterId:t});return{service:l,certifiedService:m,agent:r,canisterId:t}};var o=class extends Error{},s=(t,e)=>{if(t==null)throw new o(e)};var O=t=>t?[t]:[],u=t=>t?.[0],v=t=>{let e=u(t);return s(e),e};export{o as NullishError,s as assertNonNullish,b as createServices,n as defaultAgent,v as fromDefinedNullable,u as fromNullable,O as toNullable}; | ||
//# sourceMappingURL=index.js.map |
@@ -0,3 +1,5 @@ | ||
export type { CanisterOptions } from "./types/canister.options"; | ||
export * from "./utils/actor.utils"; | ||
export * from "./utils/agent.utils"; | ||
export * from "./utils/asserts.utils"; | ||
export * from "./utils/did.utils"; |
export declare const toNullable: <T>(value?: T | undefined) => [] | [T]; | ||
export declare const fromNullable: <T>(value: [] | [T]) => T | undefined; | ||
export declare const fromDefinedNullable: <T>(value: [] | [T]) => T; |
{ | ||
"name": "@dfinity/utils", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A collection of utilities and constants for NNS/SNS projects.", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
# utils-js | ||
A collection of utilities and constants for NNS/SNS projects. | ||
[![npm version](https://img.shields.io/npm/v/@dfinity/utils.svg?logo=npm)](https://www.npmjs.com/package/@dfinity/utils) [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
## Table of contents | ||
- [Installation](#installation) | ||
- [Features](#features) | ||
## Installation | ||
You can use `utils-js` by installing it in your project. | ||
```bash | ||
npm i @dfinity/utils | ||
``` | ||
The bundle needs peer dependencies, be sure that following resources are available in your project as well. | ||
```bash | ||
npm i @dfinity/agent @dfinity/candid @dfinity/principal | ||
``` | ||
## Features | ||
`utils-js` implements following features: | ||
<!-- TSDOC_START --> | ||
### :toolbox: Functions | ||
- [defaultAgent](#gear-defaultagent) | ||
- [createServices](#gear-createservices) | ||
- [assertNonNullish](#gear-assertnonnullish) | ||
- [toNullable](#gear-tonullable) | ||
- [fromNullable](#gear-fromnullable) | ||
- [fromDefinedNullable](#gear-fromdefinednullable) | ||
#### :gear: defaultAgent | ||
| Function | Type | | ||
| -------------- | ------------- | | ||
| `defaultAgent` | `() => Agent` | | ||
#### :gear: createServices | ||
| Function | Type | | ||
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `createServices` | `<T>({ options: { canisterId, serviceOverride, certifiedServiceOverride, agent: agentOption, }, idlFactory, certifiedIdlFactory, }: { options: RequiredCanisterOptions<T>; idlFactory: InterfaceFactory; certifiedIdlFactory: InterfaceFactory; }) => { ...; }` | | ||
#### :gear: assertNonNullish | ||
| Function | Type | | ||
| ------------------ | -------------------------------------------------------------------- | | ||
| `assertNonNullish` | `<T>(value: T, message?: string) => asserts value is NonNullable<T>` | | ||
#### :gear: toNullable | ||
| Function | Type | | ||
| ------------ | ----------------------------- | | ||
| `toNullable` | `<T>(value?: T) => [] or [T]` | | ||
#### :gear: fromNullable | ||
| Function | Type | | ||
| -------------- | ---------------------------- | | ||
| `fromNullable` | `<T>(value: [] or [T]) => T` | | ||
#### :gear: fromDefinedNullable | ||
| Function | Type | | ||
| --------------------- | ---------------------------- | | ||
| `fromDefinedNullable` | `<T>(value: [] or [T]) => T` | | ||
### :factory: NullishError | ||
#### Constructors | ||
`public` | ||
Parameters: | ||
- `message` | ||
<!-- TSDOC_END --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
26397
15
50
88