JavaScript

1 program Added 2025-10-22T09:52:42Z Model: meta-llama/llama-3.1-70b-instructTemp: 0.4 Evidence Report issue View issues
Aliases: JS, ECMAScript
Provenance: commit 319c3e6c44 · authored 2025-10-22T11:52:42+02:00 · model meta-llama/llama-3.1-70b-instruct

Sources mentioning this language

8 sources · pl_id: pl/javascript
LLM (this repo) · 1PldbLinguistPygmentsWikipediaHyperpolyglotRosettacodeWikidata · Q2005

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Paradigmsmulti-paradigm: event-driven · functional · imperative · procedural · object-oriented
Typingdynamic, weak, duck
Designed byBrendan Eich of Netscape first · then others contributed to ECMAScript standard
First appeared1995
Influenced byJava · Scheme · Self · AWK · HyperTalk
Homepagehttps://ecma-international.org/publications-and-standards/standards/ecma-262/

Extensions claimed by this language

31 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.jslinguistprimary946.0M files
.jspygmentsprimary946.0M files
.jswikidataprimary946.0M files
.mjswikidataprimary8.9M files
._jslinguistsecondary
.boneslinguistsecondary4.3K files
.cjslinguistsecondary1.5M files
.cjspygmentssecondary1.5M files
.eslinguistsecondary187.3K files
.es6linguistsecondary408.1K files
.fraglinguistsecondary781.0K files
.gslinguistsecondary257.9K files
.jakelinguistsecondary1.6K files
.javascriptlinguistsecondary5.7K files
.jsblinguistsecondary11.9K files
.jscadlinguistsecondary5.9K files
.jsfllinguistsecondary10.5K files
.jsliblinguistsecondary6.4K files
.jsmlinguistsecondary395.7K files
.jsmpygmentssecondary395.7K files
.jsprelinguistsecondary392 files
.jsslinguistsecondary8.7K files
.jsxlinguistsecondary46.4M files
.mjslinguistsecondary8.9M files
.mjspygmentssecondary8.9M files
.njslinguistsecondary11.6K files
.paclinguistsecondary141.1K files
.sjslinguistsecondary51.0K files
.ssjslinguistsecondary2.2K files
.xsjslinguistsecondary5.8K files
.xsjsliblinguistsecondary5.4K files

Related languages

UnityScript (0.39)JavaFX Script (0.38)Gjs (0.34)OJS (0.32)StratifiedJS (0.32)

LLM-contributed programs

Conway's Game of Life

Provenance: commit 319c3e6c44 · authored 2025-10-22T11:52:42+02:00 · model meta-llama/llama-3.1-70b-instruct · Temp 0.4
code.js · license: MIT · added: 2025-10-22T09:52:42Z
function createGrid(rows, cols) {
  const grid = [];
  for (let i = 0; i < rows; i++) {
    grid[i] = [];
    for (let j = 0; j < cols; j++) {
      grid[i][j] = Math.floor(Math.random() * 2);
    }
  }
  return grid;
}

function drawGrid(grid, ctx, cellSize) {
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  for (let i = 0; i < grid.length; i++) {
    for (let j = 0; j < grid[i].length; j++) {
      if (grid[i][j] === 1) {
        ctx.fillStyle = 'black';
      } else {
        ctx.fillStyle = 'white';
      }
      ctx.fillRect(j * cellSize, i * cellSize, cellSize, cellSize);
    }
  }
}

function countNeighbors(grid, row, col) {
  let count = 0;
  for (let i = -1; i <= 1; i++) {
    for (let j = -1; j <= 1; j++) {
      const newRow = row + i;
      const newCol = col + j;
      if (newRow >= 0 && newRow < grid.length && newCol >= 0 && newCol < grid[0].length) {
        count += grid[newRow][newCol];
      }
    }
  }
  count -= grid[row][col];
  return count;
}

