New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mo-convert

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mo-convert

> ### Systematic [Motoko](https://github.com/dfinity/motoko#readme) base library type conversions.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

mo-convert  npm version GitHub license PRs Welcome

Systematic Motoko base library type conversions.


This repository includes Motoko source code and a JSON metadata file containing all base library type conversions with a consistent B.ofA : A -> B naming convention. mo-convert is intended as a stepping stone for community language tooling and for those such as myself who have trouble remembering whether the function was named Array.toBuffer() or Buffer.fromArray().

Quick Start (Motoko):

Add the following to your mops.toml config file:

[dependencies]
convert = "https://github.com/rvanasa/mo-convert"

Include the following import in your Motoko source code:

import C "mo:convert";

Go to town:

let nat = 123;
let text = C.Text.ofNat(nat); // => "123"

let option = C.Option.ofResult(#ok true); // => ?true

let array = [1, 2, 3];
let buffer = C.Buffer.ofArray<Nat>(array);

// Chain conversions with the piping operator
let pipe = (
  array
  |> C.Iter.ofArray _
  |> C.List.ofIter _
  |> C.Array.ofList _
);

Quick Start (Node.js):

Run the following command to install the mo-convert npm package:

npm i --save-dev mo-convert

Access the type conversion metadata:

const { conversions } = require('mo-convert');

console.log('All type conversions:', conversions);

Example JSON entry:

conversions[0] ==
{
  from: "Array",
  to: "Blob",
  module: "Blob",
  name: "fromArray",
  signature: "Blob.fromArray(bytes : [Nat8]) : Blob",
  prim: "arrayToBlob",
}

FAQs

Package last updated on 02 Jan 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc