Nodejs

# npm
npm install --save suchjs

# yarn
yarn add suchjs

# pnpm
pnpm add suchjs
1
2
3
4
5
6
7
8
// CMD
const { default: globalSuch, createNsSuch } = require("suchjs");
// ES6 module
import globalSuch, { createNsSuch } from "suchjs";
1
2
3
4

In the nodejs environment, suchjs has the ability to load configuration files, the format of the configuration file can be viewed in API Such.config

Browser

  1. use npm

    • the installation is same as in the 'nodejs'

    • demo:

    // here imported from the path 'suchjs/lib/browser', not 'suchjs'
    import globalSuch, { createNsSuch } from "suchjs/lib/browser";
    
    1
    2
  2. use the CDN or local file

    Copy the dist/such.min.js file (or some other version) in the project to the local or upload to the CDN, use the script tag include to the html page, it will export a global Such object mounted by the window. The window.Such object look like below:

    // the default is a global Such instance, and use `createNsSuch` you will get a namespace instance
    const { default: globalSuch, createNsSuch } = window.Such;
    
    1
    2

    if you use the tool webpack, then you can configure the 'externals':

    // webpack
    module.exports = {
      // externals
      externals: {
        suchjs: "Such",
      },
    };
    
    1
    2
    3
    4
    5
    6
    7

    then used in the javascript code like this:

    import globalSuch, { createNsSuch } from "suchjs";
    
    1