function nextGeneration(grid) {
  const newGrid = [];
  for (let i = 0; i < grid.length; i++) {
    newGrid[i] = [];
    for (let j = 0; j < grid[i].length; j++) {
      const neighbors = countNeighbors(grid, i, j);
      if (grid[i][j] === 1 && (neighbors < 2 || neighbors > 3)) {
        newGrid[i][j] = 0;
      } else if (grid[i][j] === 0 && neighbors === 3) {
        newGrid[i][j] = 1;
      } else {
        newGrid[i][j] = grid[i][j];
      }
    }
  }
  return newGrid;
}

function main() {
  const canvas = document.getElementById('canvas');
  const ctx = canvas.getContext('2d');
  const cellSize = 10;
  const rows = Math.floor(canvas.height / cellSize);
  const cols = Math.floor(canvas.width / cellSize);
  let grid = createGrid(rows, cols);
  setInterval(() => {
    drawGrid(grid, ctx, cellSize);
    grid = nextGeneration(grid);
  }, 100);
}

main();

Real programs from Software Heritage

2 samples mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
iphone4-case.jscad · 8441 B · ext .jscad · seen 45× in SWH
via fallback
swh:1:cnt:2e7a097e6abdbebd6bf5235a0105a8276c3a84c4;origin=https://github.com/thejeshgn/apps;anchor=swh:1:rev:98aaa1c1e0a7bf18380e12449bb8c458ca9d6979;path=/openjscad/examples/iphone4-case.jscad
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
// title      : iPhone 4 Dock
// author     : Joost Nieuwenhuijse
// license    : MIT License
// description: iPhone 4 dock
// file       : iphone4-case.jscad

/*

OpenJsCad script for iPhone 4 dock
Note: not tried printing yet, not sure if it really wil fit.

To create the STL file, launch Google Chrome and go to:
http://joostn.github.com/OpenJsCad/processfile.html or http://openjscad.org

Then drag&drop this file into the page

OpenJsCad is an open source 3d solid modeling tool using JavaScript.
For more information see http://joostn.github.com/OpenJsCad

*/

function getParameterDefinitions () {
  return [
    {
      name: 'quality',
      type: 'choice',
      caption: 'Quality:',
      values: ['draft', 'smooth', 'supersmooth'],
      captions: ['Draft (no rounded corners)', 'Smooth (rounded corners)', 'Super smooth (rounded corners)'],
      initial: 'draft'
    },
    {
      name: 'iphonemargin',
      type: 'float',
      initial: 0.5,
      step: 0.1,
      caption: 'Margin around iphone (in mm):'
    },
    {
      name: 'plugmargin',
      type: 'float',
      initial: 0.25,
      step: 0.05,
      caption: 'Margin around dock connector (in mm):'
    },
    {name: 'mouseear', caption: 'Add mouse ear:', type: 'choice', values: [0, 1], initial: 1, captions: ['No', 'Yes']}
  ];
}

