Merge es6 into master
This commit is contained in:
commit
40b524cd08
46 changed files with 3440 additions and 5941 deletions
388
.gitignore
vendored
388
.gitignore
vendored
|
@ -1,386 +1,4 @@
|
||||||
### SublimeText template
|
.DS_Store
|
||||||
|
node_modules
|
||||||
# cache files for sublime text
|
package-lock.json
|
||||||
*.tmlanguage.cache
|
|
||||||
*.tmPreferences.cache
|
|
||||||
*.stTheme.cache
|
|
||||||
|
|
||||||
# workspace files are user-specific
|
|
||||||
*.sublime-workspace
|
|
||||||
|
|
||||||
# project files should be checked into the repository, unless a significant
|
|
||||||
# proportion of contributors will probably not be using SublimeText
|
|
||||||
# *.sublime-project
|
|
||||||
|
|
||||||
# sftp configuration file
|
|
||||||
sftp-config.json
|
|
||||||
|
|
||||||
# Package control specific files
|
|
||||||
Package Control.last-run
|
|
||||||
Package Control.ca-list
|
|
||||||
Package Control.ca-bundle
|
|
||||||
Package Control.system-ca-bundle
|
|
||||||
Package Control.cache/
|
|
||||||
Package Control.ca-certs/
|
|
||||||
Package Control.merged-ca-bundle
|
|
||||||
Package Control.user-ca-bundle
|
|
||||||
oscrypto-ca-bundle.crt
|
|
||||||
bh_unicode_properties.cache
|
|
||||||
|
|
||||||
# Sublime-github package stores a github token in this file
|
|
||||||
# https://packagecontrol.io/packages/sublime-github
|
|
||||||
GitHub.sublime-settings
|
|
||||||
|
|
||||||
### macOS template
|
|
||||||
|
|
||||||
*.DS_Store
|
|
||||||
.AppleDouble
|
|
||||||
.LSOverride
|
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
# Thumbnails
|
|
||||||
._*
|
|
||||||
|
|
||||||
# Files that might appear in the root of a volume
|
|
||||||
.DocumentRevisions-V100
|
|
||||||
.fseventsd
|
|
||||||
.Spotlight-V100
|
|
||||||
.TemporaryItems
|
|
||||||
.Trashes
|
|
||||||
.VolumeIcon.icns
|
|
||||||
.com.apple.timemachine.donotpresent
|
|
||||||
|
|
||||||
# Directories potentially created on remote AFP share
|
|
||||||
.AppleDB
|
|
||||||
.AppleDesktop
|
|
||||||
Network Trash Folder
|
|
||||||
Temporary Items
|
|
||||||
.apdisk
|
|
||||||
|
|
||||||
### Linux template
|
|
||||||
|
|
||||||
*~
|
|
||||||
|
|
||||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
||||||
.fuse_hidden*
|
|
||||||
|
|
||||||
# KDE directory preferences
|
|
||||||
.directory
|
|
||||||
|
|
||||||
# Linux trash folder which might appear on any partition or disk
|
|
||||||
.Trash-*
|
|
||||||
|
|
||||||
# .nfs files are created when an open file is removed but is still being accessed
|
|
||||||
.nfs*
|
|
||||||
|
|
||||||
### Windows template
|
|
||||||
|
|
||||||
# Windows thumbnail cache files
|
|
||||||
Thumbs.db
|
|
||||||
ehthumbs.db
|
|
||||||
ehthumbs_vista.db
|
|
||||||
|
|
||||||
# Folder config file
|
|
||||||
Desktop.ini
|
|
||||||
|
|
||||||
# Recycle Bin used on file shares
|
|
||||||
$RECYCLE.BIN/
|
|
||||||
|
|
||||||
# Windows Installer files
|
|
||||||
*.cab
|
|
||||||
*.msi
|
|
||||||
*.msm
|
|
||||||
*.msp
|
|
||||||
|
|
||||||
# Windows shortcuts
|
|
||||||
*.lnk
|
|
||||||
|
|
||||||
### CVS template
|
|
||||||
|
|
||||||
/CVS/*
|
|
||||||
**/CVS/*
|
|
||||||
.cvsignore
|
|
||||||
*/.cvsignore
|
|
||||||
|
|
||||||
### Emacs template
|
|
||||||
|
|
||||||
# -*- mode: gitignore; -*-
|
|
||||||
*~
|
|
||||||
\#*\#
|
|
||||||
/.emacs.desktop
|
|
||||||
/.emacs.desktop.lock
|
|
||||||
*.elc
|
|
||||||
auto-save-list
|
|
||||||
tramp
|
|
||||||
.\#*
|
|
||||||
|
|
||||||
# Org-mode
|
|
||||||
.org-id-locations
|
|
||||||
*_archive
|
|
||||||
|
|
||||||
# flymake-mode
|
|
||||||
*_flymake.*
|
|
||||||
|
|
||||||
# eshell files
|
|
||||||
/eshell/history
|
|
||||||
/eshell/lastdir
|
|
||||||
|
|
||||||
# elpa packages
|
|
||||||
/elpa/
|
|
||||||
|
|
||||||
# reftex files
|
|
||||||
*.rel
|
|
||||||
|
|
||||||
# AUCTeX auto folder
|
|
||||||
/auto/
|
|
||||||
|
|
||||||
# cask packages
|
|
||||||
.cask/
|
|
||||||
dist/
|
|
||||||
|
|
||||||
# Flycheck
|
|
||||||
flycheck_*.el
|
|
||||||
|
|
||||||
# server auth directory
|
|
||||||
/server/
|
|
||||||
|
|
||||||
# projectiles files
|
|
||||||
.projectile
|
|
||||||
|
|
||||||
# directory configuration
|
|
||||||
.dir-locals.el
|
|
||||||
|
|
||||||
### NetBeans template
|
|
||||||
|
|
||||||
nbproject/private/
|
|
||||||
build/
|
|
||||||
nbbuild/
|
|
||||||
dist/
|
|
||||||
nbdist/
|
|
||||||
.nb-gradle/
|
|
||||||
|
|
||||||
### Eclipse template
|
|
||||||
|
|
||||||
.metadata
|
|
||||||
bin/
|
|
||||||
tmp/
|
|
||||||
*.tmp
|
|
||||||
*.bak
|
|
||||||
*.swp
|
|
||||||
*~.nib
|
|
||||||
local.properties
|
|
||||||
.settings/
|
|
||||||
.loadpath
|
|
||||||
.recommenders
|
|
||||||
|
|
||||||
# Eclipse Core
|
|
||||||
.project
|
|
||||||
|
|
||||||
# External tool builders
|
|
||||||
.externalToolBuilders/
|
|
||||||
|
|
||||||
# Locally stored "Eclipse launch configurations"
|
|
||||||
*.launch
|
|
||||||
|
|
||||||
# PyDev specific (Python IDE for Eclipse)
|
|
||||||
*.pydevproject
|
|
||||||
|
|
||||||
# CDT-specific (C/C++ Development Tooling)
|
|
||||||
.cproject
|
|
||||||
|
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
|
||||||
.classpath
|
|
||||||
|
|
||||||
# Java annotation processor (APT)
|
|
||||||
.factorypath
|
|
||||||
|
|
||||||
# PDT-specific (PHP Development Tools)
|
|
||||||
.buildpath
|
|
||||||
|
|
||||||
# sbteclipse plugin
|
|
||||||
.target
|
|
||||||
|
|
||||||
# Tern plugin
|
|
||||||
.tern-project
|
|
||||||
|
|
||||||
# TeXlipse plugin
|
|
||||||
.texlipse
|
|
||||||
|
|
||||||
# STS (Spring Tool Suite)
|
|
||||||
.springBeans
|
|
||||||
|
|
||||||
# Code Recommenders
|
|
||||||
.recommenders/
|
|
||||||
|
|
||||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
|
||||||
.cache-main
|
|
||||||
.scala_dependencies
|
|
||||||
.worksheet
|
|
||||||
|
|
||||||
### JetBrains template
|
|
||||||
|
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff:
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/dictionaries
|
|
||||||
|
|
||||||
# Sensitive or high-churn files:
|
|
||||||
.idea/**/dataSources/
|
|
||||||
.idea/**/dataSources.ids
|
|
||||||
.idea/**/dataSources.xml
|
|
||||||
.idea/**/dataSources.local.xml
|
|
||||||
.idea/**/sqlDataSources.xml
|
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
|
|
||||||
# Gradle:
|
|
||||||
.idea/**/gradle.xml
|
|
||||||
.idea/**/libraries
|
|
||||||
|
|
||||||
# Mongo Explorer plugin:
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
## File-based project format:
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
## Plugin-specific files:
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
/out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
### Xcode template
|
|
||||||
|
|
||||||
# Xcode
|
|
||||||
#
|
|
||||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
|
||||||
|
|
||||||
## Build generated
|
|
||||||
build/
|
|
||||||
DerivedData/
|
|
||||||
|
|
||||||
## Various settings
|
|
||||||
*.pbxuser
|
|
||||||
!default.pbxuser
|
|
||||||
*.mode1v3
|
|
||||||
!default.mode1v3
|
|
||||||
*.mode2v3
|
|
||||||
!default.mode2v3
|
|
||||||
*.perspectivev3
|
|
||||||
!default.perspectivev3
|
|
||||||
xcuserdata/
|
|
||||||
|
|
||||||
## Other
|
|
||||||
*.moved-aside
|
|
||||||
*.xccheckout
|
|
||||||
*.xcscmblueprint
|
|
||||||
|
|
||||||
### Vim template
|
|
||||||
|
|
||||||
# swap
|
|
||||||
[._]*.s[a-v][a-z]
|
|
||||||
[._]*.sw[a-p]
|
|
||||||
[._]s[a-v][a-z]
|
|
||||||
[._]sw[a-p]
|
|
||||||
# session
|
|
||||||
Session.vim
|
|
||||||
# temporary
|
|
||||||
.netrwhist
|
|
||||||
*~
|
|
||||||
# auto-generated tag files
|
|
||||||
tags
|
|
||||||
|
|
||||||
### Mercurial template
|
|
||||||
|
|
||||||
.hg/
|
|
||||||
.hgignore
|
|
||||||
.hgsigs
|
|
||||||
.hgsub
|
|
||||||
.hgsubstate
|
|
||||||
.hgtags
|
|
||||||
|
|
||||||
### Node template
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
tests/coverage
|
tests/coverage
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Typescript v1 declaration files
|
|
||||||
typings/
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variables file
|
|
||||||
.env
|
|
||||||
|
|
||||||
### Notepad++ template
|
|
||||||
|
|
||||||
# Notepad++ backups #
|
|
||||||
*.bak
|
|
||||||
|
|
||||||
# WebBrains project files
|
|
||||||
.idea/
|
|
||||||
|
|
22
.jshintrc
22
.jshintrc
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"curly": true,
|
|
||||||
"eqeqeq": true,
|
|
||||||
"immed": true,
|
|
||||||
"latedef": "nofunc",
|
|
||||||
"newcap": true,
|
|
||||||
"noarg": true,
|
|
||||||
"sub": true,
|
|
||||||
"undef": true,
|
|
||||||
"unused": true,
|
|
||||||
"boss": true,
|
|
||||||
"eqnull": true,
|
|
||||||
"node": true,
|
|
||||||
"maxerr": 2000,
|
|
||||||
"esversion": 6,
|
|
||||||
"undef": true,
|
|
||||||
"unused": true,
|
|
||||||
"globals": {
|
|
||||||
"random": true,
|
|
||||||
"make": true
|
|
||||||
}
|
|
||||||
}
|
|
49
README.md
49
README.md
|
@ -8,9 +8,9 @@ A unified shared library which aids in building fuzzers for browsers or as compl
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide"></a>
|
<a href="https://standardjs.com"><img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide"></a>
|
||||||
<a href="https://travis-ci.org/MozillaSecurity/octo"><img src="https://api.travis-ci.org/MozillaSecurity/octo.svg?branch=master" alt="Build Status"></a>
|
<!--<a href="https://travis-ci.org/MozillaSecurity/octo"><img src="https://api.travis-ci.org/MozillaSecurity/octo.svg?branch=es6" alt="Build Status"></a>-->
|
||||||
<a href="https://img.shields.io/github/release/mozillasecurity/octo.svg"><img src="https://img.shields.io/github/release/mozillasecurity/octo.svg" alt="Current Release"></a>
|
<!--<a href="https://img.shields.io/github/release/mozillasecurity/octo.svg"><img src="https://img.shields.io/github/release/mozillasecurity/octo.svg" alt="Current Release"></a>-->
|
||||||
<a href="https://coveralls.io/github/MozillaSecurity/octo?branch=master"><img src="https://coveralls.io/repos/github/MozillaSecurity/octo/badge.svg?branch=master" alt="Coverage Status"></a>
|
<!--<a href="https://coveralls.io/github/MozillaSecurity/octo?branch=es6"><img src="https://coveralls.io/repos/github/MozillaSecurity/octo/badge.svg?branch=es6" alt="Coverage Status"></a>-->
|
||||||
<a href="https://www.irccloud.com/invite?channel=%23fuzzing&hostname=irc.mozilla.org&port=6697&ssl=1"><img src="https://img.shields.io/badge/IRC-%23fuzzing-1e72ff.svg?style=flat" alt="IRC"></a>
|
<a href="https://www.irccloud.com/invite?channel=%23fuzzing&hostname=irc.mozilla.org&port=6697&ssl=1"><img src="https://img.shields.io/badge/IRC-%23fuzzing-1e72ff.svg?style=flat" alt="IRC"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -18,35 +18,44 @@ Octo.js bundles core functions and generic boilerplate code commonly used in mos
|
||||||
|
|
||||||
Octo's future aims to be a stable, well-tested and well-documented standard library for fuzzing in a JavaScript environment.
|
Octo's future aims to be a stable, well-tested and well-documented standard library for fuzzing in a JavaScript environment.
|
||||||
|
|
||||||
|
## Note
|
||||||
# NOTE
|
The ES6 branch is under active development while we are incorporating it with our existing fuzzers.
|
||||||
The <a href="https://github.com/MozillaSecurity/octo/tree/es6">ES6</a> branch is under active development while we are incorporating it into our existing fuzzers.
|
|
||||||
This branch is current not maintained.
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Playbook
|
||||||
|
|
||||||
```html
|
https://runkit.com/posidron/octo-js-playbook
|
||||||
<!-- Latest -->
|
|
||||||
https://mozillasecurity.github.io/octo/octo.js
|
|
||||||
|
## Node
|
||||||
|
|
||||||
```
|
```
|
||||||
|
npm i @mozillasecurity/octo
|
||||||
```html
|
|
||||||
<!-- Release -->
|
|
||||||
https://github.com/mozillasecurity/octo/releases/download/0.0.3/octo.js
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```html
|
|
||||||
<!-- Release -->
|
|
||||||
https://cdn.jsdelivr.net/gh/MozillaSecurity/octo@0.0.3/deploy/octo.js
|
|
||||||
```
|
```
|
||||||
|
const {random} = require('@mozillasecurity/octo')
|
||||||
|
random.init()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Browser
|
||||||
|
|
||||||
|
We have not yet merged ES6 to master, hence the browser version which was released on master is not up-to-date.
|
||||||
|
Use the `dist/octo.js` version of this branch by running the following command.
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
|
npm run watch
|
||||||
|
npm run test:lint
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
@ -57,7 +66,5 @@ The automated tests are run in Firefox or Chrome using [Karma](https://karma-run
|
||||||
To run the automated tests:
|
To run the automated tests:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm test
|
||||||
CHROME_BIN=chromium npm test
|
|
||||||
```
|
```
|
||||||
When adding new files, add them in `index.html` and `karma.conf.js` so they can be tested and included in coverage reports.
|
|
||||||
|
|
64
build.py
64
build.py
|
@ -1,64 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# coding=utf-8
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
|
|
||||||
# List of files which must be loaded first
|
|
||||||
PRELOAD = (
|
|
||||||
'random/random.js',
|
|
||||||
'random/mersennetwister.js',
|
|
||||||
'utils/init.js',
|
|
||||||
'utils/platform.js',
|
|
||||||
'logging/console.js',
|
|
||||||
'make/init.js'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def argparser():
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('-l', '--libs', required=True,
|
|
||||||
help='Directory containing the octo libraries.')
|
|
||||||
parser.add_argument('-d', '--deploy', required=True,
|
|
||||||
help='Directory where the combined octo library will be built.')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if not os.path.isdir(args.libs):
|
|
||||||
parser.error("Lib directory doesn't exist!")
|
|
||||||
if not os.path.isdir(args.deploy):
|
|
||||||
parser.error("Deploy directory doesn't exist!")
|
|
||||||
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
args = argparser()
|
|
||||||
|
|
||||||
data = []
|
|
||||||
loaded = set()
|
|
||||||
|
|
||||||
for filename in PRELOAD:
|
|
||||||
path = os.path.join(args.libs, filename)
|
|
||||||
if not os.path.isfile(path):
|
|
||||||
raise Exception("Unable to find file in preload: {0}".format(path))
|
|
||||||
print("Adding path: {0}".format(path))
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
data.append(f.read())
|
|
||||||
loaded.add(path)
|
|
||||||
|
|
||||||
for root, _, files in os.walk(args.libs):
|
|
||||||
for filename in files:
|
|
||||||
path = os.path.join(root, filename)
|
|
||||||
if path.endswith('.js') and path not in loaded:
|
|
||||||
print("Adding path: {0}".format(path))
|
|
||||||
with open(path, 'rb') as f:
|
|
||||||
data.append(f.read())
|
|
||||||
|
|
||||||
octo_path = os.path.join(args.deploy, 'octo.js')
|
|
||||||
with open(octo_path, 'wb') as f:
|
|
||||||
f.write(b'\n\n'.join(data))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
3163
deploy/octo.js
3163
deploy/octo.js
File diff suppressed because one or more lines are too long
1
index.js
Normal file
1
index.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
module.exports = require('./lib/')
|
11
lib/index.js
Normal file
11
lib/index.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
const logger = require('./logging')
|
||||||
|
const make = require('./make')
|
||||||
|
const random = require('./random')
|
||||||
|
const utils = require('./utils')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
logger,
|
||||||
|
random,
|
||||||
|
make,
|
||||||
|
utils
|
||||||
|
}
|
|
@ -1,93 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
var websocket = null
|
|
||||||
|
|
||||||
var logger = (function () { // eslint-disable-line no-unused-vars
|
|
||||||
const sep = '\n/* ### NEXT TESTCASE ############################## */'
|
|
||||||
const color = {
|
|
||||||
red: '\u{1b}[1;31m',
|
|
||||||
green: '\u{1b}[1;32m',
|
|
||||||
clear: '\u{1b}[0m'
|
|
||||||
}
|
|
||||||
if (utils.platform.isWindows) {
|
|
||||||
color.red = ''
|
|
||||||
color.green = ''
|
|
||||||
color.clear = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
function console (msg) {
|
|
||||||
if (websocket) {
|
|
||||||
websocket.send(msg)
|
|
||||||
}
|
|
||||||
if (typeof window === 'undefined') {
|
|
||||||
print(msg) // eslint-disable-line no-undef
|
|
||||||
} else if (window.dump) {
|
|
||||||
window.dump(msg)
|
|
||||||
} else if (window.console && window.console.log) {
|
|
||||||
window.console.log(msg)
|
|
||||||
} else {
|
|
||||||
throw new Error('Unable to run console logger.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function dump (msg) {
|
|
||||||
console(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
function dumpln (msg) {
|
|
||||||
dump(msg + '\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
function log (msg) {
|
|
||||||
dumpln('/*L*/ ' + utils.script.safely(msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
function info (msg) {
|
|
||||||
dumpln('/*L*/ /* ' + msg + ' */')
|
|
||||||
}
|
|
||||||
|
|
||||||
function error (msg) {
|
|
||||||
dumpln(color.red + msg + color.clear)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ok (msg) { // eslint-disable-line no-unused-vars
|
|
||||||
dumpln(color.green + msg + color.green)
|
|
||||||
}
|
|
||||||
|
|
||||||
function JSError (msg) {
|
|
||||||
error('/* ERROR: ' + msg + ' */')
|
|
||||||
}
|
|
||||||
|
|
||||||
function comment (msg) {
|
|
||||||
dumpln('/*L*/ // ' + msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
function separator () {
|
|
||||||
dumpln(color.green + sep + color.clear)
|
|
||||||
}
|
|
||||||
|
|
||||||
function traceback () {
|
|
||||||
error('===[ Traceback ]')
|
|
||||||
try {
|
|
||||||
throw new Error()
|
|
||||||
} catch (e) {
|
|
||||||
dump(e.stack || e.stacktrace || '')
|
|
||||||
}
|
|
||||||
error('================')
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
console: console,
|
|
||||||
dump: dump,
|
|
||||||
log: log,
|
|
||||||
info: info,
|
|
||||||
error: error,
|
|
||||||
JSError: JSError,
|
|
||||||
dumpln: dumpln,
|
|
||||||
comment: comment,
|
|
||||||
separator: separator,
|
|
||||||
traceback: traceback
|
|
||||||
}
|
|
||||||
})()
|
|
87
lib/logging/index.js
Normal file
87
lib/logging/index.js
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
const utils = require('../utils')
|
||||||
|
|
||||||
|
let websocket = null
|
||||||
|
|
||||||
|
const sep = '\n/* ### NEXT TESTCASE ############################## */'
|
||||||
|
const color = {
|
||||||
|
red: '\u{1b}[1;31m',
|
||||||
|
green: '\u{1b}[1;32m',
|
||||||
|
clear: '\u{1b}[0m'
|
||||||
|
}
|
||||||
|
if (utils.platform.name.isWindows) {
|
||||||
|
color.red = ''
|
||||||
|
color.green = ''
|
||||||
|
color.clear = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
class logger {
|
||||||
|
static console (msg) {
|
||||||
|
if (websocket) {
|
||||||
|
websocket.send(msg)
|
||||||
|
}
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
try {
|
||||||
|
print(msg) // eslint-disable-line no-undef
|
||||||
|
} catch (e) {
|
||||||
|
console.log(msg)
|
||||||
|
}
|
||||||
|
} else if (window.dump) {
|
||||||
|
dump(msg) // eslint-disable-line no-undef
|
||||||
|
} else if (window.console && window.console.log) {
|
||||||
|
console.log(msg)
|
||||||
|
} else {
|
||||||
|
throw new Error('Unable to run console logger.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static dump (msg) {
|
||||||
|
this.console(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
static dumpln (msg) {
|
||||||
|
this.dump(`${msg}\n`)
|
||||||
|
}
|
||||||
|
|
||||||
|
static log (msg) {
|
||||||
|
this.dumpln(`/*L*/ ${utils.script.safely(msg)}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
static info (msg) {
|
||||||
|
this.dumpln(`/*L*/ /* ${msg} */`)
|
||||||
|
}
|
||||||
|
|
||||||
|
static error (msg) {
|
||||||
|
this.dumpln(color.red + msg + color.clear)
|
||||||
|
}
|
||||||
|
|
||||||
|
static ok (msg) { // eslint-disable-line no-unused-vars
|
||||||
|
this.dumpln(color.green + msg + color.green)
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSError (msg) {
|
||||||
|
this.error(`/* ERROR: ${msg} */`)
|
||||||
|
}
|
||||||
|
|
||||||
|
static comment (msg) {
|
||||||
|
this.dumpln(`/*L*/ // ${msg}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
static separator () {
|
||||||
|
this.dumpln(color.green + sep + color.clear)
|
||||||
|
}
|
||||||
|
|
||||||
|
static traceback () {
|
||||||
|
this.error('===[ Traceback ] ===')
|
||||||
|
try {
|
||||||
|
throw new Error()
|
||||||
|
} catch (e) {
|
||||||
|
this.dump(e.stack || e.stacktrace || '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = logger
|
|
@ -2,17 +2,21 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.alignment = {
|
const make = require('../make')
|
||||||
horizontal: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class alignment extends make {
|
||||||
|
static horizontal () {
|
||||||
return random.item(['left', 'right', 'justify', 'center'])
|
return random.item(['left', 'right', 'justify', 'center'])
|
||||||
},
|
}
|
||||||
vertical: function () {
|
|
||||||
|
static vertical () {
|
||||||
return random.item(['top', 'bottom', 'middle', 'baseline'])
|
return random.item(['top', 'bottom', 'middle', 'baseline'])
|
||||||
},
|
}
|
||||||
any: function () {
|
|
||||||
return random.pick([
|
static any () {
|
||||||
this.horizontal,
|
return random.pick([this.horizontal, this.vertical])
|
||||||
this.vertical
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = alignment
|
||||||
|
|
|
@ -2,14 +2,22 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.arrays = {
|
const make = require('../make')
|
||||||
filledArray: function (fn, limit) {
|
const random = require('../random')
|
||||||
let array = []
|
|
||||||
let size = limit || random.number(make.number.tiny()) + 1
|
|
||||||
|
|
||||||
for (let i = 0; i < size; i++) {
|
class arrays extends make {
|
||||||
let value = random.pick(fn)
|
/**
|
||||||
if (value !== undefined) {
|
* Returns an array containing random values generated by the supplied function
|
||||||
|
* @param {Function} fn - Function used to generate values
|
||||||
|
* @param {number} limit - Length of the array
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
static filledArray (fn, limit = make.number.tiny()) {
|
||||||
|
const array = []
|
||||||
|
|
||||||
|
for (let i = 0; i < limit; i++) {
|
||||||
|
const value = random.pick(fn)
|
||||||
|
if (value !== null) {
|
||||||
array.push(value)
|
array.push(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,3 +25,5 @@ make.arrays = {
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = arrays
|
||||||
|
|
|
@ -2,16 +2,19 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.colors = {
|
const make = require('../make')
|
||||||
any: function () {
|
const random = require('../random')
|
||||||
return random.pick([
|
|
||||||
make.colors.rgb,
|
|
||||||
make.colors.hsl,
|
|
||||||
make.colors.keyword
|
|
||||||
])
|
|
||||||
},
|
|
||||||
|
|
||||||
rgb: function () {
|
class colors extends make {
|
||||||
|
static any () {
|
||||||
|
return random.pick([
|
||||||
|
colors.rgb,
|
||||||
|
colors.hsl,
|
||||||
|
colors.keyword
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
static rgb () {
|
||||||
let values
|
let values
|
||||||
|
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
|
@ -22,43 +25,43 @@ make.colors = {
|
||||||
values = [random.number(255), random.number(255), random.number(255)]
|
values = [random.number(255), random.number(255), random.number(255)]
|
||||||
} else {
|
} else {
|
||||||
// Percents
|
// Percents
|
||||||
values = ['%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [`%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
}
|
}
|
||||||
return 'rgba(' + values.join(',') + ')'
|
return `rgba(${values.join(',')})`
|
||||||
case 1:
|
case 1:
|
||||||
// Rgba functional notation
|
// Rgba functional notation
|
||||||
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
||||||
return 'rgba(' + values.join(',') + ')'
|
return `rgba(${values.join(',')})`
|
||||||
case 2:
|
case 2:
|
||||||
// 4 char hex
|
// 4 char hex
|
||||||
return '#' + random.hex(4)
|
return `#${random.hex(4)}`
|
||||||
default:
|
default:
|
||||||
// 8 char hex
|
// 8 char hex
|
||||||
return '#' + random.hex(8)
|
return `#${random.hex(8)}`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
hsl: function () {
|
static hsl () {
|
||||||
let values, opt
|
let values, opt
|
||||||
|
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
case 0:
|
case 0:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
case 1:
|
case 1:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
case 2:
|
case 2:
|
||||||
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
||||||
values = [random.number(255) + opt, '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255) + opt, `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
default:
|
default:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), random.float()]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, random.float()]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
keyword: function () {
|
static keyword () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'lime', 'red', 'blue', 'invert', 'currentColor', 'ActiveBorder', 'ActiveCaption',
|
'lime', 'red', 'blue', 'invert', 'currentColor', 'ActiveBorder', 'ActiveCaption',
|
||||||
'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow',
|
'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow',
|
||||||
|
@ -83,3 +86,5 @@ make.colors = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = colors
|
||||||
|
|
|
@ -2,59 +2,68 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.command = {
|
const make = require('../make')
|
||||||
_data: {
|
const random = require('../random')
|
||||||
'backcolor': function () { return make.colors.any() },
|
|
||||||
'bold': null,
|
class command extends make {
|
||||||
'contentReadOnly': function () { return random.bool() },
|
static data () {
|
||||||
'copy': null,
|
return {
|
||||||
'createlink': function () { return make.uri.any() },
|
'backcolor': () => make.colors.any(),
|
||||||
'cut': null,
|
'bold': null,
|
||||||
'decreasefontsize': null,
|
'contentReadOnly': () => random.bool(),
|
||||||
'delete': null,
|
'copy': null,
|
||||||
'enableInlineTableEditing': function () { return random.bool() },
|
'createlink': () => make.uri.any(),
|
||||||
'enableObjectResizing': function () { return random.bool() },
|
'cut': null,
|
||||||
'fontname': function () { return make.font.family() },
|
'decreasefontsize': null,
|
||||||
'fontsize': function () { return make.font.relativeSize() },
|
'delete': null,
|
||||||
'formatblock': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div'],
|
'enableInlineTableEditing': () => random.bool(),
|
||||||
'forwarddelete': null,
|
'enableObjectResizing': () => random.bool(),
|
||||||
'forecolor': function () { return make.colors.any() },
|
'fontname': () => make.font.family(),
|
||||||
'gethtml': null,
|
'fontsize': () => make.font.relativeSize(),
|
||||||
'heading': null,
|
'formatblock': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div'],
|
||||||
'hilitecolor': function () { return make.colors.any() },
|
'forwarddelete': null,
|
||||||
'increasefontsize': null,
|
'forecolor': () => make.colors.any(),
|
||||||
'indent': null,
|
'gethtml': null,
|
||||||
'insertBrOnReturn': function () { return random.bool() },
|
'heading': null,
|
||||||
'inserthorizontalrule': null,
|
'hilitecolor': () => make.colors.any(),
|
||||||
// 'inserthtml': function () { },
|
'increasefontsize': null,
|
||||||
'insertlinebreak': null,
|
'indent': null,
|
||||||
'insertimage': function () { return make.uri.any() },
|
'insertBrOnReturn': () => random.bool(),
|
||||||
'insertorderedlist': null,
|
'inserthorizontalrule': null,
|
||||||
'insertparagraph': null,
|
// 'inserthtml': function () { },
|
||||||
'inserttext': function () { return make.text.any() },
|
'insertlinebreak': null,
|
||||||
'insertunorderedlist': null,
|
'insertimage': () => make.uri.any(),
|
||||||
'italic': null,
|
'insertorderedlist': null,
|
||||||
'justifycenter': null,
|
'insertparagraph': null,
|
||||||
'justifyfull': null,
|
'inserttext': () => make.text.any(),
|
||||||
'justifyleft': null,
|
'insertunorderedlist': null,
|
||||||
'justifyright': null,
|
'italic': null,
|
||||||
'outdent': null,
|
'justifycenter': null,
|
||||||
'paste': null,
|
'justifyfull': null,
|
||||||
'redo': null,
|
'justifyleft': null,
|
||||||
'removeformat': null,
|
'justifyright': null,
|
||||||
'selectall': null,
|
'outdent': null,
|
||||||
'strikethrough': null,
|
'paste': null,
|
||||||
'styleWithCSS': function () { return random.bool() },
|
'redo': null,
|
||||||
'subscript': null,
|
'removeformat': null,
|
||||||
'superscript': null,
|
'selectall': null,
|
||||||
'underline': null,
|
'strikethrough': null,
|
||||||
'undo': null,
|
'styleWithCSS': () => random.bool(),
|
||||||
'unlink': null
|
'subscript': null,
|
||||||
},
|
'superscript': null,
|
||||||
name: function () {
|
'underline': null,
|
||||||
return random.item(Object.keys(this._data))
|
'undo': null,
|
||||||
},
|
'unlink': null
|
||||||
value: function (name) {
|
}
|
||||||
return random.pick(this._data[name])
|
}
|
||||||
|
|
||||||
|
static name () {
|
||||||
|
return random.item(Object.keys(command.data()))
|
||||||
|
}
|
||||||
|
|
||||||
|
static value (name) {
|
||||||
|
return random.pick(command.data()[name])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = command
|
||||||
|
|
1720
lib/make/crypto.js
1720
lib/make/crypto.js
File diff suppressed because it is too large
Load diff
|
@ -1,26 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
make.datetime = {
|
|
||||||
object: function () {
|
|
||||||
switch (random.number(2)) {
|
|
||||||
case 0:
|
|
||||||
return new Date(new Date().getTime() + random.number())
|
|
||||||
case 1:
|
|
||||||
return new Date(new Date().getTime() - random.number())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
date: function () { // eslint-disable-line no-unused-vars
|
|
||||||
return this.object().toDateString()
|
|
||||||
},
|
|
||||||
time: function () { // eslint-disable-line no-unused-vars
|
|
||||||
return this.object().toTimeString()
|
|
||||||
},
|
|
||||||
iso: function () { // eslint-disable-line no-unused-vars
|
|
||||||
return this.object().toISOString()
|
|
||||||
},
|
|
||||||
epoch: function () { // eslint-disable-line no-unused-vars
|
|
||||||
return Math.floor(this.object() / 1000)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
|
@ -2,17 +2,23 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.font = {
|
const make = require('../make')
|
||||||
globalValue: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class font extends make {
|
||||||
|
static globalValue () {
|
||||||
return random.pick(['inherit', 'initial', 'unset'])
|
return random.pick(['inherit', 'initial', 'unset'])
|
||||||
},
|
}
|
||||||
style: function () {
|
|
||||||
|
static style () {
|
||||||
return random.pick(['italic', 'normal', 'oblique', 'inherit'])
|
return random.pick(['italic', 'normal', 'oblique', 'inherit'])
|
||||||
},
|
}
|
||||||
variant: function () {
|
|
||||||
|
static variant () {
|
||||||
return random.pick(['normal', 'small-caps', 'inherit'])
|
return random.pick(['normal', 'small-caps', 'inherit'])
|
||||||
},
|
}
|
||||||
weight: function () {
|
|
||||||
|
static weight () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
/* standard */
|
/* standard */
|
||||||
['normal', 'bold'],
|
['normal', 'bold'],
|
||||||
|
@ -21,8 +27,9 @@ make.font = {
|
||||||
/* numeric values */
|
/* numeric values */
|
||||||
[100, 200, 300, 400, 500, 600, 700, 800, 900]
|
[100, 200, 300, 400, 500, 600, 700, 800, 900]
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
size: function () {
|
|
||||||
|
static size () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
/* <absolute-size> values */
|
/* <absolute-size> values */
|
||||||
['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
|
['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
|
||||||
|
@ -33,25 +40,30 @@ make.font = {
|
||||||
/* <percentage> values */
|
/* <percentage> values */
|
||||||
make.unit.percent()
|
make.unit.percent()
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
relativeSize: function () {
|
|
||||||
|
static relativeSize () {
|
||||||
let value = random.number(8)
|
let value = random.number(8)
|
||||||
return random.item(['', '+', '-']) + value
|
return random.item(['', '+', '-']) + value
|
||||||
},
|
}
|
||||||
genericFamily: function () {
|
|
||||||
|
static genericFamily () {
|
||||||
return random.pick(['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'])
|
return random.pick(['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'])
|
||||||
},
|
}
|
||||||
familyName: function () {
|
|
||||||
|
static familyName () {
|
||||||
return random.pick(['Times New Roman', 'Arial', 'Courier', 'Helvetica'])
|
return random.pick(['Times New Roman', 'Arial', 'Courier', 'Helvetica'])
|
||||||
},
|
}
|
||||||
family: function () {
|
|
||||||
let s = random.pick(make.font.familyName)
|
static family () {
|
||||||
|
let s = random.pick(font.familyName)
|
||||||
if (random.chance(8)) {
|
if (random.chance(8)) {
|
||||||
s += ', ' + random.pick(make.font.genericFamily)
|
s += `, ${random.pick(font.genericFamily)}`
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
},
|
}
|
||||||
registeredFontFeatures: function () {
|
|
||||||
|
static registeredFontFeatures () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
|
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
|
||||||
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
|
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
|
||||||
|
@ -69,24 +81,27 @@ make.font = {
|
||||||
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
|
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
|
||||||
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
|
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
font: function () {
|
|
||||||
|
static font () {
|
||||||
let s = ''
|
let s = ''
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(make.font.style) + ' '
|
s += `${random.pick(font.style)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(make.font.variant) + ' '
|
s += `${random.pick(font.variant)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(make.font.weight) + ' '
|
s += `${random.pick(font.weight)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += make.number.any() + '/'
|
s += `${make.number.any()}/`
|
||||||
}
|
}
|
||||||
s += make.font.size()
|
s += font.size()
|
||||||
s += ' '
|
s += ' '
|
||||||
s += make.font.family()
|
s += font.family()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = font
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
make.html = {
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
tag: function () {
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
const make = require('../make')
|
||||||
|
const random = require('../random')
|
||||||
|
|
||||||
|
class html extends make {
|
||||||
|
static tag () {
|
||||||
return random.item(['a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'foo', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xmp'])
|
return random.item(['a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'foo', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xmp'])
|
||||||
},
|
}
|
||||||
attribute: function () { // eslint-disable-line no-unused-vars
|
|
||||||
|
static attribute () {
|
||||||
return random.item(['accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'async', 'autocomplete', 'autofocus', 'autoplay', 'autosave', 'bgcolor', 'border', 'buffered', 'challenge', 'charset', 'checked', 'cite', 'class', 'code', 'codebase', 'color', 'cols', 'colspan', 'content', 'contenteditable', 'contextmenu', 'controls', 'coords', 'crossorigin', 'data', 'data-*', 'datetime', 'default', 'defer', 'dir', 'dirname', 'disabled', 'download', 'draggable', 'dropzone', 'enctype', 'for', 'form', 'formaction', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'http-equiv', 'icon', 'id', 'integrity', 'ismap', 'itemprop', 'keytype', 'kind', 'label', 'lang', 'language', 'list', 'loop', 'low', 'manifest', 'max', 'maxlength', 'minlength', 'media', 'method', 'min', 'multiple', 'muted', 'name', 'novalidate', 'open', 'optimum', 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'radiogroup', 'readonly', 'rel', 'required', 'reversed', 'rows', 'rowspan', 'sandbox', 'scope', 'scoped', 'seamless', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src', 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style', 'summary', 'tabindex', 'target', 'title', 'type', 'usemap', 'value', 'width'])
|
return random.item(['accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'async', 'autocomplete', 'autofocus', 'autoplay', 'autosave', 'bgcolor', 'border', 'buffered', 'challenge', 'charset', 'checked', 'cite', 'class', 'code', 'codebase', 'color', 'cols', 'colspan', 'content', 'contenteditable', 'contextmenu', 'controls', 'coords', 'crossorigin', 'data', 'data-*', 'datetime', 'default', 'defer', 'dir', 'dirname', 'disabled', 'download', 'draggable', 'dropzone', 'enctype', 'for', 'form', 'formaction', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'http-equiv', 'icon', 'id', 'integrity', 'ismap', 'itemprop', 'keytype', 'kind', 'label', 'lang', 'language', 'list', 'loop', 'low', 'manifest', 'max', 'maxlength', 'minlength', 'media', 'method', 'min', 'multiple', 'muted', 'name', 'novalidate', 'open', 'optimum', 'pattern', 'ping', 'placeholder', 'poster', 'preload', 'radiogroup', 'readonly', 'rel', 'required', 'reversed', 'rows', 'rowspan', 'sandbox', 'scope', 'scoped', 'seamless', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'spellcheck', 'src', 'srcdoc', 'srclang', 'srcset', 'start', 'step', 'style', 'summary', 'tabindex', 'target', 'title', 'type', 'usemap', 'value', 'width'])
|
||||||
},
|
}
|
||||||
interfaceName: function () { // eslint-disable-line no-unused-vars
|
|
||||||
|
static interfaceName () {
|
||||||
return random.pick(['HTMLBRElement', 'HTMLTableSectionElement', 'HTMLDataListElement', 'HTMLTableElement', 'HTMLOListElement', 'HTMLFontElement', 'HTMLMapElement', 'HTMLButtonElement', 'HTMLFrameSetElement', 'HTMLDataElement', 'HTMLOptGroupElement', 'HTMLAnchorElement', 'HTMLLinkElement', 'HTMLObjectElement', 'HTMLHeadElement', 'HTMLProgressElement', 'HTMLFrameElement', 'HTMLTimeElement', 'HTMLTableCaptionElement', 'HTMLDivElement', 'HTMLDListElement', 'HTMLBodyElement', 'HTMLImageElement', 'HTMLTableRowElement', 'HTMLScriptElement', 'HTMLInputElement', 'HTMLMeterElement', 'HTMLFieldSetElement', 'HTMLHtmlElement', 'HTMLStyleElement', 'HTMLDetailsElement', 'HTMLTrackElement', 'HTMLBaseElement', 'HTMLTableColElement', 'HTMLSourceElement', 'HTMLPictureElement', 'HTMLSelectElement', 'HTMLLegendElement', 'HTMLHRElement', 'HTMLModElement', 'HTMLTemplateElement', 'HTMLAreaElement', 'HTMLFormElement', 'HTMLEmbedElement', 'HTMLSpanElement', 'HTMLParagraphElement', 'HTMLIFrameElement', 'HTMLTableCellElement', 'HTMLElement', 'HTMLMenuElement', 'HTMLTextAreaElement', 'HTMLHeadingElement', 'HTMLCanvasElement', 'HTMLOutputElement', 'HTMLQuoteElement', 'HTMLOptionElement', 'HTMLLIElement', 'HTMLAudioElement', 'HTMLMenuItemElement', 'HTMLParamElement', 'HTMLUListElement', 'HTMLLabelElement', 'HTMLDirectoryElement', 'HTMLTitleElement', 'HTMLPreElement', 'HTMLMetaElement', 'HTMLVideoElement'])
|
return random.pick(['HTMLBRElement', 'HTMLTableSectionElement', 'HTMLDataListElement', 'HTMLTableElement', 'HTMLOListElement', 'HTMLFontElement', 'HTMLMapElement', 'HTMLButtonElement', 'HTMLFrameSetElement', 'HTMLDataElement', 'HTMLOptGroupElement', 'HTMLAnchorElement', 'HTMLLinkElement', 'HTMLObjectElement', 'HTMLHeadElement', 'HTMLProgressElement', 'HTMLFrameElement', 'HTMLTimeElement', 'HTMLTableCaptionElement', 'HTMLDivElement', 'HTMLDListElement', 'HTMLBodyElement', 'HTMLImageElement', 'HTMLTableRowElement', 'HTMLScriptElement', 'HTMLInputElement', 'HTMLMeterElement', 'HTMLFieldSetElement', 'HTMLHtmlElement', 'HTMLStyleElement', 'HTMLDetailsElement', 'HTMLTrackElement', 'HTMLBaseElement', 'HTMLTableColElement', 'HTMLSourceElement', 'HTMLPictureElement', 'HTMLSelectElement', 'HTMLLegendElement', 'HTMLHRElement', 'HTMLModElement', 'HTMLTemplateElement', 'HTMLAreaElement', 'HTMLFormElement', 'HTMLEmbedElement', 'HTMLSpanElement', 'HTMLParagraphElement', 'HTMLIFrameElement', 'HTMLTableCellElement', 'HTMLElement', 'HTMLMenuElement', 'HTMLTextAreaElement', 'HTMLHeadingElement', 'HTMLCanvasElement', 'HTMLOutputElement', 'HTMLQuoteElement', 'HTMLOptionElement', 'HTMLLIElement', 'HTMLAudioElement', 'HTMLMenuItemElement', 'HTMLParamElement', 'HTMLUListElement', 'HTMLLabelElement', 'HTMLDirectoryElement', 'HTMLTitleElement', 'HTMLPreElement', 'HTMLMetaElement', 'HTMLVideoElement'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static className () {
|
||||||
|
return random.item(['class_1', 'class_2', 'class_3', 'class_4'])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = html
|
||||||
|
|
87
lib/make/index.js
Normal file
87
lib/make/index.js
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
class make {
|
||||||
|
static get number () {
|
||||||
|
return require('./numbers')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get alignment () {
|
||||||
|
return require('./alignment')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get arrays () {
|
||||||
|
return require('./arrays')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get colors () {
|
||||||
|
return require('./colors')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get command () {
|
||||||
|
return require('./command')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get crypto () {
|
||||||
|
return require('./crypto')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get files () {
|
||||||
|
return require('./files')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get font () {
|
||||||
|
return require('./fonts')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get html () {
|
||||||
|
return require('./html')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get mime () {
|
||||||
|
return require('./mime')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get network () {
|
||||||
|
return require('./network')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get shaders () {
|
||||||
|
return require('./shaders')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get style () {
|
||||||
|
return require('./style')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get text () {
|
||||||
|
return require('./text')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get time () {
|
||||||
|
return require('./time')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get typed () {
|
||||||
|
return require('./typed')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get types () {
|
||||||
|
return require('./types')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get unit () {
|
||||||
|
return require('./units')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get uri () {
|
||||||
|
return require('./uri')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get webgl () {
|
||||||
|
return require('./webgl')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = make
|
|
@ -1 +0,0 @@
|
||||||
var make = {} // eslint-disable-line no-unused-vars
|
|
|
@ -2,18 +2,21 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.mime = {
|
const make = require('../make')
|
||||||
any: function () {
|
const random = require('../random')
|
||||||
return random.pick([
|
|
||||||
make.mime.standard,
|
|
||||||
make.mime.xml,
|
|
||||||
make.mime.image,
|
|
||||||
make.mime.media,
|
|
||||||
make.mime.form
|
|
||||||
])
|
|
||||||
},
|
|
||||||
|
|
||||||
standard: function () {
|
class mime extends make {
|
||||||
|
static any () {
|
||||||
|
return random.pick([
|
||||||
|
mime.standard,
|
||||||
|
mime.xml,
|
||||||
|
mime.image,
|
||||||
|
mime.media,
|
||||||
|
mime.form
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
static standard () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'text/html',
|
'text/html',
|
||||||
'text/html; charset=utf-8',
|
'text/html; charset=utf-8',
|
||||||
|
@ -25,9 +28,9 @@ make.mime = {
|
||||||
'application/x-shockwave-flash',
|
'application/x-shockwave-flash',
|
||||||
'application/x-test'
|
'application/x-test'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
xml: function () {
|
static xml () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'application/xml',
|
'application/xml',
|
||||||
'text/xml',
|
'text/xml',
|
||||||
|
@ -38,9 +41,9 @@ make.mime = {
|
||||||
'application/rdf+xml',
|
'application/rdf+xml',
|
||||||
'application/xslt+xml'
|
'application/xslt+xml'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
image: function () {
|
static image () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'image/jpeg',
|
'image/jpeg',
|
||||||
'image/gif',
|
'image/gif',
|
||||||
|
@ -48,9 +51,9 @@ make.mime = {
|
||||||
'image/mng',
|
'image/mng',
|
||||||
'image/*'
|
'image/*'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
media: function () {
|
static media () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'audio/mpeg',
|
'audio/mpeg',
|
||||||
'audio/ogg',
|
'audio/ogg',
|
||||||
|
@ -60,9 +63,9 @@ make.mime = {
|
||||||
'video/mp4',
|
'video/mp4',
|
||||||
'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
|
'video/mp4; codecs="avc1.42E01E, mp4a.40.2"'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
form: function () {
|
static form () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'application/x-www-form-urlencoded',
|
'application/x-www-form-urlencoded',
|
||||||
'multipart/form-data',
|
'multipart/form-data',
|
||||||
|
@ -70,3 +73,5 @@ make.mime = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = mime
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.network = {
|
const make = require('../make')
|
||||||
sdp () {
|
const random = require('../random')
|
||||||
|
const utils = require('../utils')
|
||||||
|
|
||||||
|
class network extends make {
|
||||||
|
static sdp () {
|
||||||
// session description protocol template
|
// session description protocol template
|
||||||
return [
|
return [
|
||||||
'v=0',
|
'v=0',
|
||||||
|
@ -37,8 +41,9 @@ make.network = {
|
||||||
'a=candidate:0 1 UDP 2113601791 192.168.129.33 65080 typ host',
|
'a=candidate:0 1 UDP 2113601791 192.168.129.33 65080 typ host',
|
||||||
'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host'
|
'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host'
|
||||||
].join('\n')
|
].join('\n')
|
||||||
},
|
}
|
||||||
IceCandidate () {
|
|
||||||
|
static IceCandidate () {
|
||||||
// https://tools.ietf.org/html/rfc5245#section-15
|
// https://tools.ietf.org/html/rfc5245#section-15
|
||||||
// candidate=
|
// candidate=
|
||||||
return utils.block.block([
|
return utils.block.block([
|
||||||
|
@ -47,11 +52,11 @@ make.network = {
|
||||||
random.pick([0, 1, make.number.any]),
|
random.pick([0, 1, make.number.any]),
|
||||||
' ',
|
' ',
|
||||||
random.pick(['UDP', 'TCP', 'SCTP']),
|
random.pick(['UDP', 'TCP', 'SCTP']),
|
||||||
random.pick(['', '/' + random.pick(['DTLS', 'DTLS-SRTP'])]),
|
random.pick(['', `/${random.pick(['DTLS', 'DTLS-SRTP'])}`]),
|
||||||
' ',
|
' ',
|
||||||
random.pick([make.number.any]),
|
random.pick([make.number.any]),
|
||||||
' ',
|
' ',
|
||||||
random.pick([make.network.goodHostnames]),
|
random.pick([network.goodHostnames]),
|
||||||
' ',
|
' ',
|
||||||
random.pick([56187, make.number.any]),
|
random.pick([56187, make.number.any]),
|
||||||
' ',
|
' ',
|
||||||
|
@ -64,15 +69,16 @@ make.network = {
|
||||||
' ',
|
' ',
|
||||||
random.pick(['raddr']),
|
random.pick(['raddr']),
|
||||||
' ',
|
' ',
|
||||||
random.pick([make.network.goodHostnames]),
|
random.pick([network.goodHostnames]),
|
||||||
' ',
|
' ',
|
||||||
random.pick(['rport']),
|
random.pick(['rport']),
|
||||||
random.use([utils.block.block([' ', make.number.any])])
|
random.use([utils.block.block([' ', make.number.any])])
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
SdpMid () {
|
|
||||||
|
static SdpMid () {
|
||||||
// m=
|
// m=
|
||||||
return utils.block.block([
|
return utils.block.block([
|
||||||
random.pick(['application', 'video', 'audio']),
|
random.pick(['application', 'video', 'audio']),
|
||||||
|
@ -83,17 +89,18 @@ make.network = {
|
||||||
' ',
|
' ',
|
||||||
make.number.any
|
make.number.any
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
Turn () {
|
|
||||||
|
static Turn () {
|
||||||
// https://tools.ietf.org/html/rfc7065#section-3.1
|
// https://tools.ietf.org/html/rfc7065#section-3.1
|
||||||
return utils.block.block([
|
return utils.block.block([
|
||||||
// scheme
|
// scheme
|
||||||
random.pick(make.network.PeerConnectionProtocols),
|
random.pick(network.PeerConnectionProtocols),
|
||||||
':',
|
':',
|
||||||
// turn-host
|
// turn-host
|
||||||
random.pick([
|
random.pick([
|
||||||
make.text.any,
|
network.any,
|
||||||
make.network.hostname
|
network.hostname
|
||||||
]),
|
]),
|
||||||
// turn-port
|
// turn-port
|
||||||
random.use([utils.block.block([':', make.number.any])]),
|
random.use([utils.block.block([':', make.number.any])]),
|
||||||
|
@ -103,17 +110,21 @@ make.network = {
|
||||||
'=',
|
'=',
|
||||||
random.pick(['udp', 'tcp', make.text.any])
|
random.pick(['udp', 'tcp', make.text.any])
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
PeerConnectionProtocols () {
|
|
||||||
|
static PeerConnectionProtocols () {
|
||||||
return ['turn', 'turns', 'stun', 'stuns']
|
return ['turn', 'turns', 'stun', 'stuns']
|
||||||
},
|
}
|
||||||
randomIPv4 () {
|
|
||||||
return random.pick([random.number(255), make.number.any]) + '.' +
|
static randomIPv4 () {
|
||||||
random.pick([random.number(255), make.number.any]) + '.' +
|
function octet () {
|
||||||
random.pick([random.number(255), make.number.any]) + '.' +
|
return random.pick([random.number(255), make.number.any])
|
||||||
random.pick([random.number(255), make.number.any])
|
}
|
||||||
},
|
|
||||||
randomIPv6 () {
|
return `${octet()}.${octet()}.${octet()}.${octet()}.`
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomIPv6 () {
|
||||||
let parts = []
|
let parts = []
|
||||||
|
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
|
@ -121,26 +132,32 @@ make.network = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts.join(':')
|
return parts.join(':')
|
||||||
},
|
}
|
||||||
iceServer () {
|
|
||||||
|
static iceServer () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'stun:23.21.150.121'
|
'stun:23.21.150.121'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
dtmf () {
|
|
||||||
return random.subset([
|
static dtmf () {
|
||||||
'*', '#',
|
let count = make.number.tiny()
|
||||||
'A', 'B', 'C', 'D',
|
const values = []
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
while (count--) {
|
||||||
], make.number.range()).join('')
|
values.push(random.item(['*', '#', 'A', 'B', 'C', 'D', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']))
|
||||||
},
|
}
|
||||||
goodHostnames () {
|
|
||||||
|
return values.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
static goodHostnames () {
|
||||||
return [
|
return [
|
||||||
'0.0.0.0',
|
'0.0.0.0',
|
||||||
'127.0.0.1:8080'
|
'127.0.0.1:8080'
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
badHostnames () {
|
|
||||||
|
static badHostnames () {
|
||||||
return [
|
return [
|
||||||
'google.org:8080',
|
'google.org:8080',
|
||||||
'::1',
|
'::1',
|
||||||
|
@ -154,61 +171,70 @@ make.network = {
|
||||||
'2001:db8::1:2',
|
'2001:db8::1:2',
|
||||||
'2001:db8::1:1:1:1:1'
|
'2001:db8::1:1:1:1:1'
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
hostname () {
|
|
||||||
|
static hostname () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
this.randomIPv4,
|
network.randomIPv4,
|
||||||
this.randomIPv6,
|
network.randomIPv6,
|
||||||
this.goodHostnames,
|
network.goodHostnames,
|
||||||
this.badHostnames
|
network.badHostnames
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
port () {
|
|
||||||
|
static port () {
|
||||||
return random.pick([80, 443, 21, 23, 9310])
|
return random.pick([80, 443, 21, 23, 9310])
|
||||||
},
|
}
|
||||||
hash () {
|
|
||||||
|
static hash () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'',
|
'',
|
||||||
'#',
|
'#',
|
||||||
'#main-content',
|
'#main-content',
|
||||||
() => '#' + make.text.any()
|
() => `#${make.text.any()}`
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
path () {
|
|
||||||
|
static path () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'',
|
'',
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
() => '/' + make.text.any()
|
() => `/${make.text.any()}`
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
protocol () {
|
|
||||||
return random.pick([
|
static protocol () {
|
||||||
|
return `${random.pick([
|
||||||
'http',
|
'http',
|
||||||
'https',
|
'https',
|
||||||
'ftp',
|
'ftp',
|
||||||
'telnet',
|
'telnet',
|
||||||
'chrome',
|
'chrome',
|
||||||
'resource'
|
'resource'
|
||||||
]) + ':'
|
])}:`
|
||||||
},
|
}
|
||||||
search () {
|
|
||||||
|
static search () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'',
|
'',
|
||||||
'?',
|
'?',
|
||||||
'?foo=bar',
|
'?foo=bar',
|
||||||
() => '?' + make.text.any()
|
() => `?${make.text.any()}`
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
randomBitmask (list) {
|
|
||||||
|
static randomBitmask (list) {
|
||||||
if (list.length <= 1) {
|
if (list.length <= 1) {
|
||||||
return list.join('')
|
return list.join('')
|
||||||
}
|
}
|
||||||
let max = random.range(2, list.length)
|
let max = random.range(2, list.length)
|
||||||
let mask = random.pick(list)
|
let mask = random.pick(list)
|
||||||
for (let i = 1; i < max; i++) {
|
for (let i = 1; i < max; i++) {
|
||||||
mask += '|' + random.pick(list)
|
mask += `|${random.pick(list)}`
|
||||||
}
|
}
|
||||||
return mask
|
return mask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = network
|
||||||
|
|
|
@ -2,71 +2,219 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.number = {
|
const make = require('../make')
|
||||||
bool: function () {
|
const random = require('../random')
|
||||||
return random.bool()
|
|
||||||
},
|
class number extends make {
|
||||||
float: function () {
|
/**
|
||||||
let n
|
* Returns a number that is more likely to exceed the supplied boundary
|
||||||
if (random.chance(32)) {
|
* @param value {number}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
static _exceed (value) {
|
||||||
|
switch (random.number(4)) {
|
||||||
|
case 0:
|
||||||
|
// Divisions
|
||||||
|
return Math.ceil(value / random.range(2, 4))
|
||||||
|
case 1:
|
||||||
|
// Powers
|
||||||
|
const offset = Math.pow(2, random.range(1, 7))
|
||||||
|
return (value > 0) ? (value - offset) : value + offset
|
||||||
|
default:
|
||||||
|
// Slightly less than limit
|
||||||
|
return (value > 0) ? (value - random.number(3)) : value + random.number(3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a int8 [-128, 127]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static int8 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(random.choose([
|
||||||
|
[1, -128],
|
||||||
|
[10, 127]
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(-128, 127)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a uint8 [0, 255]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static uint8 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(255)
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(0, 255)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a int16 [-32768, 32767]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static int16 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(random.choose([
|
||||||
|
[1, -32768],
|
||||||
|
[10, 32767]
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(-32768, 32767)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a uint16 [0, 65535]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static uint16 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(65535)
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(-0, 65535)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a int32 [-2147483648, 2147483647]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static int32 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(random.choose([
|
||||||
|
[1, -2147483648],
|
||||||
|
[10, 2147483647]
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(-2147483648, 2147483647)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a uint32 [0, 4294967295]
|
||||||
|
* @param bypass {boolean} - Determines if the range should be exceeded
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static uint32 (bypass = false) {
|
||||||
|
if (bypass || random.chance(50)) {
|
||||||
|
return number._exceed(4294967295)
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.range(0, 4294967295)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random floating point number
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static float () {
|
||||||
|
/* if (random.chance(32)) {
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
case 0:
|
case 0:
|
||||||
n = random.range(Number.MIN_VALUE, Number.MAX_VALUE)
|
return random.range(Number.MIN_VALUE, Number.MAX_VALUE)
|
||||||
break
|
|
||||||
case 1:
|
case 1:
|
||||||
n = Math.pow(10, 1) / Math.pow(10, random.number(307))
|
return Math.pow(10, 1) / Math.pow(10, random.number(307))
|
||||||
break
|
|
||||||
case 2:
|
case 2:
|
||||||
n = Math.pow(2, random.float() * random.float() * 64)
|
return Math.pow(2, random.float() * random.float() * 64)
|
||||||
break
|
|
||||||
case 3:
|
case 3:
|
||||||
n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9))
|
return Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9))
|
||||||
break
|
|
||||||
}
|
}
|
||||||
return n
|
} */
|
||||||
}
|
|
||||||
switch (random.number(6)) {
|
return random.float()
|
||||||
default:
|
}
|
||||||
n = random.float()
|
|
||||||
}
|
/**
|
||||||
return n
|
* Returns a float value within the supplied range
|
||||||
},
|
* @param {number} min - Start value
|
||||||
range: function () {
|
* @param {number} max - End value
|
||||||
return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.number.tiny])
|
* @param {number} precision
|
||||||
},
|
* @returns {number}
|
||||||
frange: function (min, max, precision) {
|
*/
|
||||||
|
static frange (min, max, precision) {
|
||||||
let x = Math.random() * (min - max) + max
|
let x = Math.random() * (min - max) + max
|
||||||
if (precision) {
|
if (precision) {
|
||||||
let power = Math.pow(10, precision || 0)
|
let power = Math.pow(10, precision || 0)
|
||||||
x = Math.round(x * power) / power
|
x = Math.round(x * power) / power
|
||||||
}
|
}
|
||||||
return x
|
return x
|
||||||
},
|
}
|
||||||
tiny: function () {
|
|
||||||
return Math.pow(2, random.number(12))
|
/**
|
||||||
},
|
* Returns a random power of 2 between 1 and 2048
|
||||||
unsigned: function () {
|
* @returns {number}
|
||||||
if (random.chance(2)) {
|
*/
|
||||||
return Math.abs(make.number.any())
|
static tiny () {
|
||||||
}
|
// Calling random.number twice prefers lower values
|
||||||
return Math.pow(2, random.number(random.number(65))) + random.number(3) - 1
|
return Math.pow(2, random.number(random.number(13)))
|
||||||
},
|
}
|
||||||
even: function (number) {
|
|
||||||
|
/**
|
||||||
|
* Returns a random number adjacent to the supplied number
|
||||||
|
* @param {number} number
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static even (number) {
|
||||||
return number % 2 === 1 ? ++number : number
|
return number % 2 === 1 ? ++number : number
|
||||||
},
|
}
|
||||||
interesting: function () {
|
|
||||||
|
/**
|
||||||
|
* Returns a random number that may be interesting
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static interesting () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[10, [-128, -1, 0, 1, 16, 32, 64, 100, 127]],
|
[50, [-128, -1, 0, 1, 16, 32, 64, 100, 127]],
|
||||||
[7, [-32768, -129, 128, 255, 256, 512, 1000, 1024, 4096, 32767]],
|
[30, [-32768, -129, 128, 255, 256, 512, 1000, 1024, 4096, 32767]],
|
||||||
[1, [-2147483648, -100663046, -32769, 32768, 65535, 65536, 100663045, 2147483647]]
|
[1, [-2147483648, -100663046, -32769, 32768, 65535, 65536, 100663045, 2147483647]]
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
any: function () {
|
|
||||||
let value = random.choose([
|
/**
|
||||||
[10, make.number.float],
|
* Returns a random signed number
|
||||||
[10, [make.number.range, make.number.tiny]],
|
* @returns {number}
|
||||||
[1, make.number.unsigned]
|
*/
|
||||||
|
static signed () {
|
||||||
|
return random.choose([
|
||||||
|
[50, [number.int8]],
|
||||||
|
[30, [number.int16]],
|
||||||
|
[1, [number.int32]]
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random unsigned number
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static unsigned () {
|
||||||
|
return random.choose([
|
||||||
|
[50, [number.uint8]],
|
||||||
|
[30, [number.uint16]],
|
||||||
|
[1, [number.uint32]]
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random number using the type base number generators above
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static any () {
|
||||||
|
return random.choose([
|
||||||
|
[50, [number.int8, number.uint8]],
|
||||||
|
[30, [number.int16, number.uint16]],
|
||||||
|
[1, [number.int32, number.uint32]]
|
||||||
])
|
])
|
||||||
return random.chance(10) ? -value : value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = number
|
||||||
|
|
|
@ -2,133 +2,149 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.shaders = {
|
const random = require('../random')
|
||||||
fragment1: [
|
const make = require('../make')
|
||||||
[
|
const utils = require('../utils')
|
||||||
'#ifdef GL_ES',
|
|
||||||
'precision mediump float;',
|
class shaders extends make {
|
||||||
'#endif',
|
static get fragment1 () {
|
||||||
'varying vec4 vColor;',
|
return [
|
||||||
'void main() {',
|
[
|
||||||
'gl_FragColor=vColor;',
|
'#ifdef GL_ES',
|
||||||
'}'
|
'precision mediump float;',
|
||||||
],
|
'#endif',
|
||||||
[
|
'varying vec4 vColor;',
|
||||||
'varying highp vec2 vTextureCoord;',
|
'void main() {',
|
||||||
'varying highp vec3 vLighting;',
|
'gl_FragColor=vColor;',
|
||||||
'uniform sampler2D uSampler;',
|
'}'
|
||||||
'void main(void) {',
|
],
|
||||||
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
[
|
||||||
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
'varying highp vec2 vTextureCoord;',
|
||||||
'}'
|
'varying highp vec3 vLighting;',
|
||||||
|
'uniform sampler2D uSampler;',
|
||||||
|
'void main(void) {',
|
||||||
|
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
||||||
|
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
}
|
||||||
vertex1: [
|
|
||||||
[
|
static get vertex1 () {
|
||||||
'attribute vec4 aVertex;',
|
return [
|
||||||
'attribute vec4 aColor;',
|
[
|
||||||
'varying vec4 vColor;',
|
'attribute vec4 aVertex;',
|
||||||
'void main(){',
|
'attribute vec4 aColor;',
|
||||||
'vColor=aColor;',
|
'varying vec4 vColor;',
|
||||||
'gl_Position=aVertex;',
|
'void main(){',
|
||||||
'}'
|
'vColor=aColor;',
|
||||||
],
|
'gl_Position=aVertex;',
|
||||||
[
|
'}'
|
||||||
'attribute highp vec3 aVertexNormal;',
|
],
|
||||||
'attribute highp vec3 aVertexPosition;',
|
[
|
||||||
'attribute highp vec2 aTextureCoord;',
|
'attribute highp vec3 aVertexNormal;',
|
||||||
'uniform highp mat4 uNormalMatrix;',
|
'attribute highp vec3 aVertexPosition;',
|
||||||
'uniform highp mat4 uMVMatrix;',
|
'attribute highp vec2 aTextureCoord;',
|
||||||
'uniform highp mat4 uPMatrix;',
|
'uniform highp mat4 uNormalMatrix;',
|
||||||
'varying highp vec2 vTextureCoord;',
|
'uniform highp mat4 uMVMatrix;',
|
||||||
'varying highp vec3 vLighting;',
|
'uniform highp mat4 uPMatrix;',
|
||||||
'void main(void) {',
|
'varying highp vec2 vTextureCoord;',
|
||||||
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
'varying highp vec3 vLighting;',
|
||||||
'vTextureCoord = aTextureCoord;',
|
'void main(void) {',
|
||||||
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
||||||
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
'vTextureCoord = aTextureCoord;',
|
||||||
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
||||||
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
||||||
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
||||||
'vLighting = ambientLight + (directionalLightColor * directional);',
|
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
||||||
'}'
|
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
||||||
|
'vLighting = ambientLight + (directionalLightColor * directional);',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
}
|
||||||
fragment2: [
|
|
||||||
[
|
static get fragment2 () {
|
||||||
'varying highp vec2 vTextureCoord;',
|
return [
|
||||||
'varying highp vec3 vLighting;',
|
[
|
||||||
'uniform sampler2D uSampler;',
|
'varying highp vec2 vTextureCoord;',
|
||||||
'void main(void) {',
|
'varying highp vec3 vLighting;',
|
||||||
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
'uniform sampler2D uSampler;',
|
||||||
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
'void main(void) {',
|
||||||
'}'
|
'highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));',
|
||||||
],
|
'gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);',
|
||||||
[
|
'}'
|
||||||
'#version proto-200',
|
],
|
||||||
'uniform sampler2D albedoMap;',
|
[
|
||||||
'uniform sampler2D normalMap;',
|
'#version proto-200',
|
||||||
'varying vec3 varyingTangent;',
|
'uniform sampler2D albedoMap;',
|
||||||
'varying vec3 varyingBitangent;',
|
'uniform sampler2D normalMap;',
|
||||||
'varying vec3 varyingNormal;',
|
'varying vec3 varyingTangent;',
|
||||||
'varying vec2 varyingUV;',
|
'varying vec3 varyingBitangent;',
|
||||||
'void main(void) {',
|
'varying vec3 varyingNormal;',
|
||||||
'vec3 albedo=texture2D(albedoMap,varyingUV).rgb;',
|
'varying vec2 varyingUV;',
|
||||||
'vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;',
|
'void main(void) {',
|
||||||
'float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);',
|
'vec3 albedo=texture2D(albedoMap,varyingUV).rgb;',
|
||||||
'float specularHardness=2.0;',
|
'vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;',
|
||||||
'vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;',
|
'float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);',
|
||||||
'gl_FragData[0]=vec4(albedo,1.0);',
|
'float specularHardness=2.0;',
|
||||||
'gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);',
|
'vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;',
|
||||||
'gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);',
|
'gl_FragData[0]=vec4(albedo,1.0);',
|
||||||
'}'
|
'gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);',
|
||||||
|
'gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
}
|
||||||
vertex2: [
|
|
||||||
[
|
static get vertex2 () {
|
||||||
'attribute highp vec3 aVertexNormal;',
|
return [
|
||||||
'attribute highp vec3 aVertexPosition;',
|
[
|
||||||
'attribute highp vec2 aTextureCoord;',
|
'attribute highp vec3 aVertexNormal;',
|
||||||
'uniform highp mat4 uNormalMatrix;',
|
'attribute highp vec3 aVertexPosition;',
|
||||||
'uniform highp mat4 uMVMatrix;',
|
'attribute highp vec2 aTextureCoord;',
|
||||||
'uniform highp mat4 uPMatrix;',
|
'uniform highp mat4 uNormalMatrix;',
|
||||||
'varying highp vec2 vTextureCoord;',
|
'uniform highp mat4 uMVMatrix;',
|
||||||
'varying highp vec3 vLighting;',
|
'uniform highp mat4 uPMatrix;',
|
||||||
'void main(void) {',
|
'varying highp vec2 vTextureCoord;',
|
||||||
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
'varying highp vec3 vLighting;',
|
||||||
'vTextureCoord = aTextureCoord;',
|
'void main(void) {',
|
||||||
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
'gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);',
|
||||||
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
'vTextureCoord = aTextureCoord;',
|
||||||
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
'highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);',
|
||||||
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
'highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);',
|
||||||
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
'highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);',
|
||||||
'vLighting = ambientLight + (directionalLightColor * directional);',
|
'highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);',
|
||||||
'}'
|
'highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);',
|
||||||
],
|
'vLighting = ambientLight + (directionalLightColor * directional);',
|
||||||
[
|
'}'
|
||||||
'#version proto-200',
|
],
|
||||||
'attribute vec3 vertexPosition;',
|
[
|
||||||
'attribute vec3 vertexTangent;',
|
'#version proto-200',
|
||||||
'attribute vec3 vertexBitangent;',
|
'attribute vec3 vertexPosition;',
|
||||||
'attribute vec3 vertexNormal;',
|
'attribute vec3 vertexTangent;',
|
||||||
'attribute vec2 vertexUV;',
|
'attribute vec3 vertexBitangent;',
|
||||||
'uniform mat4 modelMatrix;',
|
'attribute vec3 vertexNormal;',
|
||||||
'uniform mat4 viewMatrix;',
|
'attribute vec2 vertexUV;',
|
||||||
'varying vec3 varyingTangent;',
|
'uniform mat4 modelMatrix;',
|
||||||
'varying vec3 varyingBitangent;',
|
'uniform mat4 viewMatrix;',
|
||||||
'varying vec3 varyingNormal;',
|
'varying vec3 varyingTangent;',
|
||||||
'varying vec2 varyingUV;',
|
'varying vec3 varyingBitangent;',
|
||||||
'void main(void){',
|
'varying vec3 varyingNormal;',
|
||||||
'gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));',
|
'varying vec2 varyingUV;',
|
||||||
'gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);',
|
'void main(void){',
|
||||||
'varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;',
|
'gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));',
|
||||||
'varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;',
|
'gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);',
|
||||||
'varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;',
|
'varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;',
|
||||||
'varyingUV = vertexUV;',
|
'varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;',
|
||||||
'}'
|
'varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;',
|
||||||
|
'varyingUV = vertexUV;',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
}
|
||||||
shaderPair: function (v, f) {
|
|
||||||
|
static shaderPair (v, f) {
|
||||||
let i = random.number(v.length)
|
let i = random.number(v.length)
|
||||||
return {
|
return {
|
||||||
vertex: utils.common.quote(v[i].join(' ')),
|
vertex: utils.common.quote(v[i].join(' ')),
|
||||||
|
@ -136,3 +152,5 @@ make.shaders = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = shaders
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
make.style = {
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
pseudoElement: function () {
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
const make = require('../make')
|
||||||
|
const random = require('../random')
|
||||||
|
|
||||||
|
class style extends make {
|
||||||
|
static pseudoElement () {
|
||||||
return random.item([
|
return random.item([
|
||||||
'::after',
|
'::after',
|
||||||
'::before',
|
'::before',
|
||||||
|
@ -14,3 +21,5 @@ make.style = {
|
||||||
'::grammar-error'])
|
'::grammar-error'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = style
|
||||||
|
|
473
lib/make/text.js
473
lib/make/text.js
|
@ -2,34 +2,90 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.text = {
|
const random = require('../random')
|
||||||
lineEnd: function () {
|
const make = require('../make')
|
||||||
|
const utils = require('../utils')
|
||||||
|
|
||||||
|
class text extends make {
|
||||||
|
/**
|
||||||
|
* Generate a random alphabetic character
|
||||||
|
*/
|
||||||
|
static alpha () {
|
||||||
|
return String.fromCharCode(random.range('A'.charCodeAt(0), 'z'.charCodeAt(0)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random alphanumeric character
|
||||||
|
*/
|
||||||
|
static alphanum () {
|
||||||
|
return String.fromCharCode(random.range('0'.charCodeAt(0), 'z'.charCodeAt(0)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random assignment operator
|
||||||
|
*/
|
||||||
|
static assignmentOperator () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'\n', '\r', '\r\n', '\n\r'
|
'=', '+=', '-=', '*=', '/=', '%=', '**=', '<<=', '>>=', '>>>=', '&=', '^=', '|='
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
controlChar: function () {
|
|
||||||
|
/**
|
||||||
|
* Generate a random arithmetic operator
|
||||||
|
*/
|
||||||
|
static arithmeticOperator () {
|
||||||
|
return random.pick([
|
||||||
|
'%', '-', '+', '*', '/'
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random control character
|
||||||
|
*/
|
||||||
|
static controlChar () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'\b', '\t', '\n', '\v', '\f', '\r', '\0', '\c', '\a', '\e' // eslint-disable-line no-useless-escape
|
'\b', '\t', '\n', '\v', '\f', '\r', '\0', '\c', '\a', '\e' // eslint-disable-line no-useless-escape
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
token: function () {
|
|
||||||
|
/**
|
||||||
|
* Generate a random digit
|
||||||
|
*/
|
||||||
|
static digit () {
|
||||||
|
return String.fromCharCode(random.range('0'.charCodeAt(0), '9'.charCodeAt(0)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random line ending
|
||||||
|
*/
|
||||||
|
static lineEnd () {
|
||||||
|
return random.pick([
|
||||||
|
'\n', '\r', '\r\n', '\n\r'
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random token
|
||||||
|
*/
|
||||||
|
static token () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'*', '+', '%', '-', '!', '^', ':', '|', '&', '<', '>', '.', '"',
|
'*', '+', '%', '-', '!', '^', ':', '|', '&', '<', '>', '.', '"',
|
||||||
'#', ' ', ';', ',', '{', '}', '(', ')', '[', ']', '/', '\\', '/*', '*/'
|
'#', ' ', ';', ',', '{', '}', '(', ')', '[', ']', '/', '\\', '/*', '*/'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
charset: function () {
|
|
||||||
|
static charset () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'UTF-8', 'ISO-8859-1'
|
'UTF-8', 'ISO-8859-1'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
language: function () {
|
|
||||||
|
static language () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
// special casing for i, I, dotted/dotless variants
|
// special casing for i, I, dotted/dotless variants
|
||||||
['tr', 'az'],
|
['tr', 'az', 'crh', 'tt', 'ba'],
|
||||||
// special casing rules: https://developer.mozilla.org/en/CSS/text-transform
|
// special casing rules: https://developer.mozilla.org/en/CSS/text-transform
|
||||||
['nl', 'gr'],
|
['nl', 'el', 'ga'],
|
||||||
// special justification rules
|
// special justification rules
|
||||||
['ja', 'zh'],
|
['ja', 'zh'],
|
||||||
// tend to be RTL
|
// tend to be RTL
|
||||||
|
@ -39,157 +95,189 @@ make.text = {
|
||||||
// Seen in mxr
|
// Seen in mxr
|
||||||
['en-US', 'fr', 'fra', 'de', 'ru', 'en-us', 'is-IS', 'xyzzy']
|
['en-US', 'fr', 'fra', 'de', 'ru', 'en-us', 'is-IS', 'xyzzy']
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
layoutCharCodes: function () {
|
|
||||||
return random.pick([
|
/**
|
||||||
0, // null
|
* Generate a random character that may affect layout
|
||||||
160, // non-breaking space
|
*/
|
||||||
0x005C, // backslash, but in some countries, represents local currency symbol (e.g. yen)
|
static layoutCharCodes () {
|
||||||
0x00AD, // soft hyphen
|
return String.fromCodePoint(
|
||||||
0x0BCC, // a Tamil character that is displayed as three glyphs
|
random.pick([
|
||||||
// http://unicode.org/charts/PDF/U2000.pdf
|
0, // null
|
||||||
0x200B, // zero-width space
|
160, // non-breaking space
|
||||||
0x200C, // zero-width non-joiner
|
0x005C, // backslash, but in some countries, represents local currency symbol (e.g. yen)
|
||||||
0x200D, // zero-width joiner
|
0x00AD, // soft hyphen
|
||||||
0x200E, // left-to-right mark
|
0x0BCC, // a Tamil character that is displayed as three glyphs
|
||||||
0x200F, // right-to-left mark
|
// http://unicode.org/charts/PDF/U2000.pdf
|
||||||
0x2011, // non-breaking hyphen
|
0x200B, // zero-width space
|
||||||
0x2027, // hyphenation point
|
0x200C, // zero-width non-joiner
|
||||||
0x2028, // line separator
|
0x200D, // zero-width joiner
|
||||||
0x2029, // paragraph separator
|
0x200E, // left-to-right mark
|
||||||
0x202A, // left-to-right embedding
|
0x200F, // right-to-left mark
|
||||||
0x202B, // right-to-left embedding
|
0x2011, // non-breaking hyphen
|
||||||
0x202C, // pop directional formatting
|
0x2027, // hyphenation point
|
||||||
0x202D, // left-to-right override
|
0x2028, // line separator
|
||||||
0x202E, // right-to-left override
|
0x2029, // paragraph separator
|
||||||
0x202F, // narrow no-break space
|
0x202A, // left-to-right embedding
|
||||||
0x2060, // word joiner
|
0x202B, // right-to-left embedding
|
||||||
0x2061, // function application (one of several invisible mathematical operators)
|
0x202C, // pop directional formatting
|
||||||
// http://unicode.org/charts/PDF/U3000.pdf
|
0x202D, // left-to-right override
|
||||||
0x3000, // ideographic space (CJK)
|
0x202E, // right-to-left override
|
||||||
// http://unicode.org/charts/PDF/U0300.pdf
|
0x202F, // narrow no-break space
|
||||||
0x0301, // combining acute accent (if it appears after "a", it turns into "a" with an accent)
|
0x2060, // word joiner
|
||||||
// Arabic has the interesting property that most letters connect to the next letter.
|
0x2061, // function application (one of several invisible mathematical operators)
|
||||||
// Some code calls this "shaping".
|
// http://unicode.org/charts/PDF/U3000.pdf
|
||||||
0x0643, // arabic letter kaf
|
0x3000, // ideographic space (CJK)
|
||||||
0x0645, // arabic letter meem
|
// http://unicode.org/charts/PDF/U0300.pdf
|
||||||
0x06CD, // arabic letter yeh with tail
|
0x0301, // combining acute accent (if it appears after "a", it turns into "a" with an accent)
|
||||||
0xFDDE, // invalid unicode? but somehow associated with arabic.
|
// Arabic has the interesting property that most letters connect to the next letter.
|
||||||
// http://unicode.org/reports/tr36/tr36-7.html#Buffer_Overflows
|
// Some code calls this "shaping".
|
||||||
// Characters with especially high expansion factors when they go through various unicode "normalizations"
|
0x0643, // arabic letter kaf
|
||||||
0x1F82,
|
0x0645, // arabic letter meem
|
||||||
0xFDFA,
|
0x06CD, // arabic letter yeh with tail
|
||||||
0xFB2C,
|
0xFDDE, // invalid unicode? but somehow associated with arabic.
|
||||||
0x0390,
|
// http://unicode.org/reports/tr36/tr36-7.html#Buffer_Overflows
|
||||||
// 0x1D160, // hmm, need surrogates
|
// Characters with especially high expansion factors when they go through various unicode "normalizations"
|
||||||
// Characters with especially high expansion factors when lowercased or uppercased
|
0x1F82,
|
||||||
0x023A,
|
0xFDFA,
|
||||||
0x0041,
|
0xFB2C,
|
||||||
0xDC1D, // a low surrogate
|
0x0390,
|
||||||
0xDB00, // a high surrogate
|
// 0x1D160, // hmm, need surrogates
|
||||||
// UFFF0.pdf
|
// Characters with especially high expansion factors when lowercased or uppercased
|
||||||
0xFFF9, // interlinear annotation anchor
|
0x023A,
|
||||||
0xFFFA, // interlinear annotation seperator
|
0x0041,
|
||||||
0xFFFB, // interlinear annotation terminator
|
0xDC1D, // a low surrogate
|
||||||
0xFFFC, // object replacement character
|
0xDB00, // a high surrogate
|
||||||
0xFFFD, // replacement character
|
// UFFF0.pdf
|
||||||
0xFEFF, // zero width no-break space
|
0xFFF9, // interlinear annotation anchor
|
||||||
0xFFFF, // not a character
|
0xFFFA, // interlinear annotation seperator
|
||||||
0x00A0, // no-break space
|
0xFFFB, // interlinear annotation terminator
|
||||||
0x2426,
|
0xFFFC, // object replacement character
|
||||||
0x003F,
|
0xFFFD, // replacement character
|
||||||
0x00BF,
|
0xFEFF, // zero width no-break space
|
||||||
0xDC80,
|
0xFFFF, // not a character
|
||||||
0xDCFF,
|
0x00A0, // no-break space
|
||||||
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
|
0x2426,
|
||||||
0x205F, // mathematical space
|
0x003F,
|
||||||
0x2061, // mathematical function application
|
0x00BF,
|
||||||
0x2064, // mathematical invisible separator
|
0xDC80,
|
||||||
0x2044 // fraction slash character
|
0xDCFF,
|
||||||
])
|
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
|
||||||
},
|
0x205F, // mathematical space
|
||||||
bidiCharCodes: function () {
|
0x2061, // mathematical function application
|
||||||
return random.pick([
|
0x2064, // mathematical invisible separator
|
||||||
0x0660, // START_HINDI_DIGITS
|
0x2044 // fraction slash character
|
||||||
0x0669, // END_HINDI_DIGITS
|
])
|
||||||
0x066A, // START_ARABIC_SEPARATOR
|
)
|
||||||
0x066B, // END_ARABIC_SEPARATOR
|
}
|
||||||
0x0030, // START_ARABIC_DIGITS
|
|
||||||
0x0039, // END_ARABIC_DIGITS
|
/**
|
||||||
0x06f0, // START_FARSI_DIGITS
|
* Generate a random character that affects bidi layout
|
||||||
0x06f9 // END_FARSI_DIGITS
|
*/
|
||||||
])
|
static bidiCharCodes () {
|
||||||
},
|
return String.fromCodePoint(
|
||||||
// http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
|
random.pick([
|
||||||
unicodeCombiningCharacters: function () {
|
0x0660, // START_HINDI_DIGITS
|
||||||
return random.item([
|
0x0669, // END_HINDI_DIGITS
|
||||||
[0x0300, 0x036F], // Combining Diacritical Marks
|
0x066A, // START_ARABIC_SEPARATOR
|
||||||
[0x0483, 0x0489],
|
0x066B, // END_ARABIC_SEPARATOR
|
||||||
[0x07EB, 0x07F3],
|
0x0030, // START_ARABIC_DIGITS
|
||||||
[0x135D, 0x135F],
|
0x0039, // END_ARABIC_DIGITS
|
||||||
[0x1A7F, 0x1A7F],
|
0x06f0, // START_FARSI_DIGITS
|
||||||
[0x1B6B, 0x1B73],
|
0x06f9 // END_FARSI_DIGITS
|
||||||
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
|
])
|
||||||
[0x20D0, 0x2DFF],
|
)
|
||||||
[0x3099, 0x309A],
|
}
|
||||||
[0xA66F, 0xA6F1],
|
|
||||||
[0xA8E0, 0xA8F1],
|
/**
|
||||||
[0xFE20, 0xFE26], // Combining Half Marks
|
* Generate a random unicode combining character
|
||||||
[0x101FD, 0x101FD],
|
* http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
|
||||||
[0x1D165, 0x1D169],
|
*/
|
||||||
[0x1D16D, 0x1D172],
|
static unicodeCombiningCharacter () {
|
||||||
[0x1D17B, 0x1D18B],
|
return String.fromCodePoint(
|
||||||
[0x1D1AA, 0x1D1AD],
|
random.range(
|
||||||
[0x1D242, 0x1D244]
|
...random.item([
|
||||||
])
|
[0x0300, 0x036F], // Combining Diacritical Marks
|
||||||
},
|
[0x0483, 0x0489],
|
||||||
unicodeBMP: function () {
|
[0x07EB, 0x07F3],
|
||||||
return random.item([
|
[0x135D, 0x135F],
|
||||||
// BMP = Basic Multilingual Plane
|
[0x1A7F, 0x1A7F],
|
||||||
[0x0000, 0xFFFF]
|
[0x1B6B, 0x1B73],
|
||||||
])
|
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
|
||||||
},
|
[0x20D0, 0x2DFF],
|
||||||
unicodeSMP: function () {
|
[0x3099, 0x309A],
|
||||||
return random.item([
|
[0xA66F, 0xA6F1],
|
||||||
// SMP = Supplementary Multilingual Plane
|
[0xA8E0, 0xA8F1],
|
||||||
[0x10000, 0x13FFF],
|
[0xFE20, 0xFE26], // Combining Half Marks
|
||||||
[0x16000, 0x16FFF],
|
[0x101FD, 0x101FD],
|
||||||
[0x1B000, 0x1BFFF],
|
[0x1D165, 0x1D169],
|
||||||
[0x1D000, 0x1DFFF],
|
[0x1D16D, 0x1D172],
|
||||||
[0x1F000, 0x1FFFF]
|
[0x1D17B, 0x1D18B],
|
||||||
])
|
[0x1D1AA, 0x1D1AD],
|
||||||
},
|
[0x1D242, 0x1D244]
|
||||||
unicodeSIP: function () {
|
])
|
||||||
return random.item([
|
)
|
||||||
// SIP = Supplementary Ideographic Plane
|
)
|
||||||
[0x20000, 0x2BFFF],
|
}
|
||||||
[0x2F000, 0x2FFFF]
|
|
||||||
])
|
/**
|
||||||
},
|
* Generate a random basic multilingual plane character
|
||||||
unicodeSSP: function () {
|
*/
|
||||||
return random.item([
|
static unicodeBMP () {
|
||||||
// SSP = Supplementary Special-purpose Plane
|
return String.fromCodePoint(
|
||||||
[0xE0000, 0xE0FFF]
|
random.range(0x0000, 0xFFFF)
|
||||||
])
|
)
|
||||||
},
|
}
|
||||||
assignmentOperator: function () {
|
|
||||||
return random.pick([
|
/**
|
||||||
'=', '+=', '-=', '*=', '/=', '%=', '**=', '<<=', '>>=', '>>>=', '&=', '^=', '|='
|
* Generate a random supplementary multilingual plane character
|
||||||
])
|
*/
|
||||||
},
|
static unicodeSMP () {
|
||||||
arithmeticOperator: function () {
|
return String.fromCodePoint(
|
||||||
return random.pick([
|
random.range(
|
||||||
'%', '-', '+', '*', '/'
|
...random.item([
|
||||||
])
|
[0x10000, 0x13FFF],
|
||||||
},
|
[0x16000, 0x16FFF],
|
||||||
currency: function () {
|
[0x1B000, 0x1BFFF],
|
||||||
|
[0x1D000, 0x1DFFF],
|
||||||
|
[0x1F000, 0x1FFFF]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random supplementary ideographic plane character
|
||||||
|
*/
|
||||||
|
static unicodeSIP () {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.range(
|
||||||
|
...random.item([
|
||||||
|
[0x20000, 0x2BFFF],
|
||||||
|
[0x2F000, 0x2FFFF]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a random supplementary special-purpose plane character
|
||||||
|
*/
|
||||||
|
static unicodeSSP () {
|
||||||
|
return String.fromCodePoint(
|
||||||
|
random.range(0xE0000, 0xE0FFF)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
static currency () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
// https://en.wikipedia.org/wiki/ISO_4217
|
// https://en.wikipedia.org/wiki/ISO_4217
|
||||||
'USD', 'USS', 'USN', 'EUR', 'CHF', 'GBP', 'XAG', 'XBA', 'XBB', 'XBC',
|
'USD', 'USS', 'USN', 'EUR', 'CHF', 'GBP', 'XAG', 'XBA', 'XBB', 'XBC',
|
||||||
'XBD', 'XSU', 'XTS', 'XXX'
|
'XBD', 'XSU', 'XTS', 'XXX'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
fromBlocks: function (set, maxlen) {
|
|
||||||
|
static fromBlocks (set, maxlen) {
|
||||||
let s = ''
|
let s = ''
|
||||||
|
|
||||||
for (let i = 0; i < random.number(maxlen || 255); i++) {
|
for (let i = 0; i < random.number(maxlen || 255); i++) {
|
||||||
|
@ -197,29 +285,56 @@ make.text = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
},
|
}
|
||||||
quotedString: function () {
|
|
||||||
return utils.common.quote(make.text.any())
|
static quotedString () {
|
||||||
},
|
return utils.common.quote(text.any())
|
||||||
chars: function () {
|
}
|
||||||
return random.pick([
|
|
||||||
make.text.controlChar,
|
/**
|
||||||
make.text.token,
|
* Wrapper for all text generators
|
||||||
make.text.assignmentOperator,
|
* @returns {string}
|
||||||
make.text.arithmeticOperator,
|
*/
|
||||||
String.fromCharCode(make.text.layoutCharCodes()),
|
static random () {
|
||||||
String.fromCharCode(make.text.bidiCharCodes())
|
return random.choose([
|
||||||
|
[1, text.alpha],
|
||||||
|
[1, text.alphanum],
|
||||||
|
[1, text.arithmeticOperator],
|
||||||
|
[1, text.assignmentOperator],
|
||||||
|
[1, text.controlChar],
|
||||||
|
[1, text.digit],
|
||||||
|
[1, text.lineEnd],
|
||||||
|
[1, text.token],
|
||||||
|
[3, text.layoutCharCodes],
|
||||||
|
[3, text.bidiCharCodes],
|
||||||
|
[3, text.unicodeCombiningCharacter],
|
||||||
|
[3, text.unicodeBMP],
|
||||||
|
[3, text.unicodeSMP],
|
||||||
|
[3, text.unicodeSIP],
|
||||||
|
[3, text.unicodeSSP]
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
any: function () {
|
|
||||||
// Generate a string compromised of random individual characters
|
/**
|
||||||
// This might be too slow to used for all 'texts' uses
|
* Generate a single character
|
||||||
|
*/
|
||||||
|
static character () {
|
||||||
|
return text.random().charAt(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate string comprised of random generators
|
||||||
|
*/
|
||||||
|
static any () {
|
||||||
let s = ''
|
let s = ''
|
||||||
// TODO: Len calculation take from DOMFuzz - maybe we should revise this?
|
let len = random.range(1, 126)
|
||||||
let len = random.pick([make.number.tiny, make.number.range])
|
|
||||||
for (let i = 0; i < len; i++) {
|
while (len--) {
|
||||||
s += make.text.chars()
|
s += make.text.random()
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = text
|
||||||
|
|
|
@ -2,13 +2,44 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.time = {
|
const make = require('../make')
|
||||||
unit: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class time extends make {
|
||||||
|
static unit () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
's', 'ms'
|
's', 'ms'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
any: function () {
|
|
||||||
return make.number.any() + make.time.unit()
|
static datetime () {
|
||||||
|
switch (random.number(2)) {
|
||||||
|
case 0:
|
||||||
|
return new Date(new Date().getTime() + random.number())
|
||||||
|
case 1:
|
||||||
|
return new Date(new Date().getTime() - random.number())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static date () {
|
||||||
|
return time.datetime().toDateString()
|
||||||
|
}
|
||||||
|
|
||||||
|
static time () {
|
||||||
|
return time.datetime().toTimeString()
|
||||||
|
}
|
||||||
|
|
||||||
|
static iso () {
|
||||||
|
return time.datetime().toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
static epoch () {
|
||||||
|
return Math.floor(time.datetime() / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
static any () {
|
||||||
|
return make.number.any() + time.unit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = time
|
||||||
|
|
|
@ -2,116 +2,129 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.typed = {
|
const make = require('../make')
|
||||||
byte: function (limit = null) {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class typed extends make {
|
||||||
|
static byte (limit = null) {
|
||||||
// [-128, 127]
|
// [-128, 127]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(129)
|
let value = (limit !== null) ? random.number(limit) : random.number(129)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Uint8Array([' + value + '])[0]'
|
return `new Uint8Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
octet: function (limit = null) {
|
|
||||||
|
static octet (limit = null) {
|
||||||
// [0, 255]
|
// [0, 255]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(256)
|
let value = (limit !== null) ? random.number(limit) : random.number(256)
|
||||||
return 'new Int8Array([' + value + '])[0]'
|
return `new Int8Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
short: function (limit = null) {
|
|
||||||
|
static short (limit = null) {
|
||||||
// [-32768, 32767]
|
// [-32768, 32767]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(32769)
|
let value = (limit !== null) ? random.number(limit) : random.number(32769)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Int16Array([' + value + '])[0]'
|
return `new Int16Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
unsignedShort: function (limit = null) {
|
|
||||||
|
static unsignedShort (limit = null) {
|
||||||
// [0, 65535]
|
// [0, 65535]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(65535)
|
let value = (limit !== null) ? random.number(limit) : random.number(65535)
|
||||||
return 'new Uint16Array([' + value + '])[0]'
|
return `new Uint16Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
long: function (limit = null) {
|
|
||||||
|
static long (limit = null) {
|
||||||
// [-2147483648, 2147483647]
|
// [-2147483648, 2147483647]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
|
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Int32Array([' + value + '])[0]'
|
return `new Int32Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
unsignedLong: function (limit = null) {
|
|
||||||
|
static unsignedLong (limit = null) {
|
||||||
// [0, 4294967295]
|
// [0, 4294967295]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
|
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
|
||||||
return 'new Uint32Array([' + value + '])[0]'
|
return `new Uint32Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
// ToDo: Add support for longlong and ulonglong
|
|
||||||
/*
|
static float (limit = null) {
|
||||||
longLong: function () {},
|
|
||||||
unsignedLongLong: function () {},
|
|
||||||
*/
|
|
||||||
float: function (limit = null) {
|
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float32Array([' + value + '])[0]'
|
return `new Float32Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
unrestrictedFloat: function (limit = null) {
|
|
||||||
|
static unrestrictedFloat (limit = null) {
|
||||||
if (random.chance(100)) {
|
if (random.chance(100)) {
|
||||||
return random.pick([NaN, +Infinity, -Infinity])
|
return random.pick([NaN, +Infinity, -Infinity])
|
||||||
} else {
|
} else {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
return 'new Float32Array([' + (base + random.float()) + '])[0]'
|
return `new Float32Array([${base + random.float()}])[0]`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
double: function (limit = null) {
|
|
||||||
|
static double (limit = null) {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float64Array([' + value + '])[0]'
|
return `new Float64Array([${value}])[0]`
|
||||||
},
|
}
|
||||||
unrestrictedDouble: function (limit = null) {
|
|
||||||
|
static unrestrictedDouble (limit = null) {
|
||||||
if (random.chance(100)) {
|
if (random.chance(100)) {
|
||||||
return random.pick([NaN, +Infinity, -Infinity])
|
return random.pick([NaN, +Infinity, -Infinity])
|
||||||
} else {
|
} else {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float64Array([' + value + '])[0]'
|
return `new Float64Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
any: function () {
|
|
||||||
|
static any () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[1, [this.byte, this.octet]],
|
[1, [typed.byte, typed.octet]],
|
||||||
[1, [this.short, this.unsignedShort]],
|
[1, [typed.short, typed.unsignedShort]],
|
||||||
[1, [this.long, this.unsignedLong]],
|
[1, [typed.long, typed.unsignedLong]],
|
||||||
[1, [this.float, this.unrestrictedFloat]],
|
[1, [typed.float, typed.unrestrictedFloat]],
|
||||||
[1, [this.double, this.unrestrictedDouble]],
|
[1, [typed.double, typed.unrestrictedDouble]]
|
||||||
[1, [make.number.range, make.number.tiny]]
|
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
arrayBuffer: function (byteLength = null) {
|
|
||||||
let length = (byteLength !== null) ? byteLength : this.unsignedShort()
|
static arrayBuffer (byteLength = null) {
|
||||||
return 'new ArrayBuffer(' + length + ')'
|
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
||||||
},
|
return `new ArrayBuffer(${length})`
|
||||||
dataView: function (byteLength = null) {
|
}
|
||||||
let length = (byteLength !== null) ? byteLength : this.unsignedShort()
|
|
||||||
return 'new DataView(' + this.arrayBuffer(length) + ')'
|
static dataView (byteLength = null) {
|
||||||
},
|
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
||||||
typedArray: function (byteLength = null) {
|
return `new DataView(${typed.arrayBuffer(length)})`
|
||||||
let length = (byteLength !== null) ? byteLength : this.unsignedShort()
|
}
|
||||||
|
|
||||||
|
static typedArray (byteLength = null) {
|
||||||
|
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
||||||
let arrType = random.item([
|
let arrType = random.item([
|
||||||
'Int8', 'Uint8', 'Uint8Clamped',
|
'Int8', 'Uint8', 'Uint8Clamped',
|
||||||
'Int16', 'Uint16',
|
'Int16', 'Uint16',
|
||||||
'Int32', 'Uint32',
|
'Int32', 'Uint32',
|
||||||
'Float32', 'Float64'
|
'Float32', 'Float64'
|
||||||
])
|
])
|
||||||
let method = 'new ' + arrType + 'Array'
|
let method = `new ${arrType}Array`
|
||||||
switch (random.number(16)) {
|
switch (random.number(16)) {
|
||||||
case 0:
|
case 0:
|
||||||
return method + '()'
|
return `${method}()`
|
||||||
case 1:
|
case 1:
|
||||||
return method + '(' + this.typedArray() + ')'
|
return `${method}(${this.typedArray()})`
|
||||||
default:
|
default:
|
||||||
return method + '(' + length + ')'
|
return `${method}(${length})`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
bufferSource: function () {
|
|
||||||
|
static bufferSource () {
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
case 0:
|
case 0:
|
||||||
return this.arrayBuffer()
|
return typed.arrayBuffer()
|
||||||
case 1:
|
case 1:
|
||||||
return this.dataView()
|
return typed.dataView()
|
||||||
default:
|
default:
|
||||||
return this.typedArray()
|
return typed.typedArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = typed
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.types = {
|
const make = require('../make')
|
||||||
random: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class types extends make {
|
||||||
|
static random () {
|
||||||
return random.item([
|
return random.item([
|
||||||
'true',
|
'true',
|
||||||
'null',
|
'null',
|
||||||
|
@ -16,3 +19,5 @@ make.types = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = types
|
||||||
|
|
|
@ -2,16 +2,23 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.unit = {
|
const make = require('../make')
|
||||||
unit: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class unit extends make {
|
||||||
|
static unit () {
|
||||||
return random.pick([
|
return random.pick([
|
||||||
'px', 'em', 'ex', 'ch', 'rem', 'mm', 'cm', 'in', 'pt', 'pc', '%'
|
'px', 'em', 'ex', 'ch', 'rem', 'mm', 'cm', 'in', 'pt', 'pc', '%'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
length: function () {
|
|
||||||
|
static length () {
|
||||||
return make.number.any() + make.unit.unit()
|
return make.number.any() + make.unit.unit()
|
||||||
},
|
}
|
||||||
percent: function () {
|
|
||||||
return make.number.any() + '%'
|
static percent () {
|
||||||
|
return `${make.number.any()}%`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = unit
|
||||||
|
|
|
@ -2,17 +2,20 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.uri = {
|
const make = require('../make')
|
||||||
problematic: function () {
|
const random = require('../random')
|
||||||
|
|
||||||
|
class uri extends make {
|
||||||
|
static problematic () {
|
||||||
return random.item([
|
return random.item([
|
||||||
'aim:yaz', // Often triggers an 'external protocol request' dialog
|
'aim:yaz', // Often triggers an 'external protocol request' dialog
|
||||||
'foop:yaz', // Often triggers an unknown protocol
|
'foop:yaz', // Often triggers an unknown protocol
|
||||||
'about:memory', // Content is not allowed to link or load
|
'about:memory', // Content is not allowed to link or load
|
||||||
'ws://localhost/' // WebSocket protocol
|
'ws://localhost/' // WebSocket protocol
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
standard: function () {
|
static standard () {
|
||||||
return random.item([
|
return random.item([
|
||||||
'about:blank',
|
'about:blank',
|
||||||
'about:srcdoc',
|
'about:srcdoc',
|
||||||
|
@ -22,29 +25,31 @@ make.uri = {
|
||||||
'data:image/png,',
|
'data:image/png,',
|
||||||
'data:',
|
'data:',
|
||||||
'javascript:5555',
|
'javascript:5555',
|
||||||
'javascript:"QQQQ' + String.fromCharCode(0) + 'UUUU"',
|
`javascript:"QQQQ${String.fromCharCode(0)}UUUU"`,
|
||||||
'http://a.invalid/',
|
'http://a.invalid/',
|
||||||
'http://localhost:6/',
|
'http://localhost:6/',
|
||||||
'https://localhost:6/',
|
'https://localhost:6/',
|
||||||
'ftp://localhost:6/',
|
'ftp://localhost:6/',
|
||||||
'http://localhost:25/'
|
'http://localhost:25/'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
namespace: function () {
|
static namespace () {
|
||||||
return random.item([
|
return random.item([
|
||||||
'http://www.w3.org/1999/xhtml',
|
'http://www.w3.org/1999/xhtml',
|
||||||
'http://www.w3.org/2000/svg',
|
'http://www.w3.org/2000/svg',
|
||||||
'http://www.w3.org/1998/Math/MathML'
|
'http://www.w3.org/1998/Math/MathML'
|
||||||
])
|
])
|
||||||
},
|
}
|
||||||
|
|
||||||
any: function () {
|
static any () {
|
||||||
return random.choose([
|
return random.choose([
|
||||||
[1, this.problematic],
|
[1, uri.problematic],
|
||||||
[10, this.standard],
|
[10, uri.standard],
|
||||||
[10, this.namespace],
|
[10, uri.namespace],
|
||||||
[10, make.files.any]
|
[10, make.files.any]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = uri
|
||||||
|
|
|
@ -2,45 +2,52 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
make.webgl = {
|
const make = require('../make')
|
||||||
internalFormat: {
|
const random = require('../random')
|
||||||
'RGB': {format: 'RGB', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5']},
|
|
||||||
'RGBA': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4', 'UNSIGNED_SHORT_5_5_5_1']},
|
class webgl extends make {
|
||||||
'LUMINANCE_ALPHA': {format: 'LUMINANCE_ALPHA', type: ['UNSIGNED_BYTE']},
|
static get internalFormat () {
|
||||||
'LUMINANCE': {format: 'LUMINANCE', type: ['UNSIGNED_BYTE']},
|
return {
|
||||||
'ALPHA': {format: 'ALPHA', type: ['UNSIGNED_BYTE']},
|
'RGB': {format: 'RGB', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5']},
|
||||||
'R8': {format: 'RED', type: ['UNSIGNED_BYTE']},
|
'RGBA': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4', 'UNSIGNED_SHORT_5_5_5_1']},
|
||||||
'R16F': {format: 'RED', type: ['HALF_FLOAT', 'FLOAT']},
|
'LUMINANCE_ALPHA': {format: 'LUMINANCE_ALPHA', type: ['UNSIGNED_BYTE']},
|
||||||
'R32F': {format: 'RED', type: ['FLOAT']},
|
'LUMINANCE': {format: 'LUMINANCE', type: ['UNSIGNED_BYTE']},
|
||||||
'R8UI': {format: 'RED_INTEGER', type: ['UNSIGNED_BYTE']},
|
'ALPHA': {format: 'ALPHA', type: ['UNSIGNED_BYTE']},
|
||||||
'RG8': {format: 'RG', type: ['UNSIGNED_BYTE']},
|
'R8': {format: 'RED', type: ['UNSIGNED_BYTE']},
|
||||||
'RG16F': {format: 'RG', type: ['HALF_FLOAT', 'FLOAT']},
|
'R16F': {format: 'RED', type: ['HALF_FLOAT', 'FLOAT']},
|
||||||
'RG32F': {format: 'RG', type: ['FLOAT']},
|
'R32F': {format: 'RED', type: ['FLOAT']},
|
||||||
'RG8UI': {format: 'RG_INTEGER', type: ['UNSIGNED_BYTE']},
|
'R8UI': {format: 'RED_INTEGER', type: ['UNSIGNED_BYTE']},
|
||||||
'RGB8': {format: 'RGB', type: ['UNSIGNED_BYTE']},
|
'RG8': {format: 'RG', type: ['UNSIGNED_BYTE']},
|
||||||
'SRGB8': {format: 'RGB', type: ['UNSIGNED_BYTE']},
|
'RG16F': {format: 'RG', type: ['HALF_FLOAT', 'FLOAT']},
|
||||||
'RGB565': {format: 'RGB', type: ['RGB', 'UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5']},
|
'RG32F': {format: 'RG', type: ['FLOAT']},
|
||||||
'R11F_G11F_B10F': {format: 'RGB', type: ['UNSIGNED_INT_10F_11F_11F_REV', 'HALF_FLOAT', 'FLOAT']},
|
'RG8UI': {format: 'RG_INTEGER', type: ['UNSIGNED_BYTE']},
|
||||||
'RGB9_E5': {format: 'RGB', type: ['HALF_FLOAT', 'FLOAT']},
|
'RGB8': {format: 'RGB', type: ['UNSIGNED_BYTE']},
|
||||||
'RGB16F': {format: 'RGB', type: ['HALF_FLOAT', 'FLOAT']},
|
'SRGB8': {format: 'RGB', type: ['UNSIGNED_BYTE']},
|
||||||
'RGB32F': {format: 'RGB', type: ['FLOAT']},
|
'RGB565': {format: 'RGB', type: ['RGB', 'UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_6_5']},
|
||||||
'RGB8UI': {format: 'RGB_INTEGER', type: ['UNSIGNED_BYTE']},
|
'R11F_G11F_B10F': {format: 'RGB', type: ['UNSIGNED_INT_10F_11F_11F_REV', 'HALF_FLOAT', 'FLOAT']},
|
||||||
'RGBA8': {format: 'RGBA', type: ['UNSIGNED_BYTE']},
|
'RGB9_E5': {format: 'RGB', type: ['HALF_FLOAT', 'FLOAT']},
|
||||||
'SRGB8_ALPHA8': {format: 'RGBA', type: ['UNSIGNED_BYTE']},
|
'RGB16F': {format: 'RGB', type: ['HALF_FLOAT', 'FLOAT']},
|
||||||
'RGB5_A1': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_5_5_1']},
|
'RGB32F': {format: 'RGB', type: ['FLOAT']},
|
||||||
'RGB10_A2': {format: 'RGBA', type: ['UNSIGNED_INT_2_10_10_10_REV']},
|
'RGB8UI': {format: 'RGB_INTEGER', type: ['UNSIGNED_BYTE']},
|
||||||
'RGBA4': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4']},
|
'RGBA8': {format: 'RGBA', type: ['UNSIGNED_BYTE']},
|
||||||
'RGBA16F': {format: 'RGBA', type: ['HALF_FLOAT', 'FLOAT']},
|
'SRGB8_ALPHA8': {format: 'RGBA', type: ['UNSIGNED_BYTE']},
|
||||||
'RGBA32F': {format: 'RGBA', type: ['FLOAT']},
|
'RGB5_A1': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_5_5_5_1']},
|
||||||
'RGBA8UI': {format: 'RGBA_INTEGER', type: ['UNSIGNED_BYTE']}
|
'RGB10_A2': {format: 'RGBA', type: ['UNSIGNED_INT_2_10_10_10_REV']},
|
||||||
},
|
'RGBA4': {format: 'RGBA', type: ['UNSIGNED_BYTE', 'UNSIGNED_SHORT_4_4_4_4']},
|
||||||
WebGLFormat: () => {
|
'RGBA16F': {format: 'RGBA', type: ['HALF_FLOAT', 'FLOAT']},
|
||||||
let internalformat = random.item(Object.keys(make.webgl.internalFormat))
|
'RGBA32F': {format: 'RGBA', type: ['FLOAT']},
|
||||||
let format = make.webgl.internalFormat[internalformat].format
|
'RGBA8UI': {format: 'RGBA_INTEGER', type: ['UNSIGNED_BYTE']}
|
||||||
let type = random.item(make.webgl.internalFormat[internalformat].type)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static WebGLFormat () {
|
||||||
|
let internalformat = random.item(Object.keys(webgl.internalFormat))
|
||||||
|
let format = webgl.internalFormat[internalformat].format
|
||||||
|
let type = random.item(webgl.internalFormat[internalformat].type)
|
||||||
return [internalformat, format, type]
|
return [internalformat, format, type]
|
||||||
},
|
}
|
||||||
textureSources: () => {
|
|
||||||
|
static textureSources () {
|
||||||
let sources = [
|
let sources = [
|
||||||
'HTMLCanvasElement',
|
'HTMLCanvasElement',
|
||||||
'HTMLImageElement',
|
'HTMLImageElement',
|
||||||
|
@ -48,30 +55,62 @@ make.webgl = {
|
||||||
'ImageData'
|
'ImageData'
|
||||||
]
|
]
|
||||||
return random.item(sources)
|
return random.item(sources)
|
||||||
},
|
}
|
||||||
parseUniforms: (shader) => {
|
|
||||||
let names = []
|
static match (shader, regex, group = 1) {
|
||||||
let result = shader.match(/uniform .* (\w+)(?=;)/gm)
|
let matches = []
|
||||||
if (result) {
|
while (true) {
|
||||||
result.forEach((v) => names.push(v.split(' ').pop()))
|
let match = regex.exec(shader)
|
||||||
|
if (match) {
|
||||||
|
matches.push(match[group])
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return names
|
return matches
|
||||||
},
|
}
|
||||||
parseAttributes: (shader) => {
|
|
||||||
let names = []
|
static parseUniforms (shader, group = 1) {
|
||||||
let result = shader.match(/attribute .* (\w+)(?=;)/gm)
|
/* Todo: Parse their individual data types into categories. */
|
||||||
if (result) {
|
return webgl.match(shader, /uniform .+? (\w+)(?=[\[;])/gm, group) // eslint-disable-line no-useless-escape
|
||||||
result.forEach((v) => names.push(v.split(' ').pop()))
|
}
|
||||||
|
|
||||||
|
static parseAttributes (shader, group = 1) {
|
||||||
|
return webgl.match(shader, /attribute .+? (\w+)(?=;)/gm, group)
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseVaryings (shader, group = 1) {
|
||||||
|
return webgl.match(shader, /varying .+? (\w+)(?=;)/gm, group)
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFragDatav2 (shader, group = 1) {
|
||||||
|
// #version 200
|
||||||
|
return webgl.match(shader, /(gl_Frag[^[ =]+)/gm, group)
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFragDatav3 (shader, group = 1) {
|
||||||
|
// #version 300
|
||||||
|
return webgl.match(shader, /out .+? (\w+)(?=[\[;])/gm, group) // eslint-disable-line no-useless-escape
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseFrag (shader, group = 1) {
|
||||||
|
let matches = webgl.parseFragDatav2(shader)
|
||||||
|
if (matches.length) {
|
||||||
|
return matches
|
||||||
}
|
}
|
||||||
return names
|
return webgl.parseFragDatav3(shader)
|
||||||
},
|
}
|
||||||
parseFrag: (shader) => {
|
|
||||||
return shader.match(/(gl_Frag[^[ =]+)/gm)
|
static randomBitmask () {
|
||||||
},
|
const values = []
|
||||||
randomBitmask: () => {
|
for (let i = 0; i < 8; i++) {
|
||||||
return parseInt((random.subset([1, 0], 8).join('')))
|
values.push(random.item([1, 0]))
|
||||||
},
|
}
|
||||||
randomBufferTarget: (isWebGL2) => {
|
|
||||||
|
return parseInt(values.join(''))
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomBufferTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'ARRAY_BUFFER',
|
'ARRAY_BUFFER',
|
||||||
'ELEMENT_ARRAY_BUFFER'
|
'ELEMENT_ARRAY_BUFFER'
|
||||||
|
@ -87,8 +126,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomTexParameter: (isWebGL2) => {
|
|
||||||
|
static randomTexParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'TEXTURE_MAG_FILTER',
|
'TEXTURE_MAG_FILTER',
|
||||||
'TEXTURE_MIN_FILTER',
|
'TEXTURE_MIN_FILTER',
|
||||||
|
@ -107,8 +147,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomTexParameterValue: (isWebGL2) => {
|
|
||||||
|
static randomTexParameterValue (isWebGL2) {
|
||||||
let pnameparam = {
|
let pnameparam = {
|
||||||
'TEXTURE_MAG_FILTER': [
|
'TEXTURE_MAG_FILTER': [
|
||||||
'LINEAR',
|
'LINEAR',
|
||||||
|
@ -174,8 +215,9 @@ make.webgl = {
|
||||||
let pname = random.item(Object.keys(pnameparam))
|
let pname = random.item(Object.keys(pnameparam))
|
||||||
let param = random.item(pnameparam[pname])
|
let param = random.item(pnameparam[pname])
|
||||||
return [pname, param]
|
return [pname, param]
|
||||||
},
|
}
|
||||||
randomBlendMode: (isWebGL2) => {
|
|
||||||
|
static randomBlendMode (isWebGL2) {
|
||||||
let mode = [
|
let mode = [
|
||||||
'FUNC_ADD',
|
'FUNC_ADD',
|
||||||
'FUNC_SUBTRACT',
|
'FUNC_SUBTRACT',
|
||||||
|
@ -188,8 +230,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(mode)
|
return random.item(mode)
|
||||||
},
|
}
|
||||||
randomBlendFactor: (isWebGL2) => {
|
|
||||||
|
static randomBlendFactor (isWebGL2) {
|
||||||
let factor = [
|
let factor = [
|
||||||
'ZERO',
|
'ZERO',
|
||||||
'ONE',
|
'ONE',
|
||||||
|
@ -208,16 +251,18 @@ make.webgl = {
|
||||||
'SRC_ALPHA_SATURATE'
|
'SRC_ALPHA_SATURATE'
|
||||||
]
|
]
|
||||||
return random.item(factor)
|
return random.item(factor)
|
||||||
},
|
}
|
||||||
randomFace: (isWebGL2) => {
|
|
||||||
|
static randomFace (isWebGL2) {
|
||||||
let mode = [
|
let mode = [
|
||||||
'FRONT',
|
'FRONT',
|
||||||
'BACK',
|
'BACK',
|
||||||
'FRONT_AND_BACK'
|
'FRONT_AND_BACK'
|
||||||
]
|
]
|
||||||
return random.item(mode)
|
return random.item(mode)
|
||||||
},
|
}
|
||||||
randomTexImage2DTarget: (isWebGL2) => {
|
|
||||||
|
static randomTexImage2DTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'TEXTURE_2D',
|
'TEXTURE_2D',
|
||||||
'TEXTURE_CUBE_MAP_POSITIVE_X',
|
'TEXTURE_CUBE_MAP_POSITIVE_X',
|
||||||
|
@ -228,8 +273,9 @@ make.webgl = {
|
||||||
'TEXTURE_CUBE_MAP_NEGATIVE_Z'
|
'TEXTURE_CUBE_MAP_NEGATIVE_Z'
|
||||||
]
|
]
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomTextureTarget: (isWebGL2) => {
|
|
||||||
|
static randomTextureTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'TEXTURE_2D',
|
'TEXTURE_2D',
|
||||||
'TEXTURE_CUBE_MAP'
|
'TEXTURE_CUBE_MAP'
|
||||||
|
@ -241,8 +287,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomFunc: (isWebGL2) => {
|
|
||||||
|
static randomFunc (isWebGL2) {
|
||||||
let func = [
|
let func = [
|
||||||
'NEVER',
|
'NEVER',
|
||||||
'LESS',
|
'LESS',
|
||||||
|
@ -254,8 +301,9 @@ make.webgl = {
|
||||||
'ALWAYS'
|
'ALWAYS'
|
||||||
]
|
]
|
||||||
return random.item(func)
|
return random.item(func)
|
||||||
},
|
}
|
||||||
randomCap: (isWebGL2) => {
|
|
||||||
|
static randomCap (isWebGL2) {
|
||||||
let cap = [
|
let cap = [
|
||||||
'BLEND',
|
'BLEND',
|
||||||
'CULL_FACE',
|
'CULL_FACE',
|
||||||
|
@ -273,8 +321,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(cap)
|
return random.item(cap)
|
||||||
},
|
}
|
||||||
randomPrimitive: (isWebGL2) => {
|
|
||||||
|
static randomPrimitive (isWebGL2) {
|
||||||
let mode = [
|
let mode = [
|
||||||
'POINTS',
|
'POINTS',
|
||||||
'LINE_STRIP',
|
'LINE_STRIP',
|
||||||
|
@ -285,8 +334,9 @@ make.webgl = {
|
||||||
'TRIANGLES'
|
'TRIANGLES'
|
||||||
]
|
]
|
||||||
return random.item(mode)
|
return random.item(mode)
|
||||||
},
|
}
|
||||||
randomTextureAttachment: (isWebGL2) => {
|
|
||||||
|
static randomTextureAttachment (isWebGL2) {
|
||||||
let attachment = [
|
let attachment = [
|
||||||
'COLOR_ATTACHMENT0',
|
'COLOR_ATTACHMENT0',
|
||||||
'DEPTH_ATTACHMENT',
|
'DEPTH_ATTACHMENT',
|
||||||
|
@ -295,12 +345,13 @@ make.webgl = {
|
||||||
]
|
]
|
||||||
if (isWebGL2) {
|
if (isWebGL2) {
|
||||||
attachment.extend([
|
attachment.extend([
|
||||||
'COLOR_ATTACHMENT' + random.range(0, 15)
|
`COLOR_ATTACHMENT${random.range(0, 15)}`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(attachment)
|
return random.item(attachment)
|
||||||
},
|
}
|
||||||
randomAttachmentQuery: (isWebGL2) => {
|
|
||||||
|
static randomAttachmentQuery (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE',
|
'FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE',
|
||||||
'FRAMEBUFFER_ATTACHMENT_OBJECT_NAME',
|
'FRAMEBUFFER_ATTACHMENT_OBJECT_NAME',
|
||||||
|
@ -321,8 +372,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomShaderPrecision: (isWebGL2) => {
|
|
||||||
|
static randomShaderPrecision (isWebGL2) {
|
||||||
let precisiontype = [
|
let precisiontype = [
|
||||||
'LOW_FLOAT',
|
'LOW_FLOAT',
|
||||||
'MEDIUM_FLOAT',
|
'MEDIUM_FLOAT',
|
||||||
|
@ -332,8 +384,9 @@ make.webgl = {
|
||||||
'HIGH_INT'
|
'HIGH_INT'
|
||||||
]
|
]
|
||||||
return random.item(precisiontype)
|
return random.item(precisiontype)
|
||||||
},
|
}
|
||||||
randomStencilRefParameter: (isWebGL2) => {
|
|
||||||
|
static randomStencilRefParameter (isWebGL2) {
|
||||||
let param = [
|
let param = [
|
||||||
'STENCIL_FUNC',
|
'STENCIL_FUNC',
|
||||||
'STENCIL_VALUE_MASK',
|
'STENCIL_VALUE_MASK',
|
||||||
|
@ -344,16 +397,18 @@ make.webgl = {
|
||||||
'STENCIL_BITS'
|
'STENCIL_BITS'
|
||||||
]
|
]
|
||||||
return random.item(param)
|
return random.item(param)
|
||||||
},
|
}
|
||||||
randomStencilMaskParameter: (isWebGL2) => {
|
|
||||||
|
static randomStencilMaskParameter (isWebGL2) {
|
||||||
let param = [
|
let param = [
|
||||||
'STENCIL_WRITEMASK',
|
'STENCIL_WRITEMASK',
|
||||||
'STENCIL_BACK_WRITEMASK',
|
'STENCIL_BACK_WRITEMASK',
|
||||||
'STENCIL_BITS'
|
'STENCIL_BITS'
|
||||||
]
|
]
|
||||||
return random.item(param)
|
return random.item(param)
|
||||||
},
|
}
|
||||||
randomVertexAttribParameter: (isWebGL2) => {
|
|
||||||
|
static randomVertexAttribParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING',
|
'VERTEX_ATTRIB_ARRAY_BUFFER_BINDING',
|
||||||
'VERTEX_ATTRIB_ARRAY_ENABLED',
|
'VERTEX_ATTRIB_ARRAY_ENABLED',
|
||||||
|
@ -371,8 +426,9 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomHint: (isWebGL2) => {
|
|
||||||
|
static randomHint (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'GENERATE_MIPMAP_HINT'
|
'GENERATE_MIPMAP_HINT'
|
||||||
]
|
]
|
||||||
|
@ -382,16 +438,18 @@ make.webgl = {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomHintMode: (isWebGL2) => {
|
|
||||||
|
static randomHintMode (isWebGL2) {
|
||||||
let mode = [
|
let mode = [
|
||||||
'FASTEST',
|
'FASTEST',
|
||||||
'NICEST',
|
'NICEST',
|
||||||
'DONT_CARE'
|
'DONT_CARE'
|
||||||
]
|
]
|
||||||
return random.item(mode)
|
return random.item(mode)
|
||||||
},
|
}
|
||||||
randomPixelStorage: (isWebGL2) => {
|
|
||||||
|
static randomPixelStorage (isWebGL2) {
|
||||||
let pname = {
|
let pname = {
|
||||||
'PACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
'PACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
||||||
'UNPACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
'UNPACK_ALIGNMENT': random.item([1, 2, 4, 8]),
|
||||||
|
@ -416,8 +474,9 @@ make.webgl = {
|
||||||
}
|
}
|
||||||
let name = random.item(Object.keys(pname))
|
let name = random.item(Object.keys(pname))
|
||||||
return [name, pname[name]]
|
return [name, pname[name]]
|
||||||
},
|
}
|
||||||
randomStencilAction: (isWebGL2) => {
|
|
||||||
|
static randomStencilAction (isWebGL2) {
|
||||||
let action = [
|
let action = [
|
||||||
'KEEP',
|
'KEEP',
|
||||||
'ZERO',
|
'ZERO',
|
||||||
|
@ -429,24 +488,27 @@ make.webgl = {
|
||||||
'INVERT'
|
'INVERT'
|
||||||
]
|
]
|
||||||
return random.item(action)
|
return random.item(action)
|
||||||
},
|
}
|
||||||
randomQueryTarget: (isWebGL2) => {
|
|
||||||
|
static randomQueryTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'ANY_SAMPLES_PASSED',
|
'ANY_SAMPLES_PASSED',
|
||||||
'ANY_SAMPLES_PASSED_CONSERVATIVE',
|
'ANY_SAMPLES_PASSED_CONSERVATIVE',
|
||||||
'TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN'
|
'TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN'
|
||||||
]
|
]
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomQueryPname: (isWebGL2) => {
|
|
||||||
|
static randomQueryPname (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'CURRENT_QUERY',
|
'CURRENT_QUERY',
|
||||||
'QUERY_RESULT',
|
'QUERY_RESULT',
|
||||||
'QUERY_RESULT_AVAILABLE'
|
'QUERY_RESULT_AVAILABLE'
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomSamplerParameter: (isWebGL2) => {
|
|
||||||
|
static randomSamplerParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'TEXTURE_MAG_FILTER',
|
'TEXTURE_MAG_FILTER',
|
||||||
'TEXTURE_MIN_FILTER',
|
'TEXTURE_MIN_FILTER',
|
||||||
|
@ -462,8 +524,9 @@ make.webgl = {
|
||||||
'TEXTURE_MAX_ANISOTROPY_EXT'
|
'TEXTURE_MAX_ANISOTROPY_EXT'
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomSyncParameter: (isWebGL2) => {
|
|
||||||
|
static randomSyncParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'OBJECT_TYPE',
|
'OBJECT_TYPE',
|
||||||
'SYNC_STATUS',
|
'SYNC_STATUS',
|
||||||
|
@ -471,8 +534,9 @@ make.webgl = {
|
||||||
'SYNC_FLAGS'
|
'SYNC_FLAGS'
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomClearBuffer: (isWebGL2) => {
|
|
||||||
|
static randomClearBuffer (isWebGL2) {
|
||||||
let buffer = [
|
let buffer = [
|
||||||
'COLOR',
|
'COLOR',
|
||||||
'DEPTH',
|
'DEPTH',
|
||||||
|
@ -480,15 +544,17 @@ make.webgl = {
|
||||||
'DEPTH_STENCIL'
|
'DEPTH_STENCIL'
|
||||||
]
|
]
|
||||||
return random.item(buffer)
|
return random.item(buffer)
|
||||||
},
|
}
|
||||||
randomBindBufferTarget: (isWebGL2) => {
|
|
||||||
|
static randomBindBufferTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'TRANSFORM_FEEDBACK_BUFFER',
|
'TRANSFORM_FEEDBACK_BUFFER',
|
||||||
'UNIFORM_BUFFER'
|
'UNIFORM_BUFFER'
|
||||||
]
|
]
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomIndexedParameterTarget: (isWebGL2) => {
|
|
||||||
|
static randomIndexedParameterTarget (isWebGL2) {
|
||||||
let target = [
|
let target = [
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_BINDING',
|
'TRANSFORM_FEEDBACK_BUFFER_BINDING',
|
||||||
'TRANSFORM_FEEDBACK_BUFFER_SIZE',
|
'TRANSFORM_FEEDBACK_BUFFER_SIZE',
|
||||||
|
@ -498,8 +564,9 @@ make.webgl = {
|
||||||
'UNIFORM_BUFFER_START'
|
'UNIFORM_BUFFER_START'
|
||||||
]
|
]
|
||||||
return random.item(target)
|
return random.item(target)
|
||||||
},
|
}
|
||||||
randomUniformParameter: (isWebGL2) => {
|
|
||||||
|
static randomUniformParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'UNIFORM_TYPE',
|
'UNIFORM_TYPE',
|
||||||
'UNIFORM_SIZE',
|
'UNIFORM_SIZE',
|
||||||
|
@ -510,8 +577,9 @@ make.webgl = {
|
||||||
'UNIFORM_IS_ROW_MAJOR'
|
'UNIFORM_IS_ROW_MAJOR'
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomUniformBlockParameter: (isWebGL2) => {
|
|
||||||
|
static randomUniformBlockParameter (isWebGL2) {
|
||||||
let pname = [
|
let pname = [
|
||||||
'UNIFORM_BLOCK_BINDING',
|
'UNIFORM_BLOCK_BINDING',
|
||||||
'UNIFORM_BLOCK_DATA_SIZE',
|
'UNIFORM_BLOCK_DATA_SIZE',
|
||||||
|
@ -521,8 +589,9 @@ make.webgl = {
|
||||||
'UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER'
|
'UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER'
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
},
|
}
|
||||||
randomPixelDatatype: (isWebGL2) => {
|
|
||||||
|
static randomPixelDatatype (isWebGL2) {
|
||||||
let type = [
|
let type = [
|
||||||
'UNSIGNED_BYTE',
|
'UNSIGNED_BYTE',
|
||||||
'UNSIGNED_SHORT',
|
'UNSIGNED_SHORT',
|
||||||
|
@ -533,8 +602,9 @@ make.webgl = {
|
||||||
'FLOAT'
|
'FLOAT'
|
||||||
]
|
]
|
||||||
return random.item(type)
|
return random.item(type)
|
||||||
},
|
}
|
||||||
randomBufferUsage: (isWebGL2) => {
|
|
||||||
|
static randomBufferUsage (isWebGL2) {
|
||||||
let usage = [
|
let usage = [
|
||||||
'STATIC_DRAW',
|
'STATIC_DRAW',
|
||||||
'DYNAMIC_DRAW',
|
'DYNAMIC_DRAW',
|
||||||
|
@ -739,4 +809,234 @@ make.webgl = {
|
||||||
]
|
]
|
||||||
return random.item(pname)
|
return random.item(pname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static randomParameter (isWebGL2) {
|
||||||
|
let pname = [
|
||||||
|
'ACTIVE_TEXTURE',
|
||||||
|
'ALIASED_LINE_WIDTH_RANGE',
|
||||||
|
'ALIASED_POINT_SIZE_RANGE',
|
||||||
|
'ALPHA_BITS',
|
||||||
|
'ARRAY_BUFFER_BINDING',
|
||||||
|
'BLEND',
|
||||||
|
'BLEND_COLOR',
|
||||||
|
'BLEND_DST_ALPHA',
|
||||||
|
'BLEND_DST_RGB',
|
||||||
|
'BLEND_EQUATION_ALPHA',
|
||||||
|
'BLEND_EQUATION_RGB',
|
||||||
|
'BLEND_SRC_ALPHA',
|
||||||
|
'BLEND_SRC_RGB',
|
||||||
|
'BLUE_BITS',
|
||||||
|
'COLOR_CLEAR_VALUE',
|
||||||
|
'COLOR_WRITEMASK',
|
||||||
|
'COMPRESSED_TEXTURE_FORMATS',
|
||||||
|
'CULL_FACE',
|
||||||
|
'CULL_FACE_MODE',
|
||||||
|
'CURRENT_PROGRAM',
|
||||||
|
'DEPTH_BITS',
|
||||||
|
'DEPTH_CLEAR_VALUE',
|
||||||
|
'DEPTH_FUNC',
|
||||||
|
'DEPTH_RANGE',
|
||||||
|
'DEPTH_TEST',
|
||||||
|
'DEPTH_WRITEMASK',
|
||||||
|
'DITHER',
|
||||||
|
'ELEMENT_ARRAY_BUFFER_BINDING',
|
||||||
|
'FRAMEBUFFER_BINDING',
|
||||||
|
'FRONT_FACE',
|
||||||
|
'GENERATE_MIPMAP_HINT',
|
||||||
|
'GREEN_BITS',
|
||||||
|
'IMPLEMENTATION_COLOR_READ_FORMAT',
|
||||||
|
'IMPLEMENTATION_COLOR_READ_TYPE',
|
||||||
|
'LINE_WIDTH',
|
||||||
|
'MAX_COMBINED_TEXTURE_IMAGE_UNITS',
|
||||||
|
'MAX_CUBE_MAP_TEXTURE_SIZE',
|
||||||
|
'MAX_FRAGMENT_UNIFORM_VECTORS',
|
||||||
|
'MAX_RENDERBUFFER_SIZE',
|
||||||
|
'MAX_TEXTURE_IMAGE_UNITS',
|
||||||
|
'MAX_TEXTURE_SIZE',
|
||||||
|
'MAX_VARYING_VECTORS',
|
||||||
|
'MAX_VERTEX_ATTRIBS',
|
||||||
|
'MAX_VERTEX_TEXTURE_IMAGE_UNITS',
|
||||||
|
'MAX_VERTEX_UNIFORM_VECTORS',
|
||||||
|
'MAX_VIEWPORT_DIMS',
|
||||||
|
'PACK_ALIGNMENT',
|
||||||
|
'POLYGON_OFFSET_FACTOR',
|
||||||
|
'POLYGON_OFFSET_FILL',
|
||||||
|
'POLYGON_OFFSET_UNITS',
|
||||||
|
'RED_BITS',
|
||||||
|
'RENDERBUFFER_BINDING',
|
||||||
|
'RENDERER',
|
||||||
|
'SAMPLE_ALPHA_TO_COVERAGE',
|
||||||
|
'SAMPLE_BUFFERS',
|
||||||
|
'SAMPLE_COVERAGE',
|
||||||
|
'SAMPLE_COVERAGE_INVERT',
|
||||||
|
'SAMPLE_COVERAGE_VALUE',
|
||||||
|
'SAMPLES',
|
||||||
|
'SCISSOR_BOX',
|
||||||
|
'SCISSOR_TEST',
|
||||||
|
'SHADING_LANGUAGE_VERSION',
|
||||||
|
'STENCIL_BACK_FAIL',
|
||||||
|
'STENCIL_BACK_FUNC',
|
||||||
|
'STENCIL_BACK_PASS_DEPTH_FAIL',
|
||||||
|
'STENCIL_BACK_PASS_DEPTH_PASS',
|
||||||
|
'STENCIL_BACK_REF',
|
||||||
|
'STENCIL_BACK_VALUE_MASK',
|
||||||
|
'STENCIL_BACK_WRITEMASK',
|
||||||
|
'STENCIL_BITS',
|
||||||
|
'STENCIL_CLEAR_VALUE',
|
||||||
|
'STENCIL_FAIL',
|
||||||
|
'STENCIL_FUNC',
|
||||||
|
'STENCIL_PASS_DEPTH_FAIL',
|
||||||
|
'STENCIL_PASS_DEPTH_PASS',
|
||||||
|
'STENCIL_REF',
|
||||||
|
'STENCIL_TEST',
|
||||||
|
'STENCIL_VALUE_MASK',
|
||||||
|
'STENCIL_WRITEMASK',
|
||||||
|
'SUBPIXEL_BITS',
|
||||||
|
'TEXTURE_BINDING_2D',
|
||||||
|
'TEXTURE_BINDING_CUBE_MAP',
|
||||||
|
'UNPACK_ALIGNMENT',
|
||||||
|
'UNPACK_COLORSPACE_CONVERSION_WEBGL',
|
||||||
|
'UNPACK_FLIP_Y_WEBGL',
|
||||||
|
'UNPACK_PREMULTIPLY_ALPHA_WEBGL',
|
||||||
|
'VENDOR',
|
||||||
|
'VERSION',
|
||||||
|
'VIEWPORT',
|
||||||
|
'VERSION',
|
||||||
|
'SHADING_LANGUAGE_VERSION',
|
||||||
|
'VENDOR',
|
||||||
|
'RENDERER'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (isWebGL2) {
|
||||||
|
pname.extend([
|
||||||
|
'COPY_READ_BUFFER_BINDING',
|
||||||
|
'COPY_WRITE_BUFFER_BINDING',
|
||||||
|
'DRAW_BUFFERi',
|
||||||
|
'DRAW_FRAMEBUFFER_BINDING',
|
||||||
|
'FRAGMENT_SHADER_DERIVATIVE_HINT',
|
||||||
|
'MAX_3D_TEXTURE_SIZE',
|
||||||
|
'MAX_ARRAY_TEXTURE_LAYERS',
|
||||||
|
'MAX_CLIENT_WAIT_TIMEOUT_WEBGL',
|
||||||
|
'MAX_COLOR_ATTACHMENTS',
|
||||||
|
'MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS',
|
||||||
|
'MAX_COMBINED_UNIFORM_BLOCKS',
|
||||||
|
'MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS',
|
||||||
|
'MAX_DRAW_BUFFERS',
|
||||||
|
'MAX_ELEMENT_INDEX',
|
||||||
|
'MAX_ELEMENTS_INDICE',
|
||||||
|
'MAX_ELEMENTS_VERTICES',
|
||||||
|
'MAX_FRAGMENT_INPUT_COMPONENTS',
|
||||||
|
'MAX_FRAGMENT_UNIFORM_BLOCKS',
|
||||||
|
'MAX_FRAGMENT_UNIFORM_COMPONENTS',
|
||||||
|
'MAX_PROGRAM_TEXEL_OFFSET',
|
||||||
|
'MAX_SAMPLES',
|
||||||
|
'MAX_SERVER_WAIT_TIMEOUT',
|
||||||
|
'MAX_TEXTURE_LOD_BIAS',
|
||||||
|
'MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS',
|
||||||
|
'MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS',
|
||||||
|
'MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS',
|
||||||
|
'MAX_UNIFORM_BLOCK_SIZE',
|
||||||
|
'MAX_UNIFORM_BUFFER_BINDINGS',
|
||||||
|
'MAX_VARYING_COMPONENTS',
|
||||||
|
'MAX_VERTEX_OUTPUT_COMPONENTS',
|
||||||
|
'MAX_VERTEX_UNIFORM_BLOCKS',
|
||||||
|
'MAX_VERTEX_UNIFORM_COMPONENTS',
|
||||||
|
'MIN_PROGRAM_TEXEL_OFFSET',
|
||||||
|
'PACK_ROW_LENGTH',
|
||||||
|
'PACK_SKIP_PIXELS',
|
||||||
|
'PACK_SKIP_ROWS',
|
||||||
|
'PIXEL_PACK_BUFFER_BINDING',
|
||||||
|
'PIXEL_UNPACK_BUFFER_BINDING',
|
||||||
|
'RASTERIZER_DISCARD',
|
||||||
|
'READ_BUFFER',
|
||||||
|
'READ_FRAMEBUFFER_BINDING',
|
||||||
|
'SAMPLER_BINDING',
|
||||||
|
'TEXTURE_BINDING_2D_ARRAY',
|
||||||
|
'TEXTURE_BINDING_3D',
|
||||||
|
'TRANSFORM_FEEDBACK_ACTIVE',
|
||||||
|
'TRANSFORM_FEEDBACK_BINDING',
|
||||||
|
'TRANSFORM_FEEDBACK_BUFFER_BINDING',
|
||||||
|
'TRANSFORM_FEEDBACK_PAUSED',
|
||||||
|
'UNIFORM_BUFFER_BINDING',
|
||||||
|
'UNIFORM_BUFFER_OFFSET_ALIGNMENT',
|
||||||
|
'UNPACK_IMAGE_HEIGHT',
|
||||||
|
'UNPACK_ROW_LENGTH',
|
||||||
|
'UNPACK_SKIP_IMAGES',
|
||||||
|
'UNPACK_SKIP_PIXELS',
|
||||||
|
'UNPACK_SKIP_ROWS',
|
||||||
|
'VERTEX_ARRAY_BINDING'
|
||||||
|
])
|
||||||
|
}
|
||||||
|
return random.item(pname)
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomProgramParameter () {
|
||||||
|
let pname = [
|
||||||
|
'DELETE_STATUS',
|
||||||
|
'LINK_STATUS',
|
||||||
|
'VALIDATE_STATUS',
|
||||||
|
'ATTACHED_SHADERS',
|
||||||
|
'ACTIVE_ATTRIBUTES',
|
||||||
|
'ACTIVE_UNIFORMS',
|
||||||
|
'TRANSFORM_FEEDBACK_BUFFER_MODE',
|
||||||
|
'TRANSFORM_FEEDBACK_VARYINGS',
|
||||||
|
'ACTIVE_UNIFORM_BLOCKS'
|
||||||
|
]
|
||||||
|
return random.item(pname)
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomRenderBufferParameter () {
|
||||||
|
let pname = [
|
||||||
|
'RENDERBUFFER_WIDTH',
|
||||||
|
'RENDERBUFFER_HEIGHT',
|
||||||
|
'RENDERBUFFER_INTERNAL_FORMAT',
|
||||||
|
'RENDERBUFFER_RED_SIZE',
|
||||||
|
'RENDERBUFFER_GREEN_SIZE',
|
||||||
|
'RENDERBUFFER_BLUE_SIZE',
|
||||||
|
'RENDERBUFFER_ALPHA_SIZE',
|
||||||
|
'RENDERBUFFER_DEPTH_SIZE',
|
||||||
|
'RENDERBUFFER_STENCIL_SIZE'
|
||||||
|
]
|
||||||
|
return random.item(pname)
|
||||||
|
}
|
||||||
|
|
||||||
|
static randomExtension (pattern) {
|
||||||
|
let extensions = [
|
||||||
|
'ANGLE_instanced_arrays',
|
||||||
|
'EXT_blend_minmax',
|
||||||
|
'EXT_color_buffer_half_float',
|
||||||
|
'EXT_frag_depth',
|
||||||
|
'EXT_sRGB',
|
||||||
|
'EXT_shader_texture_lod',
|
||||||
|
'EXT_texture_filter_anisotropic',
|
||||||
|
'EXT_disjoint_timer_query',
|
||||||
|
'OES_element_index_uint',
|
||||||
|
'OES_standard_derivatives',
|
||||||
|
'OES_texture_float',
|
||||||
|
'OES_texture_float_linear',
|
||||||
|
'OES_texture_half_float',
|
||||||
|
'OES_texture_half_float_linear',
|
||||||
|
'OES_vertex_array_object',
|
||||||
|
'WEBGL_color_buffer_float',
|
||||||
|
'WEBGL_compressed_texture_s3tc',
|
||||||
|
'WEBGL_compressed_texture_s3tc_srgb',
|
||||||
|
'WEBGL_debug_renderer_info',
|
||||||
|
'WEBGL_debug_shaders',
|
||||||
|
'WEBGL_depth_texture',
|
||||||
|
'WEBGL_draw_buffers',
|
||||||
|
'WEBGL_lose_context'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (pattern) {
|
||||||
|
let candidates = []
|
||||||
|
extensions.forEach((ext) => ext.includes(pattern) ? candidates.push(ext) : '')
|
||||||
|
if (candidates.length >= 0) {
|
||||||
|
return random.item(candidates)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.item(extensions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = webgl
|
||||||
|
|
5
lib/random/index.js
Normal file
5
lib/random/index.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
module.exports = require('./random')
|
|
@ -9,67 +9,68 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function MersenneTwister () { // eslint-disable-line no-unused-vars
|
class MersenneTwister {
|
||||||
const N = 624
|
constructor () {
|
||||||
const M = 397
|
this.N = 624
|
||||||
const UPPER_MASK = 0x80000000
|
this.M = 397
|
||||||
const LOWER_MASK = 0x7fffffff
|
this.UPPER_MASK = 0x80000000
|
||||||
const MAG01 = new Int32Array([0, 0x9908b0df])
|
this.LOWER_MASK = 0x7fffffff
|
||||||
|
this.MAG01 = new Int32Array([0, 0x9908b0df])
|
||||||
|
|
||||||
let mt = new Int32Array(N)
|
this.mt = new Int32Array(this.N)
|
||||||
/* the array for the state vector */
|
this.mti = 625 // The array for the state vector.
|
||||||
let mti = 625
|
}
|
||||||
|
|
||||||
this.seed = function (s) {
|
seed (s) {
|
||||||
mt[0] = s | 0
|
this.mt[0] = s | 0
|
||||||
for (mti = 1; mti < N; mti++) {
|
for (this.mti = 1; this.mti < this.N; this.mti++) {
|
||||||
mt[mti] = Math.imul(1812433253, mt[mti - 1] ^ (mt[mti - 1] >>> 30)) + mti
|
this.mt[this.mti] = Math.imul(1812433253, this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30)) + this.mti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export_state = function () {
|
export_state () { // eslint-disable-line camelcase
|
||||||
return [mt, mti]
|
return [this.mt, this.mti]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.import_state = function (s) {
|
import_state (s) { // eslint-disable-line camelcase
|
||||||
mt = s[0]
|
this.mt = s[0]
|
||||||
mti = s[1]
|
this.mti = s[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export_mta = function () {
|
export_mta () { // eslint-disable-line camelcase
|
||||||
return mt
|
return this.mt
|
||||||
}
|
}
|
||||||
|
|
||||||
this.import_mta = function (_mta) {
|
import_mta (_mta) { // eslint-disable-line camelcase
|
||||||
mt = _mta
|
this.mt = _mta
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export_mti = function () {
|
export_mti () { // eslint-disable-line camelcase
|
||||||
return mti
|
return this.mti
|
||||||
}
|
}
|
||||||
|
|
||||||
this.import_mti = function (_mti) {
|
import_mti (_mti) { // eslint-disable-line camelcase
|
||||||
mti = _mti
|
this.mti = _mti
|
||||||
}
|
}
|
||||||
|
|
||||||
this.int32 = function () {
|
int32 () {
|
||||||
let y, kk
|
let y, kk
|
||||||
|
|
||||||
if (mti >= N) { /* generate N words at one time */
|
if (this.mti >= this.N) { /* generate N words at one time */
|
||||||
for (kk = 0; kk < N - M; kk++) {
|
for (kk = 0; kk < this.N - this.M; kk++) {
|
||||||
y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK))
|
y = ((this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK))
|
||||||
mt[kk] = (mt[kk + M] ^ (y >>> 1) ^ MAG01[y & 0x1])
|
this.mt[kk] = (this.mt[kk + this.M] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
||||||
}
|
}
|
||||||
for (; kk < N - 1; kk++) {
|
for (; kk < this.N - 1; kk++) {
|
||||||
y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK))
|
y = ((this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK))
|
||||||
mt[kk] = (mt[kk + (M - N)] ^ (y >>> 1) ^ MAG01[y & 0x1])
|
this.mt[kk] = (this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
||||||
}
|
}
|
||||||
y = ((mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK))
|
y = ((this.mt[this.N - 1] & this.UPPER_MASK) | (this.mt[0] & this.LOWER_MASK))
|
||||||
mt[N - 1] = (mt[M - 1] ^ (y >>> 1) ^ MAG01[y & 0x1])
|
this.mt[this.N - 1] = (this.mt[this.M - 1] ^ (y >>> 1) ^ this.MAG01[y & 0x1])
|
||||||
mti = 0
|
this.mti = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
y = mt[mti++]
|
y = this.mt[this.mti++]
|
||||||
|
|
||||||
/* Tempering */
|
/* Tempering */
|
||||||
y = y ^ (y >>> 11)
|
y = y ^ (y >>> 11)
|
||||||
|
@ -80,7 +81,9 @@ function MersenneTwister () { // eslint-disable-line no-unused-vars
|
||||||
return y >>> 0
|
return y >>> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
this.real2 = function () {
|
real2 () {
|
||||||
return ((this.int32() >>> 5) * 67108864.0 + (this.int32() >>> 6)) / 9007199254740992.0
|
return ((this.int32() >>> 5) * 67108864.0 + (this.int32() >>> 6)) / 9007199254740992.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = MersenneTwister
|
||||||
|
|
|
@ -2,167 +2,264 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
var random = { // eslint-disable-line no-unused-vars
|
const MersenneTwister = require('./mersennetwister')
|
||||||
seed: null,
|
const {logger} = require('../logging')
|
||||||
twister: null,
|
|
||||||
|
class random {
|
||||||
|
/**
|
||||||
|
* Must be called before any other methods can be called to initialize MersenneTwister
|
||||||
|
* @param {number|null|undefined} seed - Value to initialize MersenneTwister
|
||||||
|
*/
|
||||||
|
static init (seed) {
|
||||||
|
if (seed === null || seed === undefined) {
|
||||||
|
random.seed = new Date().getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
random.twister = new MersenneTwister()
|
||||||
|
random.twister.seed(random.seed)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must be called before any other methods can be called to initialize MersenneTwister.
|
* Returns an integer in [0, limit) (uniform distribution)
|
||||||
* @param {number|null|undefined} seed Value to initialize MersenneTwister.
|
* @param {number} limit
|
||||||
*/
|
*/
|
||||||
init: function (seed) {
|
static number (limit) {
|
||||||
if (seed === null || seed === undefined) {
|
if (!random.twister) {
|
||||||
this.seed = new Date().getTime()
|
throw new Error('random.init must be called first.')
|
||||||
}
|
|
||||||
this.twister = new MersenneTwister()
|
|
||||||
this.twister.seed(this.seed)
|
|
||||||
},
|
|
||||||
number: function (limit) {
|
|
||||||
// Returns an integer in [0, limit). Uniform distribution.
|
|
||||||
if (limit === 0) {
|
|
||||||
return limit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (limit === null || limit === undefined) {
|
if (limit === null || limit === undefined) {
|
||||||
limit = 0xffffffff
|
limit = 0xffffffff
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = (0x100000000 / limit) >>> 0
|
let x = (0x100000000 / limit) >>> 0
|
||||||
let y = (x * limit) >>> 0
|
let y = (x * limit) >>> 0
|
||||||
let r
|
let r
|
||||||
do {
|
do {
|
||||||
r = this.twister.int32()
|
r = random.twister.int32()
|
||||||
} while (y && r >= y) // eslint-disable-line no-unmodified-loop-condition
|
} while (y && r >= y) // eslint-disable-line no-unmodified-loop-condition
|
||||||
return (r / x) >>> 0
|
return (r / x) >>> 0
|
||||||
},
|
}
|
||||||
float: function () {
|
|
||||||
// Returns a float in [0, 1). Uniform distribution.
|
/**
|
||||||
return this.twister.real2()
|
* Returns a float in [0, 1) (uniform distribution)
|
||||||
},
|
*/
|
||||||
range: function (start, limit) {
|
static float () {
|
||||||
// Returns an integer in [start, limit]. Uniform distribution.
|
if (!random.twister) {
|
||||||
if (isNaN(start) || isNaN(limit)) {
|
throw new Error('random.init must be called first.')
|
||||||
logger.traceback()
|
|
||||||
throw new TypeError('random.range() received a non number type: \'' + start + '\', \'' + limit + '\')')
|
|
||||||
}
|
|
||||||
return this.number(limit - start + 1) + start
|
|
||||||
},
|
|
||||||
ludOneTo: function (limit) {
|
|
||||||
// Returns a float in [1, limit]. The logarithm has uniform distribution.
|
|
||||||
return Math.exp(this.float() * Math.log(limit))
|
|
||||||
},
|
|
||||||
item: function (list) {
|
|
||||||
if (list === undefined || typeof list === 'string' || list.length === undefined) {
|
|
||||||
logger.traceback()
|
|
||||||
throw new TypeError('random.item() received an invalid object: \'' + list + '\'')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list[this.number(list.length)]
|
return random.twister.real2()
|
||||||
},
|
}
|
||||||
key: function (obj) {
|
|
||||||
let list = []
|
/**
|
||||||
for (let i in obj) {
|
* Returns an integer in [start, limit) (uniform distribution)
|
||||||
list.push(i)
|
* @param {number} start
|
||||||
|
* @param {number} limit
|
||||||
|
*/
|
||||||
|
static range (start, limit) {
|
||||||
|
if (!random.twister) {
|
||||||
|
throw new Error('random.init must be called first.')
|
||||||
}
|
}
|
||||||
return this.item(list)
|
|
||||||
},
|
if (isNaN(start) || isNaN(limit)) {
|
||||||
bool: function () {
|
logger.traceback()
|
||||||
return this.item([true, false])
|
throw new TypeError(`random.range() received non-number type: (${start}, ${limit})`)
|
||||||
},
|
}
|
||||||
pick: function (obj) {
|
|
||||||
|
return random.number(limit - start + 1) + start
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a float in [1, limit). The logarithm has uniform distribution.
|
||||||
|
* @param {number} limit
|
||||||
|
*/
|
||||||
|
static ludOneTo (limit) {
|
||||||
|
return Math.exp(random.float() * Math.log(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random index from a list
|
||||||
|
* @param {Array} list
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static item (list) {
|
||||||
|
if (!Array.isArray(list)) {
|
||||||
|
logger.traceback()
|
||||||
|
throw new TypeError(`random.item() received invalid object: (${list})`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return list[random.number(list.length)]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random key of a provided object
|
||||||
|
* @param {Object} obj
|
||||||
|
*/
|
||||||
|
static key (obj) {
|
||||||
|
return random.item(Object.keys(obj))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a random Boolean value
|
||||||
|
*/
|
||||||
|
static bool () {
|
||||||
|
return random.item([true, false])
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively iterate over array until non-array item identified
|
||||||
|
* If item is a function, evaluate it with no args
|
||||||
|
* @param {*} obj
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static pick (obj) {
|
||||||
if (typeof obj === 'function') {
|
if (typeof obj === 'function') {
|
||||||
return obj()
|
return obj()
|
||||||
|
} else if (Array.isArray(obj)) {
|
||||||
|
return random.pick(random.item(obj))
|
||||||
}
|
}
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return this.pick(this.item(obj))
|
|
||||||
}
|
|
||||||
return obj
|
return obj
|
||||||
},
|
}
|
||||||
chance: function (limit) {
|
|
||||||
if (limit === null || limit === undefined) {
|
/**
|
||||||
limit = 2
|
* Returns a boolean result based on limit
|
||||||
}
|
* @param limit
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
static chance (limit = 2) {
|
||||||
if (isNaN(limit)) {
|
if (isNaN(limit)) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('random.chance() received a non number type: \'' + limit + '\'')
|
throw new TypeError(`random.chance() received non-number type: (${limit})`)
|
||||||
}
|
}
|
||||||
return this.number(limit) === 1
|
|
||||||
},
|
return random.number(limit) === 1
|
||||||
choose: function (list, flat) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an item from an array of arrays where the first index in each sub-array denotes the weight
|
||||||
|
* @param {Array} list - Array of arrays
|
||||||
|
* @param {Boolean} flat - Indicates whether we should iterate over the arrays recursively
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static choose (list, flat = false) {
|
||||||
if (!(Array.isArray(list))) {
|
if (!(Array.isArray(list))) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('random.choose() received a non-array type: \'' + list + '\'')
|
throw new TypeError(`random.choose() received non-array type: (${list})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
let total = 0
|
let total = 0
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
total += list[i][0]
|
total += list[i][0]
|
||||||
}
|
}
|
||||||
let n = this.number(total)
|
|
||||||
|
let n = random.number(total)
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
if (n < list[i][0]) {
|
if (n < list[i][0]) {
|
||||||
if (flat === true) {
|
if (flat === true) {
|
||||||
return list[i][1]
|
return list[i][1]
|
||||||
} else {
|
} else {
|
||||||
return this.pick([list[i][1]])
|
return random.pick([list[i][1]])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = n - list[i][0]
|
n = n - list[i][0]
|
||||||
}
|
}
|
||||||
if (flat === true) {
|
|
||||||
|
if (flat) {
|
||||||
return list[0][1]
|
return list[0][1]
|
||||||
}
|
}
|
||||||
return this.pick([list[0][1]])
|
|
||||||
},
|
return random.pick([list[0][1]])
|
||||||
weighted: function (wa) {
|
}
|
||||||
// More memory-hungry but hopefully faster than random.choose$flat
|
|
||||||
|
/**
|
||||||
|
* More memory-hungry but hopefully faster than random.choose$flat.
|
||||||
|
* @param {*} wa
|
||||||
|
*/
|
||||||
|
static weighted (wa) {
|
||||||
let a = []
|
let a = []
|
||||||
for (let i = 0; i < wa.length; ++i) {
|
for (let i = 0; i < wa.length; ++i) {
|
||||||
for (let j = 0; j < wa[i].w; ++j) {
|
for (let j = 0; j < wa[i].w; ++j) {
|
||||||
a.push(wa[i].v)
|
a.push(wa[i].v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return a
|
return a
|
||||||
},
|
}
|
||||||
use: function (obj) {
|
|
||||||
return this.bool() ? obj : ''
|
static use (obj) {
|
||||||
},
|
return random.bool() ? obj : ''
|
||||||
shuffle: function (arr) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns arr shuffled
|
||||||
|
* @param arr
|
||||||
|
*/
|
||||||
|
static shuffle (arr) {
|
||||||
let i = arr.length
|
let i = arr.length
|
||||||
while (i--) {
|
while (i--) {
|
||||||
let p = this.number(i + 1)
|
let p = random.number(i + 1)
|
||||||
let t = arr[i]
|
let t = arr[i]
|
||||||
arr[i] = arr[p]
|
arr[i] = arr[p]
|
||||||
arr[p] = t
|
arr[p] = t
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
shuffled: function (arr) {
|
|
||||||
|
/**
|
||||||
|
* Returns a shuffled copy of arr
|
||||||
|
* @param arr
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static shuffled (arr) {
|
||||||
let newArray = arr.slice()
|
let newArray = arr.slice()
|
||||||
this.shuffle(newArray)
|
random.shuffle(newArray)
|
||||||
return newArray
|
return newArray
|
||||||
},
|
}
|
||||||
subset: function (list, limit) {
|
|
||||||
|
/**
|
||||||
|
* Select an array containing a subset of 'list'
|
||||||
|
* @param list
|
||||||
|
* @param limit
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
static subset (list, limit) {
|
||||||
if (!(Array.isArray(list))) {
|
if (!(Array.isArray(list))) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('random.subset() received a non-array type: \'' + list + '\'')
|
throw new TypeError(`random.subset() received non-array type: (${list})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof limit !== 'number') {
|
if (typeof limit !== 'number') {
|
||||||
limit = this.number(list.length + 1)
|
limit = random.number(list.length + 1)
|
||||||
}
|
}
|
||||||
let result = []
|
|
||||||
for (let i = 0; i < limit; i++) {
|
// Deepclone list
|
||||||
result.push(this.pick(list))
|
const temp = JSON.parse(JSON.stringify(list))
|
||||||
|
const result = []
|
||||||
|
while (limit--) {
|
||||||
|
result.push(random.pop(temp))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
},
|
}
|
||||||
pop: function (arr) {
|
|
||||||
// Removes and returns a random item from an array
|
/**
|
||||||
|
* Removes and returns a random item from an array.
|
||||||
|
* @param {*} arr
|
||||||
|
*/
|
||||||
|
static pop (arr) {
|
||||||
let i, obj
|
let i, obj
|
||||||
|
|
||||||
i = this.number(arr.length)
|
i = random.number(arr.length)
|
||||||
obj = arr[i]
|
obj = arr[i]
|
||||||
arr.splice(i, 1)
|
arr.splice(i, 1)
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
},
|
}
|
||||||
hex: function (len) {
|
|
||||||
return this.number(Math.pow(2, len * 4)).toString(16)
|
static hex (len) {
|
||||||
|
return random.number(Math.pow(2, len * 4)).toString(16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = random
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
utils.block = {
|
const random = require('../random')
|
||||||
block: function (list, optional) {
|
const utils = require('../utils')
|
||||||
|
|
||||||
|
class block extends utils {
|
||||||
|
static block (list, optional) {
|
||||||
if (optional === true) {
|
if (optional === true) {
|
||||||
if (random.chance(6)) {
|
if (random.chance(6)) {
|
||||||
return ''
|
return ''
|
||||||
|
@ -38,3 +41,5 @@ utils.block = {
|
||||||
return asString
|
return asString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = block
|
||||||
|
|
|
@ -1,71 +1,110 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
const jsesc = require('jsesc')
|
||||||
|
const utils = require('../utils')
|
||||||
|
|
||||||
utils.common = {
|
class common extends utils {
|
||||||
objToString: function (obj) {
|
/**
|
||||||
|
* Return stringified object
|
||||||
|
* @param obj
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static objToString (obj) {
|
||||||
try {
|
try {
|
||||||
return '' + obj
|
return `${obj}`
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return '[' + e + ']'
|
return `[${e}]`
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
getAllProperties: function (obj) {
|
|
||||||
|
/**
|
||||||
|
* Return enumerable properties recursively
|
||||||
|
* @param obj
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
static getAllProperties (obj) {
|
||||||
let list = []
|
let list = []
|
||||||
while (obj) {
|
while (obj) {
|
||||||
list = list.concat(Object.getOwnPropertyNames(obj))
|
list = list.concat(Object.getOwnPropertyNames(obj))
|
||||||
obj = Object.getPrototypeOf(obj)
|
obj = Object.getPrototypeOf(obj)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
},
|
}
|
||||||
getKeysFromHash: function (obj) {
|
|
||||||
|
/**
|
||||||
|
* Return all properties (non-recursive)
|
||||||
|
* @param obj
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
static getKeysFromHash (obj) {
|
||||||
let list = []
|
let list = []
|
||||||
for (let p in obj) {
|
for (let p in obj) {
|
||||||
list.push(p)
|
list.push(p)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
},
|
}
|
||||||
quote: function (s) {
|
|
||||||
// Taken from DOMfuzz
|
/**
|
||||||
function escapeString (s) {
|
* Escape and quote a string
|
||||||
return ('\"' + // eslint-disable-line no-useless-escape
|
* @param s - String to be quoted
|
||||||
s.replace(/\\/g, '\\\\')
|
* @param {boolean} html - Identifies whether the string must be HTML safe
|
||||||
.replace(/\"/g, '\\\"') // eslint-disable-line no-useless-escape
|
* @returns {*}
|
||||||
.replace(/\0/g, '\\0')
|
*/
|
||||||
.replace(/\n/g, '\\n') +
|
static quote (s, html = false) {
|
||||||
'\"') // eslint-disable-line no-useless-escape
|
const options = {
|
||||||
|
minimal: true,
|
||||||
|
isScriptContext: html
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof s === 'string') {
|
if (typeof s === 'string') {
|
||||||
if (/^[\n\x20-\x7f]*$/.exec(s) || !self.uneval) { // eslint-disable-line no-undef
|
return `'${jsesc(s, options)}'`
|
||||||
// Printable ASCII characters and line breaks: try to make it pretty.
|
|
||||||
return escapeString(s)
|
|
||||||
} else {
|
|
||||||
// Non-ASCII: use uneval to get \u escapes.
|
|
||||||
return uneval(s) // eslint-disable-line no-undef
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// For other things (such as numbers, |null|, and |undefined|), just coerce to string.
|
return jsesc(s, options)
|
||||||
return JSON.stringify(s)
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
b64encode: function (str) {
|
|
||||||
// Unicode safe b64 encoding
|
/**
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
* Unicode safe b64 encoding
|
||||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
||||||
function toSolidBytes (match, p1) {
|
* @param {string} str
|
||||||
// noinspection JSCheckFunctionSignatures
|
* @returns {*}
|
||||||
return String.fromCharCode('0x' + p1)
|
*/
|
||||||
}))
|
static b64encode (str) {
|
||||||
},
|
if (process.browser) {
|
||||||
b64decode: function (str) {
|
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
|
||||||
// Unicode safe b64 decoding
|
function toSolidBytes (match, p1) {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
// noinspection JSCheckFunctionSignatures
|
||||||
return decodeURIComponent(atob(str).split('').map(function (c) {
|
return String.fromCharCode('0x' + p1)
|
||||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
|
})
|
||||||
}).join(''))
|
)
|
||||||
},
|
} else {
|
||||||
uniqueList: function (list) {
|
return Buffer.from(str).toString('base64')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unicode safe b64 decoding
|
||||||
|
* https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
||||||
|
* @param {string} str
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static b64decode (str) {
|
||||||
|
if (process.browser) {
|
||||||
|
return decodeURIComponent(atob(str).split('').map(function (c) {
|
||||||
|
return `%${('00' + c.charCodeAt(0).toString(16)).slice(-2)}`
|
||||||
|
}).join(''))
|
||||||
|
} else {
|
||||||
|
return Buffer.from(str, 'base64').toString('ascii')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove duplicate items from a list
|
||||||
|
* @param {Array} list
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
static uniqueList (list) {
|
||||||
let tmp = {}
|
let tmp = {}
|
||||||
let r = []
|
let r = []
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
@ -75,8 +114,15 @@ utils.common = {
|
||||||
r.push(tmp[i])
|
r.push(tmp[i])
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
},
|
}
|
||||||
mergeHash: function (obj1, obj2) {
|
|
||||||
|
/**
|
||||||
|
* Merge two objects recursively
|
||||||
|
* @param {Object} obj1
|
||||||
|
* @param {Object} obj2
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static mergeHash (obj1, obj2) {
|
||||||
for (let p in obj2) {
|
for (let p in obj2) {
|
||||||
try {
|
try {
|
||||||
if (obj2[p].constructor === Object) {
|
if (obj2[p].constructor === Object) {
|
||||||
|
@ -89,6 +135,16 @@ utils.common = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj1
|
return obj1
|
||||||
},
|
}
|
||||||
mockup: (obj) => obj.split('\n').map((ln) => ln.trim()).join('')
|
|
||||||
|
/**
|
||||||
|
* Template string beautifier
|
||||||
|
* @param {Object} obj
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static mockup (obj) {
|
||||||
|
return obj.split('\n').map((ln) => ln.trim()).join('')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = common
|
||||||
|
|
31
lib/utils/index.js
Normal file
31
lib/utils/index.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
class utils {
|
||||||
|
static get common () {
|
||||||
|
return require('./common')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get block () {
|
||||||
|
return require('./block')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get mutate () {
|
||||||
|
return require('./mutate')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get objects () {
|
||||||
|
return require('./objects')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get platform () {
|
||||||
|
return require('./platform')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get script () {
|
||||||
|
return require('./script')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get prototypes () {
|
||||||
|
return require('./prototypes')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = utils
|
|
@ -1 +0,0 @@
|
||||||
var utils = {} // eslint-disable-line no-unused-vars
|
|
|
@ -2,22 +2,26 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
utils.mutate = {
|
const make = require('../make')
|
||||||
text: function (str) {
|
const utils = require('../utils')
|
||||||
|
const random = require('../random')
|
||||||
|
|
||||||
|
class mutate extends utils {
|
||||||
|
static text (str) {
|
||||||
let mutator = function (m) {
|
let mutator = function (m) {
|
||||||
return random.chance(4) ? m : make.text.any()
|
return random.chance(4) ? m : make.text.any()
|
||||||
}
|
}
|
||||||
return str.replace(/[a-zA-Z]+?/g, mutator)
|
return str.replace(/[a-zA-Z]+?/g, mutator)
|
||||||
},
|
}
|
||||||
|
|
||||||
numbers: function (str) {
|
static numbers (str) {
|
||||||
let mutator = function (m) {
|
let mutator = function (m) {
|
||||||
return random.chance(4) ? m : make.number.any()
|
return random.chance(4) ? m : make.number.any()
|
||||||
}
|
}
|
||||||
return str.replace(/-?\d+(\.\d+)?/g, mutator)
|
return str.replace(/-?\d+(\.\d+)?/g, mutator)
|
||||||
},
|
}
|
||||||
|
|
||||||
units: function (str) {
|
static units (str) {
|
||||||
let mutator = function (m, p1) {
|
let mutator = function (m, p1) {
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
return m
|
return m
|
||||||
|
@ -26,9 +30,9 @@ utils.mutate = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str.replace(/(\d+)(px|em|ex|ch|rem|mm|cm|in|pt|pc|%')/g, mutator)
|
return str.replace(/(\d+)(px|em|ex|ch|rem|mm|cm|in|pt|pc|%')/g, mutator)
|
||||||
},
|
}
|
||||||
|
|
||||||
random: function (str) {
|
static random (str) {
|
||||||
let mutator = function (m) {
|
let mutator = function (m) {
|
||||||
if (random.chance(20)) {
|
if (random.chance(20)) {
|
||||||
if (str.match(/[0-9]/g)) {
|
if (str.match(/[0-9]/g)) {
|
||||||
|
@ -41,9 +45,9 @@ utils.mutate = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str.replace(/./g, mutator)
|
return str.replace(/./g, mutator)
|
||||||
},
|
}
|
||||||
|
|
||||||
any: function (str) {
|
static any (str) {
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
case 0:
|
case 0:
|
||||||
return utils.mutate.text(str)
|
return utils.mutate.text(str)
|
||||||
|
@ -56,3 +60,5 @@ utils.mutate = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = mutate
|
||||||
|
|
|
@ -2,108 +2,119 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
const random = require('../random')
|
||||||
|
const utils = require('../utils')
|
||||||
|
const {logger} = require('../logging')
|
||||||
|
|
||||||
var o = null // eslint-disable-line no-unused-vars
|
var o = null // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
function Objects () {
|
class Objects {
|
||||||
this.counter = 0
|
constructor () {
|
||||||
this.container = {}
|
this.counter = 0
|
||||||
}
|
this.container = {}
|
||||||
|
}
|
||||||
|
|
||||||
Objects.prototype.add = function (category, member) {
|
add (category, member) {
|
||||||
if (!member) {
|
if (!member) {
|
||||||
member = 'o' + this.counter
|
member = 'o' + this.counter
|
||||||
|
}
|
||||||
|
if (!this.has(category)) {
|
||||||
|
this.container[category] = []
|
||||||
|
}
|
||||||
|
this.container[category].push({type: category, name: member})
|
||||||
|
++this.counter
|
||||||
|
return this.container[category].slice(-1)[0].name
|
||||||
}
|
}
|
||||||
if (!this.has(category)) {
|
|
||||||
this.container[category] = []
|
|
||||||
}
|
|
||||||
this.container[category].push({type: category, name: member})
|
|
||||||
++this.counter
|
|
||||||
return this.container[category].slice(-1)[0].name
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.get = function (category, last) {
|
get (category, last) {
|
||||||
if (!(category in this.container)) {
|
if (!(category in this.container)) {
|
||||||
// return {type:null, name:null};
|
// return {type:null, name:null};
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new Error(category + ' is not available.')
|
throw new Error(`${category} is not available.`)
|
||||||
|
}
|
||||||
|
if (last) {
|
||||||
|
return this.container[category].slice(-1)[0]
|
||||||
|
}
|
||||||
|
return random.pick(this.container[category])
|
||||||
}
|
}
|
||||||
if (last) {
|
|
||||||
return this.container[category].slice(-1)[0]
|
|
||||||
}
|
|
||||||
return random.pick(this.container[category])
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.pick = function (category, last) {
|
pick (category, last) {
|
||||||
try {
|
try {
|
||||||
return this.get(category, last).name
|
return this.get(category, last).name
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw logger.JSError('Error: pick(\'' + category + '\') is undefined.')
|
throw logger.JSError(`Error: pick('${category}') is undefined.`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.pop = function (objectName) {
|
pop (objectName) {
|
||||||
let self = this
|
let self = this
|
||||||
utils.common.getKeysFromHash(this.container).forEach(function (category) {
|
utils.common.getKeysFromHash(this.container).forEach(function (category) {
|
||||||
self.container[category].forEach(function (obj) {
|
self.container[category].forEach(function (obj) {
|
||||||
if (obj.name === objectName) {
|
if (obj.name === objectName) {
|
||||||
self.container[category].splice(self.container[category].indexOf(obj), 1)
|
self.container[category].splice(self.container[category].indexOf(obj), 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
contains (categoryNames) {
|
||||||
|
let categories = []
|
||||||
|
let self = this
|
||||||
|
categoryNames.forEach(function (name) {
|
||||||
|
if (self.has(name)) {
|
||||||
|
categories.push(name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
return (categories.length === 0) ? null : categories
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.contains = function (categoryNames) {
|
|
||||||
let categories = []
|
|
||||||
let self = this
|
|
||||||
categoryNames.forEach(function (name) {
|
|
||||||
if (self.has(name)) {
|
|
||||||
categories.push(name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return (categories.length === 0) ? null : categories
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.show = function (category) {
|
|
||||||
return (category in this.container) ? this.container[category] : this.container
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.count = function (category) {
|
|
||||||
return (category in this.container) ? this.container[category].length : 0
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.has = function (category) {
|
|
||||||
if (category in this.container) {
|
|
||||||
this.check(category)
|
|
||||||
return this.container[category].length > 0
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.valid = function () {
|
show (category) {
|
||||||
let items = []
|
return (category in this.container) ? this.container[category] : this.container
|
||||||
let self = this
|
}
|
||||||
utils.common.getKeysFromHash(self.container).forEach(function (category) {
|
|
||||||
self.check(category)
|
count (category) {
|
||||||
})
|
return (category in this.container) ? this.container[category].length : 0
|
||||||
utils.common.getKeysFromHash(self.container).forEach(function (category) {
|
}
|
||||||
for (let i = 0; i < self.container[category].length; i++) {
|
|
||||||
items.push(self.container[category][i].name)
|
has (category) {
|
||||||
|
if (category in this.container) {
|
||||||
|
this.check(category)
|
||||||
|
return this.container[category].length > 0
|
||||||
}
|
}
|
||||||
})
|
return false
|
||||||
return items
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Objects.prototype.check = function (category) {
|
valid () {
|
||||||
let self = this
|
let items = []
|
||||||
self.container[category].forEach(function (object) {
|
let self = this
|
||||||
try {
|
utils.common.getKeysFromHash(self.container).forEach(function (category) {
|
||||||
let x = /* frame.contentWindow. */ eval(object.name) // eslint-disable-line no-eval
|
self.check(category)
|
||||||
if (x === undefined || x === null) {
|
})
|
||||||
|
utils.common.getKeysFromHash(self.container).forEach(function (category) {
|
||||||
|
for (let i = 0; i < self.container[category].length; i++) {
|
||||||
|
items.push(self.container[category][i].name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
check (category) {
|
||||||
|
let self = this
|
||||||
|
self.container[category].forEach(function (object) {
|
||||||
|
try {
|
||||||
|
let x = /* frame.contentWindow. */ eval(object.name) // eslint-disable-line no-eval
|
||||||
|
if (x === undefined || x === null) {
|
||||||
|
self.pop(object.name)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
self.pop(object.name)
|
self.pop(object.name)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
})
|
||||||
self.pop(object.name)
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
module.exports = {
|
||||||
|
o,
|
||||||
|
Objects
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,101 +2,112 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
utils.platform = (function () {
|
const utils = require('../utils')
|
||||||
let platform = {}
|
|
||||||
|
|
||||||
const userAgent = (navigator.userAgent).toLowerCase()
|
class platform extends utils {
|
||||||
const language = navigator.language || navigator.browserLanguage
|
static get name () {
|
||||||
|
let platform = {}
|
||||||
|
|
||||||
const version = platform.version = (userAgent.match(/.*(?:rv|chrome|webkit|opera|ie)[/: ](.+?)([ );]|$)/) || [])[1]
|
/* In case we are running in Node. */
|
||||||
const webkitVersion = (userAgent.match(/webkit\/(.+?) /) || [])[1]
|
if (typeof window === 'undefined') {
|
||||||
|
return platform
|
||||||
platform.windows = platform.isWindows = !!/windows/.test(userAgent)
|
|
||||||
platform.mac = platform.isMac = !!/macintosh/.test(userAgent) || (/mac os x/.test(userAgent) && !/like mac os x/.test(userAgent))
|
|
||||||
platform.lion = platform.isLion = !!(/mac os x 10_7/.test(userAgent) && !/like mac os x 10_7/.test(userAgent))
|
|
||||||
platform.iPhone = platform.isiPhone = !!/iphone/.test(userAgent)
|
|
||||||
platform.iPod = platform.isiPod = !!/ipod/.test(userAgent)
|
|
||||||
platform.iPad = platform.isiPad = !!/ipad/.test(userAgent)
|
|
||||||
platform.iOS = platform.isiOS = platform.iPhone || platform.iPod || platform.iPad
|
|
||||||
platform.android = platform.isAndroid = !!/android/.test(userAgent)
|
|
||||||
platform.opera = /opera/.test(userAgent) ? version : 0
|
|
||||||
platform.isOpera = !!platform.opera
|
|
||||||
platform.msie = /msie/.test(userAgent) && !platform.opera ? version : 0
|
|
||||||
platform.isIE = !!platform.msie
|
|
||||||
platform.isIE8OrLower = !!(platform.msie && parseInt(platform.msie, 10) <= 8)
|
|
||||||
platform.mozilla = /mozilla/.test(userAgent) && !/(compatible|webkit|msie)/.test(userAgent) ? version : 0
|
|
||||||
platform.isMozilla = !!platform.mozilla
|
|
||||||
platform.webkit = /webkit/.test(userAgent) ? webkitVersion : 0
|
|
||||||
platform.isWebkit = !!platform.webkit
|
|
||||||
platform.chrome = /chrome/.test(userAgent) ? version : 0
|
|
||||||
platform.isChrome = !!platform.chrome
|
|
||||||
platform.mobileSafari = /apple.*mobile/.test(userAgent) && platform.iOS ? webkitVersion : 0
|
|
||||||
platform.isMobileSafari = !!platform.mobileSafari
|
|
||||||
platform.iPadSafari = platform.iPad && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPadSafari = !!platform.iPadSafari
|
|
||||||
platform.iPhoneSafari = platform.iPhone && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPhoneSafari = !!platform.iphoneSafari
|
|
||||||
platform.iPodSafari = platform.iPod && platform.isMobileSafari ? webkitVersion : 0
|
|
||||||
platform.isiPodSafari = !!platform.iPodSafari
|
|
||||||
platform.isiOSHomeScreen = platform.isMobileSafari && !/apple.*mobile.*safari/.test(userAgent)
|
|
||||||
platform.safari = platform.webkit && !platform.chrome && !platform.iOS && !platform.android ? webkitVersion : 0
|
|
||||||
platform.isSafari = !!platform.safari
|
|
||||||
platform.language = language.split('-', 1)[0]
|
|
||||||
platform.current =
|
|
||||||
platform.msie ? 'msie' : platform.mozilla ? 'mozilla' : platform.chrome ? 'chrome' : platform.safari ? 'safari' : platform.opera ? 'opera' : platform.mobileSafari ? 'mobile-safari' : platform.android ? 'android' : 'unknown'
|
|
||||||
|
|
||||||
function platformName (candidates) {
|
|
||||||
for (let i = 0; i < candidates.length; i++) {
|
|
||||||
if (candidates[i] in window) {
|
|
||||||
return 'window.' + candidates[i]
|
|
||||||
}
|
|
||||||
if (candidates[i] in navigator) {
|
|
||||||
return 'navigator.' + candidates[i]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return undefined
|
|
||||||
|
const userAgent = (navigator.userAgent).toLowerCase()
|
||||||
|
const language = navigator.language || navigator.browserLanguage
|
||||||
|
|
||||||
|
const version = platform.version = (userAgent.match(/.*(?:rv|chrome|webkit|opera|ie)[/: ](.+?)([ );]|$)/) || [])[1]
|
||||||
|
const webkitVersion = (userAgent.match(/webkit\/(.+?) /) || [])[1]
|
||||||
|
|
||||||
|
platform.windows = platform.isWindows = !!/windows/.test(userAgent)
|
||||||
|
platform.mac = platform.isMac = !!/macintosh/.test(userAgent) || (/mac os x/.test(userAgent) && !/like mac os x/.test(userAgent))
|
||||||
|
platform.lion = platform.isLion = !!(/mac os x 10_7/.test(userAgent) && !/like mac os x 10_7/.test(userAgent))
|
||||||
|
platform.iPhone = platform.isiPhone = !!/iphone/.test(userAgent)
|
||||||
|
platform.iPod = platform.isiPod = !!/ipod/.test(userAgent)
|
||||||
|
platform.iPad = platform.isiPad = !!/ipad/.test(userAgent)
|
||||||
|
platform.iOS = platform.isiOS = platform.iPhone || platform.iPod || platform.iPad
|
||||||
|
platform.android = platform.isAndroid = !!/android/.test(userAgent)
|
||||||
|
platform.opera = /opera/.test(userAgent) ? version : 0
|
||||||
|
platform.isOpera = !!platform.opera
|
||||||
|
platform.msie = /msie/.test(userAgent) && !platform.opera ? version : 0
|
||||||
|
platform.isIE = !!platform.msie
|
||||||
|
platform.isIE8OrLower = !!(platform.msie && parseInt(platform.msie, 10) <= 8)
|
||||||
|
platform.mozilla = /mozilla/.test(userAgent) && !/(compatible|webkit|msie)/.test(userAgent) ? version : 0
|
||||||
|
platform.isMozilla = !!platform.mozilla
|
||||||
|
platform.webkit = /webkit/.test(userAgent) ? webkitVersion : 0
|
||||||
|
platform.isWebkit = !!platform.webkit
|
||||||
|
platform.chrome = /chrome/.test(userAgent) ? version : 0
|
||||||
|
platform.isChrome = !!platform.chrome
|
||||||
|
platform.mobileSafari = /apple.*mobile/.test(userAgent) && platform.iOS ? webkitVersion : 0
|
||||||
|
platform.isMobileSafari = !!platform.mobileSafari
|
||||||
|
platform.iPadSafari = platform.iPad && platform.isMobileSafari ? webkitVersion : 0
|
||||||
|
platform.isiPadSafari = !!platform.iPadSafari
|
||||||
|
platform.iPhoneSafari = platform.iPhone && platform.isMobileSafari ? webkitVersion : 0
|
||||||
|
platform.isiPhoneSafari = !!platform.iphoneSafari
|
||||||
|
platform.iPodSafari = platform.iPod && platform.isMobileSafari ? webkitVersion : 0
|
||||||
|
platform.isiPodSafari = !!platform.iPodSafari
|
||||||
|
platform.isiOSHomeScreen = platform.isMobileSafari && !/apple.*mobile.*safari/.test(userAgent)
|
||||||
|
platform.safari = platform.webkit && !platform.chrome && !platform.iOS && !platform.android ? webkitVersion : 0
|
||||||
|
platform.isSafari = !!platform.safari
|
||||||
|
platform.language = language.split('-', 1)[0]
|
||||||
|
platform.current =
|
||||||
|
platform.msie ? 'msie' : platform.mozilla ? 'mozilla' : platform.chrome ? 'chrome' : platform.safari ? 'safari' : platform.opera ? 'opera' : platform.mobileSafari ? 'mobile-safari' : platform.android ? 'android' : 'unknown'
|
||||||
|
|
||||||
|
function platformName (candidates) {
|
||||||
|
for (let i = 0; i < candidates.length; i++) {
|
||||||
|
if (candidates[i] in window) {
|
||||||
|
return `window.${candidates[i]}`
|
||||||
|
}
|
||||||
|
if (candidates[i] in navigator) {
|
||||||
|
return `navigator.${candidates[i]}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
platform.GUM = platformName(['getUserMedia', 'webkitGetUserMedia', 'mozGetUserMedia', 'msGetUserMedia', 'getGUM'])
|
||||||
|
platform.PeerConnection = platformName(['webkitRTCPeerConnection', 'mozRTCPeerConnection', 'msPeerConnection'])
|
||||||
|
platform.IceCandidate = platformName(['mozRTCIceCandidate', 'RTCIceCandidate'])
|
||||||
|
platform.SessionDescription = platformName(['mozRTCSessionDescription', 'RTCSessionDescription'])
|
||||||
|
platform.URL = platformName(['URL', 'webkitURL'])
|
||||||
|
platform.AudioContext = platformName(['AudioContext', 'webkitAudioContext'])
|
||||||
|
platform.OfflineAudioContext = platformName(['OfflineAudioContext', 'webkitOfflineAudioContext'])
|
||||||
|
platform.MediaSource = platformName(['MediaSource', 'WebKitMediaSource'])
|
||||||
|
|
||||||
|
platform.SpeechRecognition = platformName(['SpeechRecognition', 'webkitSpeechRecognition'])
|
||||||
|
platform.SpeechGrammarList = platformName(['SpeechGrammarList', 'webkitSpeechGrammarList'])
|
||||||
|
platform.SpeechGrammar = platformName(['SpeechGrammar'])
|
||||||
|
|
||||||
|
/*
|
||||||
|
function findWebGLContextName (candidates) {
|
||||||
|
var canvas = document.createElement('canvas')
|
||||||
|
for (var i = 0; i < candidates.length; i++) {
|
||||||
|
var name = candidates[i]
|
||||||
|
try {
|
||||||
|
if (canvas.getContext(name)) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
platform.WebGL = 'webgl' // findWebGLContextName(["webgl", "experimental-webgl", "webkit-3d"]);
|
||||||
|
platform.WebGL2 = 'webgl2' // findWebGLContextName(["webgl2", "experimental-webgl2"]);
|
||||||
|
|
||||||
|
platform.captureStreamUntilEnded = 'captureStreamUntilEnded'
|
||||||
|
if (platform.isMozilla) {
|
||||||
|
platform.captureStreamUntilEnded = 'mozCaptureStreamUntilEnded'
|
||||||
|
}
|
||||||
|
|
||||||
|
platform.srcObject = 'srcObject'
|
||||||
|
if (platform.isMozilla) {
|
||||||
|
platform.srcObject = 'mozSrcObject'
|
||||||
|
}
|
||||||
|
|
||||||
|
return platform
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
platform.GUM = platformName(['getUserMedia', 'webkitGetUserMedia', 'mozGetUserMedia', 'msGetUserMedia', 'getGUM'])
|
module.exports = platform
|
||||||
platform.PeerConnection = platformName(['webkitRTCPeerConnection', 'mozRTCPeerConnection', 'msPeerConnection'])
|
|
||||||
platform.IceCandidate = platformName(['mozRTCIceCandidate', 'RTCIceCandidate'])
|
|
||||||
platform.SessionDescription = platformName(['mozRTCSessionDescription', 'RTCSessionDescription'])
|
|
||||||
platform.URL = platformName(['URL', 'webkitURL'])
|
|
||||||
platform.AudioContext = platformName(['AudioContext', 'webkitAudioContext'])
|
|
||||||
platform.OfflineAudioContext = platformName(['OfflineAudioContext', 'webkitOfflineAudioContext'])
|
|
||||||
platform.MediaSource = platformName(['MediaSource', 'WebKitMediaSource'])
|
|
||||||
|
|
||||||
platform.SpeechRecognition = platformName(['SpeechRecognition', 'webkitSpeechRecognition'])
|
|
||||||
platform.SpeechGrammarList = platformName(['SpeechGrammarList', 'webkitSpeechGrammarList'])
|
|
||||||
platform.SpeechGrammar = platformName(['SpeechGrammar'])
|
|
||||||
|
|
||||||
/*
|
|
||||||
function findWebGLContextName (candidates) {
|
|
||||||
var canvas = document.createElement('canvas')
|
|
||||||
for (var i = 0; i < candidates.length; i++) {
|
|
||||||
var name = candidates[i]
|
|
||||||
try {
|
|
||||||
if (canvas.getContext(name)) {
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
platform.WebGL = 'webgl' // findWebGLContextName(["webgl", "experimental-webgl", "webkit-3d"]);
|
|
||||||
platform.WebGL2 = 'webgl2' // findWebGLContextName(["webgl2", "experimental-webgl2"]);
|
|
||||||
|
|
||||||
platform.captureStreamUntilEnded = 'captureStreamUntilEnded'
|
|
||||||
if (platform.isMozilla) {
|
|
||||||
platform.captureStreamUntilEnded = 'mozCaptureStreamUntilEnded'
|
|
||||||
}
|
|
||||||
|
|
||||||
platform.srcObject = 'srcObject'
|
|
||||||
if (platform.isMozilla) {
|
|
||||||
platform.srcObject = 'mozSrcObject'
|
|
||||||
}
|
|
||||||
|
|
||||||
return platform
|
|
||||||
})()
|
|
||||||
|
|
108
lib/utils/prototypes.js
vendored
108
lib/utils/prototypes.js
vendored
|
@ -3,73 +3,51 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
Object.defineProperty(String.prototype, 'fromCodePoint', function () {
|
const utils = require('../utils')
|
||||||
let chars = []
|
|
||||||
let point, offset, units, i
|
|
||||||
for (i = 0; i < arguments.length; ++i) {
|
|
||||||
point = arguments[i]
|
|
||||||
offset = point - 0x10000
|
|
||||||
units = point > 0xFFFF
|
|
||||||
? [
|
|
||||||
0xD800 + (offset >> 10),
|
|
||||||
0xDC00 + (offset & 0x3FF)]
|
|
||||||
: [point]
|
|
||||||
chars.push(String.fromCharCode.apply(null, units))
|
|
||||||
}
|
|
||||||
return chars.join('')
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(String.prototype, 'endsWith', function (str) {
|
class prototypes extends utils {
|
||||||
return this.match(str + '$') === str
|
static enable () {
|
||||||
})
|
if (!String.prototype.hasOwnProperty('insert')) {
|
||||||
|
Object.defineProperty(String.prototype, 'insert', {
|
||||||
Object.defineProperty(String.prototype, 'startsWith', function (str) {
|
value: function (data, i) {
|
||||||
return this.match('^' + str) === str
|
return this.slice(0, i) + data + this.slice(i, this.length)
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(String.prototype, 'trim', function () {
|
|
||||||
return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '')
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(String.prototype, 'insert', function (data, idx) {
|
|
||||||
return this.slice(0, idx) + data + this.slice(idx, this.length)
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(Array.prototype, 'has', function (v) {
|
|
||||||
return this.indexOf(v) !== -1
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(Array.prototype, 'forEach', function (array, fn) {
|
|
||||||
for (let i = 0; i < array.length; i++) {
|
|
||||||
fn(array[i])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(Array.prototype, 'map', function (fn, array) {
|
|
||||||
let result = []
|
|
||||||
Array.forEach(array, function (element) {
|
|
||||||
result.push(fn(element))
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.defineProperty(Array.prototype, 'extend', {
|
|
||||||
value: function (obj) {
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
obj.forEach(function (v) {
|
|
||||||
if (typeof v !== 'undefined') {
|
|
||||||
this.push(v)
|
|
||||||
}
|
}
|
||||||
}, this)
|
})
|
||||||
} else {
|
}
|
||||||
this.push(obj)
|
|
||||||
|
if (!Array.prototype.hasOwnProperty('has')) {
|
||||||
|
Object.defineProperty(Array.prototype, 'has', {
|
||||||
|
value: function (v) {
|
||||||
|
return this.indexOf(v) !== -1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.prototype.hasOwnProperty('extend')) {
|
||||||
|
Object.defineProperty(Array.prototype, 'extend', {
|
||||||
|
value: function (obj) {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
obj.forEach(function (v) {
|
||||||
|
if (typeof v !== 'undefined') {
|
||||||
|
this.push(v)
|
||||||
|
}
|
||||||
|
}, this)
|
||||||
|
} else {
|
||||||
|
this.push(obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Object.hasOwnProperty('isObject')) {
|
||||||
|
Object.defineProperty(Object, 'isObject', {
|
||||||
|
value: function (obj) {
|
||||||
|
return (obj !== null && typeof obj === 'object' &&
|
||||||
|
Object.prototype.toString.call(obj) === '[object Object]')
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
Object.defineProperty(Object, 'isObject', {
|
module.exports = prototypes
|
||||||
value: function (obj) {
|
|
||||||
return (obj !== null && typeof obj === 'object' &&
|
|
||||||
Object.prototype.toString.call(obj) === '[object Object]')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
|
@ -2,19 +2,60 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
utils.script = {
|
const random = require('../random')
|
||||||
methodHead: function (list, numOptional) {
|
const make = require('../make')
|
||||||
if (isNaN(numOptional)) {
|
const utils = require('../utils')
|
||||||
numOptional = 0
|
const {o} = require('./objects')
|
||||||
|
|
||||||
|
class script extends utils {
|
||||||
|
static addElementToBody (name) {
|
||||||
|
return `(document.body || document.documentElement).appendChild${script.methodHead([name])}`
|
||||||
|
}
|
||||||
|
|
||||||
|
static getRandomElement () {
|
||||||
|
return `document.getElementsByTagName('*')[${random.number(document.getElementsByTagName('*').length)}]`
|
||||||
|
}
|
||||||
|
|
||||||
|
static makeArray (type, arrayLength, cb) {
|
||||||
|
if (type === null || type === undefined) {
|
||||||
|
type = random.item(['Uint8', 'Float32'])
|
||||||
}
|
}
|
||||||
let arity = list.length - random.number(numOptional)
|
switch (random.number(8)) {
|
||||||
let params = []
|
case 0:
|
||||||
for (let i = 0; i < arity; i++) {
|
let src = `function() { let buffer = new ${type}Array(${arrayLength});`
|
||||||
params.push(random.pick([list[i]]))
|
src += script.makeLoop(`buffer[i] = ${cb()};`, arrayLength)
|
||||||
|
src += 'return buffer;}()'
|
||||||
|
return src
|
||||||
|
case 1:
|
||||||
|
return `new ${type}Array([${make.arrays.filledArray(cb, arrayLength)}])`
|
||||||
|
default:
|
||||||
|
return `new ${type}Array(${arrayLength})`
|
||||||
}
|
}
|
||||||
return '(' + params.join(', ') + ')'
|
}
|
||||||
},
|
|
||||||
methodCall: function (objectName, methodHash) {
|
static makeConstraint (keys, values) {
|
||||||
|
let o = {}
|
||||||
|
let n = random.range(0, keys.length)
|
||||||
|
while (n--) {
|
||||||
|
o[random.pick(keys)] = random.pick(values)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
static makeLoop (s, max) {
|
||||||
|
return `for (let i = 0; i < ${max || make.number.tiny()}; i++) {${s}}`
|
||||||
|
}
|
||||||
|
|
||||||
|
static makeRandomOptions (baseObject) {
|
||||||
|
let o = {}
|
||||||
|
let unique = random.subset(Object.keys(baseObject))
|
||||||
|
for (let i = 0; i < unique.length; i++) {
|
||||||
|
o[unique[i]] = random.pick(baseObject[unique[i]])
|
||||||
|
}
|
||||||
|
return JSON.stringify(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
static methodCall (objectName, methodHash) {
|
||||||
if (!utils.common.getKeysFromHash(methodHash).length || !objectName) {
|
if (!utils.common.getKeysFromHash(methodHash).length || !objectName) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
@ -23,9 +64,63 @@ utils.script = {
|
||||||
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
|
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
|
||||||
return methodArgs()
|
return methodArgs()
|
||||||
}
|
}
|
||||||
return objectName + '.' + methodName + utils.script.methodHead(methodArgs)
|
return `${objectName}.${methodName}${script.methodHead(methodArgs)}`
|
||||||
},
|
}
|
||||||
setAttribute: function (objectName, attributeHash) {
|
|
||||||
|
static methodHead (list, numOptional) {
|
||||||
|
if (isNaN(numOptional)) {
|
||||||
|
numOptional = 0
|
||||||
|
}
|
||||||
|
let arity = list.length - random.number(numOptional)
|
||||||
|
let params = []
|
||||||
|
for (let i = 0; i < arity; i++) {
|
||||||
|
params.push(random.pick([list[i]]))
|
||||||
|
}
|
||||||
|
return `(${params.join(', ')})`
|
||||||
|
}
|
||||||
|
|
||||||
|
static offset (s) {
|
||||||
|
return `(${s} % ${random.range(1, 3)})`
|
||||||
|
}
|
||||||
|
|
||||||
|
static randListIndex (objName) {
|
||||||
|
return `${random.number()} % ${o.pick(objName)}.length`
|
||||||
|
}
|
||||||
|
|
||||||
|
static runner (cmds) {
|
||||||
|
/**
|
||||||
|
* Wrap command(s) in setInterval, setTimeout, loop or run directly
|
||||||
|
* @param {Object|String} cmds - Command(s) to be executed
|
||||||
|
*/
|
||||||
|
cmds = (Array.isArray(cmds)) ? cmds : [cmds]
|
||||||
|
cmds = cmds.filter(function (i) { return i !== undefined })
|
||||||
|
if (cmds.length) {
|
||||||
|
if (random.chance(50)) {
|
||||||
|
// Wrap each command in try/catch for use in setInterval, setTimeout, repeater
|
||||||
|
switch (random.number(3)) {
|
||||||
|
case 0:
|
||||||
|
return `setInterval(function () { ${utils.script.safely(cmds)} }, ${random.range(100, 400)} )`
|
||||||
|
case 1:
|
||||||
|
return `setTimeout(function () { ${utils.script.safely(cmds)} }, ${random.range(100, 400)} )`
|
||||||
|
case 2:
|
||||||
|
let n = random.number(random.number(30))
|
||||||
|
return `for (let i = 0; i < ${n}; i++) { ${utils.script.safely(cmds)} }`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return cmds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static safely (obj) {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
return obj.map(s => utils.script.safely(s)).join(' ')
|
||||||
|
} else {
|
||||||
|
return `try { ${obj} } catch(e) { }`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static setAttribute (objectName, attributeHash) {
|
||||||
if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
|
if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
@ -40,70 +135,8 @@ utils.script = {
|
||||||
attributeValue = "'" + attributeValue + "'";
|
attributeValue = "'" + attributeValue + "'";
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return objectName + '.' + attributeName + operator + attributeValue + ';'
|
return `${objectName}.${attributeName}${operator}${attributeValue};`
|
||||||
},
|
|
||||||
makeConstraint: function (keys, values) {
|
|
||||||
let o = {}
|
|
||||||
let n = random.range(0, keys.length)
|
|
||||||
while (n--) {
|
|
||||||
o[random.pick(keys)] = random.pick(values)
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
},
|
|
||||||
makeRandomOptions: function (baseObject) {
|
|
||||||
let o = {}
|
|
||||||
let unique = random.subset(Object.keys(baseObject))
|
|
||||||
for (let i = 0; i < unique.length; i++) {
|
|
||||||
o[unique[i]] = random.pick(baseObject[unique[i]])
|
|
||||||
}
|
|
||||||
return JSON.stringify(o)
|
|
||||||
},
|
|
||||||
safely: function (obj) {
|
|
||||||
if (Array.isArray(obj)) {
|
|
||||||
return obj.map(s => utils.script.safely(s)).join(' ')
|
|
||||||
} else {
|
|
||||||
return `try { ${obj} } catch(e) { }`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
makeLoop: function (s, max) {
|
|
||||||
return 'for (let i = 0; i < ' + (max || make.number.range()) + '; i++) {' + s + '}'
|
|
||||||
},
|
|
||||||
makeArray: function (type, arrayLength, cb) {
|
|
||||||
if (type === null || type === undefined) {
|
|
||||||
type = random.item(['Uint8', 'Float32'])
|
|
||||||
}
|
|
||||||
switch (random.number(8)) {
|
|
||||||
case 0:
|
|
||||||
let src = 'function() { let buffer = new ' + type + 'Array(' + arrayLength + ');'
|
|
||||||
src += utils.script.makeLoop('buffer[i] = ' + cb() + ';', arrayLength)
|
|
||||||
src += 'return buffer;}()'
|
|
||||||
return src
|
|
||||||
case 1:
|
|
||||||
return 'new ' + type + 'Array([' + make.arrays.filledArray(cb, arrayLength) + '])'
|
|
||||||
default:
|
|
||||||
return 'new ' + type + 'Array(' + arrayLength + ')'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
randListIndex: function (objName) {
|
|
||||||
return random.number() + ' % ' + o.pick(objName) + '.length'
|
|
||||||
},
|
|
||||||
addElementToBody: function (name) {
|
|
||||||
return '(document.body || document.documentElement).appendChild' + utils.script.methodHead([name])
|
|
||||||
},
|
|
||||||
forceGC: function () {
|
|
||||||
if (utils.platform.isMozilla) {
|
|
||||||
}
|
|
||||||
if (utils.platform.isChrome) {
|
|
||||||
if (window.GCController) {
|
|
||||||
return GCController.collect() // eslint-disable-line no-undef
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (utils.platform.isSafari) {
|
|
||||||
}
|
|
||||||
if (utils.platform.isIE) {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getRandomElement: function () {
|
|
||||||
return 'document.getElementsByTagName(\'*\')[' + random.number(document.getElementsByTagName('*').length) + ']'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = script
|
||||||
|
|
54
package.json
54
package.json
|
@ -1,12 +1,15 @@
|
||||||
{
|
{
|
||||||
"name": "octo",
|
"name": "@mozillasecurity/octo",
|
||||||
"version": "0.0.3",
|
"version": "1.0.14",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"fuzzing",
|
"fuzzing",
|
||||||
"browsers"
|
"browser",
|
||||||
|
"javascript",
|
||||||
|
"node",
|
||||||
|
"library"
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/mozillasecurity/octo",
|
"homepage": "https://github.com/mozillasecurity/octo/tree/es6",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/mozillasecurity/octo.git"
|
"url": "https://github.com/mozillasecurity/octo.git"
|
||||||
|
@ -21,31 +24,25 @@
|
||||||
"test": "grunt test --verbose",
|
"test": "grunt test --verbose",
|
||||||
"test:lint": "cross-env NODE_ENV=test standard --verbose",
|
"test:lint": "cross-env NODE_ENV=test standard --verbose",
|
||||||
"test:lint:fix": "cross-env NODE_ENV=test standard --fix --verbose",
|
"test:lint:fix": "cross-env NODE_ENV=test standard --fix --verbose",
|
||||||
"build": "./build.py -l lib/ -d deploy/",
|
"build": "webpack -p",
|
||||||
|
"watch": "webpack --watch",
|
||||||
|
"precommit": "npm run test:lint",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"precommit": "npm run test:lint"
|
"release": "np"
|
||||||
},
|
},
|
||||||
"standard": {
|
"standard": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"tests/**",
|
"tests/**",
|
||||||
"deploy/"
|
"dist/"
|
||||||
],
|
],
|
||||||
"globals": [
|
"envs": {
|
||||||
"random",
|
"browser": true,
|
||||||
"make",
|
"node": true,
|
||||||
"utils",
|
"es6": true
|
||||||
"logger",
|
}
|
||||||
"MersenneTwister",
|
|
||||||
"o",
|
|
||||||
"btoa",
|
|
||||||
"atob"
|
|
||||||
],
|
|
||||||
"envs": [
|
|
||||||
"browser"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "^5.1.3",
|
"cross-env": "^5.1.4",
|
||||||
"grunt": "*",
|
"grunt": "*",
|
||||||
"grunt-karma": "*",
|
"grunt-karma": "*",
|
||||||
"grunt-karma-coveralls": "*",
|
"grunt-karma-coveralls": "*",
|
||||||
|
@ -54,9 +51,16 @@
|
||||||
"karma": "*",
|
"karma": "*",
|
||||||
"karma-chrome-launcher": "*",
|
"karma-chrome-launcher": "*",
|
||||||
"karma-coverage": "*",
|
"karma-coverage": "*",
|
||||||
"karma-firefox-launcher": "*",
|
"karma-firefox-launcher": "^1.1.0",
|
||||||
"karma-qunit": "*",
|
"karma-qunit": "^2.0.1",
|
||||||
"qunitjs": "*",
|
"np": "^3.0.4",
|
||||||
"standard": "*"
|
"qunit": "^2.5.1",
|
||||||
|
"qunitjs": "^2.4.1",
|
||||||
|
"standard": "^11.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jsesc": "^2.5.1",
|
||||||
|
"webpack": "^4.1.1",
|
||||||
|
"webpack-cli": "^2.0.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
webpack.config.js
Normal file
13
webpack.config.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
entry: './lib/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'octo.js',
|
||||||
|
library: 'octo',
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
libraryTarget: 'var'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = config
|
Loading…
Reference in a new issue