function main (params) {
  var resolution = 16; // resolution for all the curved surfaces
  var smoothing = (params.quality !== 'draft'); // set to false during development, for fast rendering
  var draft = (params.quality !== 'supersmooth'); // set to false for high resolution smoothing, rendering will take several minutes!

  var x1 = 40;
  var x2 = 25;
  var x3 = 8;
  var y1 = 35;
  var y2 = y1 + 8;
  var y3 = y2 + 25;
  var frontheight = 30;

  // Build the base from two 2D polygons:
  var base1 = new CSG.Polygon2D([[0, 0], [x1, 0], [x1, y1], [x2, y2], [0, y2]]);
  var base2 = new CSG.Polygon2D([[0, y2], [x2, y2], [x3, y3], [0, y3]]);
  var extruded1 = base1.extrude({offset: [0, 0, frontheight]});
  var extruded2 = base2.extrude({offset: [0, 0, frontheight]});
  // We now have the right half; mirror to create the left half:
  extruded1 = extruded1.union(extruded1.mirroredX());
  extruded2 = extruded2.union(extruded2.mirroredX());
  var base = extruded1.union(extruded2);

  // Make the top back surface slightly slanted:
  var backtopplane = CSG.Plane.fromNormalAndPoint([0, 8, 10], [0, y2, frontheight]);
  base = base.cutByPlane(backtopplane);

  // Make the front surface slightly slanted:
  var frontplane = CSG.Plane.fromNormalAndPoint([0, -10, 2], [0, 0, 0]);
  base = base.cutByPlane(frontplane);

  // Add a CSG.Connector to the base, at the point where the iphone should
  // rest in the base. The connector's axis points upwards and its normal
  // points towards the front:
  var recessionDepth = 10;
  var distanceFromFront = 20;
  var angle = 15;
  base.properties.iphoneConnector = new CSG.Connector(
    [0, distanceFromFront, frontheight - recessionDepth], // the point
    [0, 0, 1], // axis vector
    [1, 0, 0] // normal vector
  );
  // rotate the base.properties.iphoneConnector, so that the iphone will be tilted:
  var rotmaxtrix = CSG.Matrix4x4.rotation(base.properties.iphoneConnector.point, [1, 0, 0], angle);
  base.properties.iphoneConnector = base.properties.iphoneConnector.transform(rotmaxtrix);

  // Create iphone placeholder (it's just a cube with the iphone's dimensions):
  var iphoneradius = new CSG.Vector3D(58.6 / 2 + params.iphonemargin, 9.4 / 2 + params.iphonemargin, 115 / 2);
  var iphone = CSG.cube({radius: iphoneradius});

  // Create the little tab behind the iphone:
  var tabradius = new CSG.Vector3D(15, 5, 12);
  var tab = CSG.cube({radius: tabradius});
  tab = tab.translate([0, (iphoneradius.y + tabradius.y), (-iphoneradius.z + tabradius.z)]);

  // Add a CSG.Connector to the iphone's properties. This is the place where the
  // 30 pin dock plug will snap in. In this case it is the center of the bottom
  // Z plane of the cube. Since the cube already has 6 predefined connectors
  // at the center of each face, we can just use one of those instead of creating
  // a new CSG.Connector:
  iphone.properties.dockConnector = iphone.properties.cube.facecenters[5];

  // transform the iphone so it sits in the base:
  var iphoneTransformation = iphone.properties.dockConnector.getTransformationTo(base.properties.iphoneConnector, true, 0);
  iphone = iphone.transform(iphoneTransformation);

  // transform the tab so it stays behind the iphone:
  tab = tab.transform(iphoneTransformation);

  // and add the tab to the base:
  base = base.union(tab);

  // build the iphone plug:
  var plug = getIphoneDockConnector(params.plugmargin, resolution);

  // The plug has a predefined Connector plug.properties.iphoneConnector
  // To attach the plug to the iphone we connect plug.properties.iphoneConnector
  // to iphone.properties.dockConnector
  plug = plug.connectTo(plug.properties.iphoneConnector,
    iphone.properties.dockConnector, true, 0);

  // We must make sure we can pull the USB cable through the dock. So there needs
  // to be space for the plug. We just create a tall cube with the size of the USB
  // plug (8 by 40 mm), which will be subtracted from the dock's shape:
  var gapForUsbPlug = CSG.cube({radius: [8, 4, 40]});

  // Align it to the plug. Again, since gapForUsbPlug is a CSG.cube it already
  // has predefined CSG.Connectors at every face. Connect the Z face to the iphone:
  gapForUsbPlug = gapForUsbPlug.connectTo(gapForUsbPlug.properties.cube.facecenters[5],
    iphone.properties.dockConnector, true, 0);

  base = base.subtract(iphone);

  // make the cutout for the cable:
  var cablewidth = 3;
  var cableheight = 4;
  var bottomplane = CSG.Plane.fromNormalAndPoint([0, 0, -1], [0, 0, 0]);
  var cableline = plug.properties.cableConnector.axisLine();
  var cableexitpoint = bottomplane.intersectWithLine(cableline);
  var cableentrypoint = new CSG.Vector3D(0, y3, 0);

  var cablepath = new CSG.Path2D([[cableentrypoint.x, cableentrypoint.y], [cableexitpoint.x, cableexitpoint.y]], false);
  var cablecutout = cablepath.rectangularExtrude(cablewidth, cableheight, resolution, false);

  // Smooth the base:
  if (smoothing) {
    base = base.contract(4, draft ? 4 : 16);
    base = base.expand(4, draft ? 4 : 16);
  }

  // Subtract the connector and cable:
  base = base.subtract(iphone).subtract(plug).subtract(cablecutout).subtract(gapForUsbPlug);

  // add mouse ear:
  if (params.mouseear === 1) {
    var mouseearpoint = new CSG.Vector3D(0, y3, 0);
    var mouseearthickness = 0.5;
    var mouseearradius = 15;
    var mouseear = CSG.cylinder({
      start: mouseearpoint,
      end: mouseearpoint.plus(new CSG.Vector3D(0, 0, mouseearthickness)),
      radius: mouseearradius,
      resolution: 16
    });
    base = base.union(mouseear);
  }

  // center:
  var basecenter = base.getBounds()[0].plus(base.getBounds()[1]).times(0.5);
  base = base.translate(basecenter.negated());

  return base;
}

function getIphoneDockConnector (margin, resolution) {
  margin = new CSG.Vector3D(margin);
  var dockConnectorSize = new CSG.Vector3D([26.2, 5.7, 9.5]).plus(margin.times(2));
  var dockConnector = CSG.cube({radius: [(dockConnectorSize.x - dockConnectorSize.y) / 2, dockConnectorSize.y / 2, dockConnectorSize.z / 2]});
  dockConnector = dockConnector.union(CSG.cylinder({
    start: [(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, -dockConnectorSize.z / 2],
    end: [(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, dockConnectorSize.z / 2],
    radius: dockConnectorSize.y / 2,
    resolution: resolution
  }));
  dockConnector = dockConnector.union(CSG.cylinder({
    start: [-(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, -dockConnectorSize.z / 2],
    end: [-(dockConnectorSize.x - dockConnectorSize.y) / 2, 0, dockConnectorSize.z / 2],
    radius: dockConnectorSize.y / 2,
    resolution: resolution
  }));
  var cableTube = CSG.cylinder({
    start: [0, 0, -dockConnectorSize.z / 2 - 5.70 - margin.z],
    end: [0, 0, -dockConnectorSize.z / 2],
    radius: 2.25 + margin.y,
    resolution: resolution
  });
  dockConnector = dockConnector.union(cableTube);

  // Add CSG.Connector properties:
  dockConnector.properties.iphoneConnector = dockConnector.properties.cube.facecenters[4];
  dockConnector.properties.cableConnector = cableTube.properties.cylinder.start;

  return dockConnector;
}
AudioBlocksComponent.es6 · 4841 B · ext .es6 · seen 42× in SWH
via fallback
swh:1:cnt:92deefcadc6dbd7585ea9aded8e8ef772c857faa;origin=https://github.com/CyberAula/ediphy;anchor=swh:1:rev:f540ecf03090c900cdf29da1160d08c55e2275a1;path=/_editor/components/external_provider/file_modal/APIProviders/providers/AudioBlocksComponent.es6
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
import React from 'react';
import PropTypes from 'prop-types';
import { Modal, FormControl, Col, Form, FormGroup, ControlLabel, Button } from 'react-bootstrap';
import Ediphy from '../../../../../../core/editor/main';
import i18n from 'i18next';
import ReactDOM from 'react-dom';
import SearchComponent from '../common/SearchComponent';

import placeholder from '../logos/soundcloud_placeholder.png';
export default class SoundCloudComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            results: [],
            query: '',
            msg: 'No hay resultados',
        };
        this.onSearch = this.onSearch.bind(this);
    }
    render() {
        return <div>
            <Form horizontal action="javascript:void(0);">
                <h5>{this.props.icon ? <img className="fileMenuIcon" src={this.props.icon } alt=""/> : this.props.name}
                    <SearchComponent query={this.state.value} onChange={(e)=>{this.setState({ query: e.target.value });}} onSearch={this.onSearch} /></h5>
                <hr />

                <FormGroup>
                    <Col md={2}>
                        <Button type="submit" className="btn-primary hiddenButton" onClick={(e) => {
                            this.onSearch(this.state.query);
                            e.preventDefault();
                        }}>{i18n.t("vish_search_button")}
                        </Button>
                    </Col>
                </FormGroup>

            </Form>
            <Form style={{ minHeight: 250 }}>
                {this.state.results.length > 0 ?
                    (
                        <FormGroup>
                            <ControlLabel>{ this.state.results.length + " Resultados"}</ControlLabel>
                            <br />
                            {this.state.results.map((item, index) => {
                                let border = item.url === this.props.elementSelected ? "solid orange 3px" : "solid transparent 3px";
                                return (<div>
                                    <img key={index}
                                        src={item.thumbnail || placeholder}
                                        className={'soundCloudSong'}
                                        style={{
                                            width: '100px',
                                            height: '100px',
                                            backgroundColor: '#ddd',
                                            border: border,
                                        }}
                                        onClick={e => {
                                            this.props.onElementSelected(item.title, item.url, 'video');
                                        }}
                                    /><span>{item.title}</span></div>
                                );
                            })}
                        </FormGroup>
                    ) :
                    (
                        <FormGroup>
                            <ControlLabel id="serverMsg">{this.state.msg}</ControlLabel>
                        </FormGroup>
                    )
                }
            </Form>
        </div>;
    }

    onSearch(text) {
        const BASE = 'https://api.audioblocks.com/api/search?srch-term=' + encodeURI(text) + '&srch-type=music&callback=?';
        this.setState({ msg: 'Buscando...' });
        fetch((BASE), {
            jsonpCallback: '1',
            mode: 'no-cors',
            json: true,
        })
            .then(res => { return res.json();}
            ).then(audioStr => {
                let songs = (audioStr);
                if (songs) {
                    let results = Object.keys(songs.data.stockItems).map(a=>{
                        let s = songs.data.stockItems[a].stockItem;
                        return { title: s.title, url: s.previewUrl, thumbnail: s.thumbnailUrl };
                    });

                    this.setState({ results, msg: results.length > 0 ? '' : 'No hay resultados' });
                }
            }).catch(e=>{
                // eslint-disable-next-line no-console
                console.error(e);
                this.setState({ msg: 'Ha habido un error' });
            });
    /* $.ajax(BASE, (result)=>{
      try{
      } catch (e) {
        console.error(e);
        this.setState({ msg: 'Ha habido un error' });
      }

    });*/
    }
}
SoundCloudComponent.propTypes = {
    /**
   * Selected Element
   */
    elementSelected: PropTypes.any,
    /**
   * Select element callback
   */
    onElementSelected: PropTypes.func.isRequired,
    /**
     * Icon that identifies the API provider
     */
    icon: PropTypes.any,
    /**
     * API Provider name
     */
    name: PropTypes.string,
};

Disambiguation rules

Linguist heuristic rules that predict this language when one of its claimed extensions is shared with another.
RuleExtKindPredicates (truncated)
h/linguist/.es/1.espredicates[{"kind": "any", "regexes": ["\\/\\/|[\"']use strict[\"']|export\\s+default\\s|\\/\\*(?:.|[\\r\\n])*?\\*\\/"]}]

Contribute — propose a file extension

Tell us where to find evidence about JavaScript (mapped to pl/javascript). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/JavaScript/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← javaml JavaScript for Automation →